Java Code Examples for org.eclipse.gef.GraphicalViewer#setRootEditPart()

The following examples show how to use org.eclipse.gef.GraphicalViewer#setRootEditPart() . 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: NoWindowTest.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private static void run(final Display display, final int x) {
    final Shell shell = new Shell(display);
    shell.setBounds(0, 0, 350, 350);

    shell.setLayout(new FillLayout(SWT.VERTICAL));

    // display.syncExec(new Runnable() {
    // public void run() {

    final ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
    final GraphicalViewer viewer = new ScrollingGraphicalViewer();
    viewer.setControl(new FigureCanvas(shell));

    final ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(diagram);
    viewer.setRootEditPart(rootEditPart);

    viewer.setEditPartFactory(editPartFactory);
    viewer.setContents(diagram);

    viewer.getContents().refresh();

    // }
    // });

    shell.pack();
    shell.open();
    int count = 0;
    while (count < x) {
        if (!display.readAndDispatch()) {
            try {
                Thread.sleep(1000);
                count++;
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    viewer.getContents().deactivate();
    // display.dispose();
}
 
Example 3
Source File: ReportEditorWithPalette.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected void configureGraphicalViewer( )
{
	super.configureGraphicalViewer( );

	GraphicalViewer viewer = getGraphicalViewer( );
	ActionRegistry actionRegistry = getActionRegistry( );
	ReportRootEditPart root = new ReportRootEditPart( );
	viewer.setRootEditPart( root );

	// hook zoom actions
	hookZoom( root );

	// set key events
	viewer.setKeyHandler( new ReportViewerKeyHandler( viewer,
			actionRegistry ) );

	// configure the context menu
	ContextMenuProvider provider = new SchematicContextMenuProvider( viewer,
			actionRegistry );
	viewer.setContextMenu( provider );

	// hook the viewer into the EditDomain TODO create a function
	getEditDomain( ).addViewer( viewer );
	// acticate the viewer as selection provider for Eclipse
	getSite( ).setSelectionProvider( viewer );

	// initialize the viewer with input
	viewer.setEditPartFactory( getEditPartFactory( ) );

	ModuleHandle model = getModel( );
	WrapperCommandStack commandStack = new WrapperCommandStack( model == null ? null
			: model.getCommandStack( ) );

	viewer.getEditDomain( ).setCommandStack( commandStack );

}
 
Example 4
Source File: SankeyDiagram.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected void configureGraphicalViewer() {
	super.configureGraphicalViewer();

	MenuManager menu = SankeyMenu.create(this);
	getGraphicalViewer().setContextMenu(menu);

	GraphicalViewer viewer = getGraphicalViewer();
	viewer.setEditPartFactory(new SankeyEditPartFactory());
	ScalableRootEditPart root = new ScalableRootEditPart();
	viewer.setRootEditPart(root);

	// append zoom actions to action registry
	ZoomManager zoom = root.getZoomManager();
	getActionRegistry().registerAction(new ZoomInAction(zoom));
	getActionRegistry().registerAction(new ZoomOutAction(zoom));
	zoom.setZoomLevelContributions(Arrays.asList(
			ZoomManager.FIT_ALL,
			ZoomManager.FIT_HEIGHT,
			ZoomManager.FIT_WIDTH));

	// create key handler
	KeyHandler keyHandler = new KeyHandler();
	keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0),
			getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
	keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0),
			getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
	viewer.setKeyHandler(keyHandler);

	viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE),
			MouseWheelZoomHandler.SINGLETON);
}
 
Example 5
Source File: ERDiagramEditor.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void initViewerAction(final GraphicalViewer viewer) {
    final ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(diagram);
    viewer.setRootEditPart(rootEditPart);

    final ZoomManager manager = rootEditPart.getZoomManager();

    final double[] zoomLevels = new double[] {0.1, 0.25, 0.5, 0.75, 0.8, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0};
    manager.setZoomLevels(zoomLevels);

    final List<String> zoomContributions = new ArrayList<String>();
    zoomContributions.add(ZoomManager.FIT_ALL);
    zoomContributions.add(ZoomManager.FIT_HEIGHT);
    zoomContributions.add(ZoomManager.FIT_WIDTH);
    manager.setZoomLevelContributions(zoomContributions);

    final ZoomInAction zoomInAction = new ZoomInAction(manager);
    final ZoomOutAction zoomOutAction = new ZoomOutAction(manager);
    final ZoomAdjustAction zoomAdjustAction = new ZoomAdjustAction(manager);

    getActionRegistry().registerAction(zoomInAction);
    getActionRegistry().registerAction(zoomOutAction);
    getActionRegistry().registerAction(zoomAdjustAction);

    addKeyHandler(zoomInAction);
    addKeyHandler(zoomOutAction);

    final IFigure gridLayer = rootEditPart.getLayer(LayerConstants.GRID_LAYER);
    gridLayer.setForegroundColor(Resources.GRID_COLOR);

    IAction action = new ToggleGridAction(viewer);
    getActionRegistry().registerAction(action);

    action = new ToggleSnapToGeometryAction(viewer);
    getActionRegistry().registerAction(action);

    action = new ChangeBackgroundColorAction(this, diagram);
    getActionRegistry().registerAction(action);
    getSelectionActions().add(action.getId());

    action = new TooltipAction(this);
    getActionRegistry().registerAction(action);

    action = new LockEditAction(this);
    getActionRegistry().registerAction(action);

    action = new ExportToDBAction(this);
    getActionRegistry().registerAction(action);

    actionBarContributor = new ERDiagramActionBarContributor();
    actionBarContributor.init(getEditorSite().getActionBars(), getSite().getPage());
    // action = new ToggleRulerVisibilityAction(viewer);
    // this.getActionRegistry().registerAction(action);
}
 
Example 6
Source File: MainDiagramEditor.java    From erflute with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected void initViewerAction(GraphicalViewer viewer) {
    final ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(diagram);
    viewer.setRootEditPart(rootEditPart);

    final ZoomManager manager = rootEditPart.getZoomManager();

    final double[] zoomLevels = new double[] { 0.1, 0.25, 0.5, 0.75, 0.8, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 };
    manager.setZoomLevels(zoomLevels);

    final List<String> zoomContributions = new ArrayList<>();
    zoomContributions.add(ZoomManager.FIT_ALL);
    zoomContributions.add(ZoomManager.FIT_HEIGHT);
    zoomContributions.add(ZoomManager.FIT_WIDTH);
    manager.setZoomLevelContributions(zoomContributions);

    final ZoomInAction zoomInAction = new ZoomInAction(manager);
    final ZoomOutAction zoomOutAction = new ZoomOutAction(manager);
    final ZoomAdjustAction zoomAdjustAction = new ZoomAdjustAction(manager);

    getActionRegistry().registerAction(zoomInAction);
    getActionRegistry().registerAction(zoomOutAction);
    getActionRegistry().registerAction(zoomAdjustAction);

    addKeyHandler(zoomInAction);
    addKeyHandler(zoomOutAction);

    final IFigure gridLayer = rootEditPart.getLayer(LayerConstants.GRID_LAYER);
    gridLayer.setForegroundColor(DesignResources.GRID_COLOR);

    IAction action = new ToggleGridAction(viewer);
    getActionRegistry().registerAction(action);

    action = new ChangeBackgroundColorAction(this, diagram);
    getActionRegistry().registerAction(action);
    getSelectionActions().add(action.getId());

    action = new ToggleMainColumnAction(this);
    getActionRegistry().registerAction(action);

    action = new LockEditAction(this);
    getActionRegistry().registerAction(action);

    action = new ExportToDBAction(this);
    getActionRegistry().registerAction(action);

    this.actionBarContributor = new ERDiagramActionBarContributor(zoomComboContributionItem);
}
 
Example 7
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 8
Source File: NoWindowTest.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
private static void run(Display display, int x) {
	Shell shell = new Shell(display);
	shell.setBounds(0, 0, 350, 350);

	shell.setLayout(new FillLayout(SWT.VERTICAL));

	// display.syncExec(new Runnable() {
	// public void run() {

	ERDiagramEditPartFactory editPartFactory = new ERDiagramEditPartFactory();
	GraphicalViewer viewer = new ScrollingGraphicalViewer();
	viewer.setControl(new FigureCanvas(shell));

	ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(
			diagram);
	viewer.setRootEditPart(rootEditPart);

	viewer.setEditPartFactory(editPartFactory);
	viewer.setContents(diagram);

	viewer.getContents().refresh();

	// }
	// });

	shell.pack();
	shell.open();
	int count = 0;
	while (count < x) {
		if (!display.readAndDispatch()) {
			try {
				Thread.sleep(1000);
				count++;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	viewer.getContents().deactivate();
	// display.dispose();
}
 
Example 9
Source File: ERDiagramEditor.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected void initViewerAction(GraphicalViewer viewer) {
	ScalableFreeformRootEditPart rootEditPart = new PagableFreeformRootEditPart(
			this.diagram);
	viewer.setRootEditPart(rootEditPart);

	ZoomManager manager = rootEditPart.getZoomManager();

	double[] zoomLevels = new double[] { 0.1, 0.25, 0.5, 0.75, 0.8, 1.0,
			1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 };
	manager.setZoomLevels(zoomLevels);

	List<String> zoomContributions = new ArrayList<String>();
	zoomContributions.add(ZoomManager.FIT_ALL);
	zoomContributions.add(ZoomManager.FIT_HEIGHT);
	zoomContributions.add(ZoomManager.FIT_WIDTH);
	manager.setZoomLevelContributions(zoomContributions);

	ZoomInAction zoomInAction = new ZoomInAction(manager);
	ZoomOutAction zoomOutAction = new ZoomOutAction(manager);
	ZoomAdjustAction zoomAdjustAction = new ZoomAdjustAction(manager);

	this.getActionRegistry().registerAction(zoomInAction);
	this.getActionRegistry().registerAction(zoomOutAction);
	this.getActionRegistry().registerAction(zoomAdjustAction);

	this.addKeyHandler(zoomInAction);
	this.addKeyHandler(zoomOutAction);

	IFigure gridLayer = rootEditPart.getLayer(LayerConstants.GRID_LAYER);
	gridLayer.setForegroundColor(Resources.GRID_COLOR);

	IAction action = new ToggleGridAction(viewer);
	this.getActionRegistry().registerAction(action);

	action = new ChangeBackgroundColorAction(this, this.diagram);
	this.getActionRegistry().registerAction(action);
	this.getSelectionActions().add(action.getId());

	action = new EditExcelAction(this, this.diagram);
	this.getActionRegistry().registerAction(action);
	this.getSelectionActions().add(action.getId());

	action = new ToggleMainColumnAction(this);
	this.getActionRegistry().registerAction(action);

	action = new LockEditAction(this);
	this.getActionRegistry().registerAction(action);

	action = new ExportToDBAction(this);
	this.getActionRegistry().registerAction(action);

	this.actionBarContributor = new ERDiagramActionBarContributor(
			this.zoomComboContributionItem);

	// action = new ToggleRulerVisibilityAction(viewer);
	// this.getActionRegistry().registerAction(action);
	//
	// action = new ToggleSnapToGeometryAction(viewer);
	// this.getActionRegistry().registerAction(action);
}