org.eclipse.gef.editparts.SimpleRootEditPart Java Examples

The following examples show how to use org.eclipse.gef.editparts.SimpleRootEditPart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridEditorTools.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a basic GEF viewer in the specified container and with the
 * specified EditPartFactory.
 * 
 * @param container
 *            The Composite that will contain the viewer.
 * @param factory
 *            The factory used to create the viewer's EditParts.
 */
public static GraphicalViewer createViewer(Composite container,
		EditPartFactory factory) {
	// Create the GraphicalViewer. This is fairly standard procedure for
	// GEF.

	// Use this to test re-sizing of window (this viewer does not create
	// scroll bars).
	GraphicalViewer viewer = new GraphicalViewerImpl();
	viewer.setRootEditPart(new SimpleRootEditPart());
	viewer.createControl(container);

	// Pass the custom EditPartFactory and the Grid model to the
	// GraphicalViewer.
	viewer.setEditPartFactory(factory);

	// Set the GraphicalViewer's EditDomain to a default.
	viewer.setEditDomain(new DefaultEditDomain(null));

	return viewer;
}
 
Example #2
Source File: CustomMainPaletteViewer.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createDefaultRoot() {
	setRootEditPart(new SimpleRootEditPart(){
		@Override
		protected IFigure createFigure() {
			Figure figure = new Figure();
			figure.setLayoutManager(new StackLayout());
			return figure;
		}
	});
}
 
Example #3
Source File: AnalysisView.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Given a GEF GraphicalViewer, this method creates a save file dialog and
 * will save the contents of the viewer as an image file. Supported
 * extensions include PNG, JPG, and BMP.
 * 
 * @param viewer
 *            The GraphicalViewer to save as an image.
 */
protected static void saveViewerImage(GraphicalViewer viewer) {

	// Store the allowed extensions in a HashMap.
	HashMap<String, Integer> extensions = new HashMap<String, Integer>(4);
	extensions.put("png", SWT.IMAGE_PNG);
	extensions.put("jpg", SWT.IMAGE_JPEG);
	extensions.put("bmp", SWT.IMAGE_BMP);

	// Make the array of strings needed to pass to the file dialog.
	String[] extensionStrings = new String[extensions.keySet().size()];
	int i = 0;
	for (String extension : extensions.keySet()) {
		extensionStrings[i++] = "*." + extension;
	}

	// Create the file save dialog.
	FileDialog fileDialog = new FileDialog(viewer.getControl().getShell(),
			SWT.SAVE);
	fileDialog.setFilterExtensions(extensionStrings);
	fileDialog.setOverwrite(true);

	// Get the path of the new/overwritten image file.
	String path = fileDialog.open();

	// Return if the user cancelled.
	if (path == null) {
		return;
	}

	// Get the image type to save from the path's extension.
	String[] splitPath = path.split("\\.");
	int extensionSWT = extensions.get(splitPath[splitPath.length - 1]);

	// Get the root EditPart and its draw2d Figure.
	SimpleRootEditPart rootEditPart = (SimpleRootEditPart) viewer
			.getRootEditPart();
	IFigure figure = rootEditPart.getFigure();

	// Get the image from the Figure.
	org.eclipse.draw2d.geometry.Rectangle bounds = figure.getBounds();
	Image image = new Image(null, bounds.width, bounds.height);
	GC gc = new GC(image);
	SWTGraphics g = new SWTGraphics(gc);
	figure.paint(g);
	g.dispose();
	gc.dispose();

	// Save the file.
	ImageLoader loader = new ImageLoader();
	loader.data = new ImageData[] { image.getImageData() };
	loader.save(path, extensionSWT);
	image.dispose();

	return;
}
 
Example #4
Source File: GridViewerLauncher.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a GEF Viewer with the specified model and factory.
 * 
 * @param container
 *            The Composite that will contain the viewer.
 * @param model
 *            The model for the viewer.
 * @param factory
 *            The factory used to create the viewer's EditParts.
 */
public static GraphicalViewer createViewer(Composite container, Grid model,
		EditPartFactory factory) {
	// Create the GraphicalViewer. This is fairly standard procedure for
	// GEF.
	// GraphicalViewer viewer = new ScrollingGraphicalViewer();
	// Use this to test re-sizing of window (this viewer does not create
	// scroll bars).
	GraphicalViewer viewer = new GraphicalViewerImpl();
	viewer.setRootEditPart(new SimpleRootEditPart());
	viewer.createControl(container);
	// Pass the custom EditPartFactory and the Grid model to the
	// GraphicalViewer.
	viewer.setEditPartFactory(factory);
	viewer.setContents(model);
	// Set the GraphicalViewer's EditDomain to a default.
	viewer.setEditDomain(new DefaultEditDomain(null));

	/* -- Set the viewer's current selection of cells. -- */
	// Here, we need to set the viewer's current selection of EditParts to
	// the currently-selected Cells in the Grid model. This allows us to
	// show the user the Cells that were previously selected. To do this, we
	// need to add all of the EditParts for selected Cells to the viewer's
	// StructuredSelection.

	// Create the object array needed to create the StructuredSelection.
	List<Object> selectionList = new ArrayList<Object>();

	// Add the EditParts for all selected Cells to the ArrayList.
	for (Cell cell : model.getCells()) {
		if (cell.getSelected()) {
			// Get the Cell's EditPart.
			CellEditPart editPart = (CellEditPart) viewer
					.getEditPartRegistry().get(cell);

			// Add the CellEditPart to the array.
			selectionList.add(editPart);
		}
	}

	// Create the StructuredSelection from the array and pass it to viewer.
	viewer.setSelection(new StructuredSelection(selectionList.toArray()));
	/* -------------------------------------------------- */

	return viewer;
}
 
Example #5
Source File: CustomToolPaletteViewer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createDefaultRoot() {
	setRootEditPart(new SimpleRootEditPart());
}