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

The following examples show how to use org.eclipse.gef.GraphicalViewer#setContents() . 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: ERDiagramEditor.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void initializeGraphicalViewer() {
    final GraphicalViewer viewer = getGraphicalViewer();
    viewer.setEditPartFactory(editPartFactory);

    initViewerAction(viewer);
    initDragAndDrop(viewer);

    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON);
    viewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, true);
    viewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, true);
    viewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, true);

    final MenuManager menuMgr = new ERDiagramPopupMenuManager(getActionRegistry(), diagram);

    extensionLoader.addERDiagramPopupMenu(menuMgr, getActionRegistry());

    viewer.setContextMenu(menuMgr);

    viewer.setContents(diagram);

    outlineMenuMgr = new ERDiagramOutlinePopupMenuManager(diagram, getActionRegistry(), outlinePage.getOutlineActionRegistory(), outlinePage.getViewer());
}
 
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: VirtualDiagramEditor.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected void prepareERDiagramPopupMenu(final GraphicalViewer viewer) {
    final MenuManager menuMgr = new ERVirtualDiagramPopupMenuManager(getActionRegistry(), vdiagram);
    extensionLoader.addERDiagramPopupMenu(menuMgr, getActionRegistry());
    viewer.setContextMenu(menuMgr);
    viewer.setContents(vdiagram);
}
 
Example 4
Source File: EditorRulerComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void setRuler( RulerProvider provider, int orientation )
{
	Object ruler = null;
	if ( isRulerVisible && provider != null )
		// provider.getRuler() might return null (at least the API does not
		// prevent that)
		ruler = provider.getRuler( );

	if ( ruler == null )
	{
		// Ruler is not visible or is not present
		setRulerContainer( null, orientation );
		// Layout right-away to prevent an empty control from showing
		layout( true );
		return;
	}

	GraphicalViewer container = getRulerContainer( orientation );
	if ( container == null )
	{
		container = createRulerContainer( orientation );
		setRulerContainer( container, orientation );
	}
	if ( container.getContents( ) != ruler )
	{
		container.setContents( ruler );
		needToLayout = true;
		Display.getCurrent( ).asyncExec( runnable );
	}
}
 
Example 5
Source File: GridEditorTools.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Updates the GEF viewer's contents based on the model.
 * 
 * @param viewer
 *            The GraphicalViewer to update.
 * @param model
 *            The model to use for the Graphical Viewer.
 */
public static void setViewerContents(GraphicalViewer viewer, Grid model) {

	// Sets the actual contents of the viewer as described in the GEF API.
	viewer.setContents(model);

	/* -- 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;
}
 
Example 6
Source File: EROneDiagramEditor.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
@Override
	protected void initializeGraphicalViewer() {
		GraphicalViewer viewer = this.getGraphicalViewer();
		viewer.setEditPartFactory(editPartFactory);

		this.initViewerAction(viewer);
		this.initDragAndDrop(viewer);

		viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1),
				MouseWheelZoomHandler.SINGLETON);
		viewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, true);
		viewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, true);
		viewer.setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, true);

		MenuManager menuMgr = new ERDiagramOnePopupMenuManager(this.getActionRegistry(), this.model);

		this.extensionLoader.addERDiagramPopupMenu(menuMgr, this.getActionRegistry());

		viewer.setContextMenu(menuMgr);

		viewer.setContents(model);
//		viewer.getRootEditPart().setContents(editPartFactory.);

		this.outlineMenuMgr = new ERDiagramOutlinePopupMenuManager(
				this.diagram, this.getActionRegistry(),
				this.outlinePage.getOutlineActionRegistory(), this.outlinePage.getViewer());

		this.gotoMaker = new ERDiagramGotoMarker(this);
	}
 
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();
}