use of org.eclipse.zest.layouts.LayoutAlgorithm in project hale by halestudio.
the class AbstractMappingView method createViewControl.
@Override
public void createViewControl(Composite parent) {
viewer = new GraphViewer(parent, SWT.BORDER);
viewer.setContentProvider(createContentProvider());
// viewer.setContentProvider(new CellRelationshipContentProvider());
// viewer.setContentProvider(new NestedCellRelationshipContentProvider());
viewer.setLabelProvider(createLabelProvider(viewer));
viewer.setInput(null);
LayoutAlgorithm layout = createLayout();
viewer.setLayoutAlgorithm(layout, true);
viewer.applyLayout();
fillToolBar();
// set selection provider
selectionFacade = new SelectionProviderFacade();
selectionFacade.setSelectionProvider(getViewer());
getSite().setSelectionProvider(new PostSelectionSupport(selectionFacade));
viewer.getControl().addKeyListener(new KeyListener() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == 'a' && (e.stateMask & SWT.MODIFIER_MASK) == SWT.CTRL) {
// XXX even though getSelection returns the current state, a
// selection update is not triggered by the control
// -> force selection change event after Ctrl+A
ISelection sel = viewer.getSelection();
selectionFacade.setSelection(sel);
}
}
@Override
public void keyPressed(KeyEvent e) {
// nothing to do
}
});
// create context menu
new ViewerMenu(getSite(), getViewer()) {
/**
* @see eu.esdihumboldt.hale.ui.util.ViewContextMenu#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
*/
@Override
public void menuAboutToShow(IMenuManager manager) {
super.menuAboutToShow(manager);
AbstractMappingView.this.menuAboutToShow(manager);
}
};
}
use of org.eclipse.zest.layouts.LayoutAlgorithm in project hale by halestudio.
the class AbstractMappingView method createLayout.
/**
* Create the initial layout to use
*
* @return the layout
*/
protected LayoutAlgorithm createLayout() {
LayoutAlgorithm layout;
layout = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
return layout;
}
use of org.eclipse.zest.layouts.LayoutAlgorithm in project hale by halestudio.
the class ImageContent method getImageContent.
/**
* Get the function image for the function with the given identifier.
*
* @param func_id the function identifier
* @param tempDir the temporary directory where the function image may be
* stored
* @return the function image input stream or <code>null</code>
* @throws Exception if an error occurs generating the image
*/
public static InputStream getImageContent(String func_id, File tempDir) throws Exception {
final FunctionDefinition<?> function = FunctionUtil.getFunction(func_id, null);
if (function == null) {
log.warn("Unknown function " + func_id);
return null;
}
final File _functionFile = new File(tempDir, func_id + ".png");
if (!_functionFile.exists()) {
Display display;
if (Display.getCurrent() != null) {
// use the current display if available
display = Display.getCurrent();
} else {
try {
// use workbench display if available
display = PlatformUI.getWorkbench().getDisplay();
} catch (Throwable e) {
// use a dedicated display thread if no workbench is
// available
display = DisplayThread.getInstance().getDisplay();
}
}
display.syncExec(new Runnable() {
@Override
public void run() {
// create an initial off-screen graph with fixed values;
// resize the graph after computing the figures width and
// height
OffscreenGraph off_graph = new OffscreenGraph(300, 200) {
@Override
protected void configureViewer(GraphViewer viewer) {
LayoutAlgorithm algo = new FunctionTreeLayoutAlgorithm();
FunctionGraphContentProvider stcp = new FunctionGraphContentProvider();
// XXX no service provider given
FunctionGraphLabelProvider fglp = new FunctionGraphLabelProvider(null, false);
viewer.setContentProvider(stcp);
viewer.setLabelProvider(fglp);
viewer.setInput(function);
viewer.setLayoutAlgorithm(algo);
}
};
Graph graph = off_graph.getGraph();
Dimension dim = computeSize(graph);
int width;
if (dim.width > 450) {
width = dim.width;
} else {
// minimum width = 450
width = 450;
}
int height = dim.height;
off_graph.resize(width, height);
try {
off_graph.saveImage(new BufferedOutputStream(new FileOutputStream(_functionFile)), null);
} catch (IOException e) {
log.warn("Conversion from Graph to Image failed!");
} finally {
off_graph.dispose();
}
}
});
}
if (_functionFile.exists()) {
return new FileInputStream(_functionFile);
}
return null;
}
Aggregations