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

The following examples show how to use org.eclipse.gef.GraphicalViewer#setEditPartFactory() . 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: MainDiagramEditor.java    From erflute with Apache License 2.0 6 votes vote down vote up
@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);

    prepareERDiagramPopupMenu(viewer);

    prepareERDiagramOutlinePopupMenu();

    this.gotoMaker = new ERDiagramGotoMarker(this);
}
 
Example 3
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 4
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 5
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 6
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 7
Source File: ERDiagramEditor.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
	 * {@inheritDoc}
	 */
	@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 ERDiagramPopupMenuManager(this
				.getActionRegistry(), this.diagram);

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

		viewer.setContextMenu(menuMgr);

//		if (diagram.getCurrentErmodel() == null) {
//			viewer.setContents(diagram);
//		} else {
//			// �Ƃ肠����OFF���āA�ŏ��Ƀt�H�[�J�X�����������Ƃ��ɃR���e���c���l�߂�
//		}

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

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