use of org.eclipse.gef.ContextMenuProvider in project cubrid-manager by CUBRID.
the class ERSchemaEditor method createGraphicalViewer.
/**
* Creates a new <code>GraphicalViewer</code>, configures, registers and
* initializes it.
*
* @param parent the parent composite
* @return a new <code>GraphicalViewer</code>
*/
protected void createGraphicalViewer(Composite parent) {
IEditorSite editorSite = getEditorSite();
ScrollingGraphicalViewer viewer = createGraphicalViewer(editorSite, parent);
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getRootEditPart();
zoomManager = rootEditPart.getZoomManager();
zoomManager.setZoomLevels(ZOOM_LEVELS);
// hook the viewer into the EditDomain
getEditDomain().addViewer(viewer);
// acticate the viewer as selection provider for Eclipse
getSite().setSelectionProvider(viewer);
viewer.setContents(erSchema);
ContextMenuProvider provider = new SchemaContextMenuProvider(viewer, getActionRegistry());
viewer.setContextMenu(provider);
getSite().registerContextMenu(provider.getId(), provider, viewer);
graphicalViewer = viewer;
// key handler
GraphicalViewerKeyHandler graphicalViewerKeyHandler = new GraphicalViewerKeyHandler(viewer);
KeyHandler parentKeyHandler = graphicalViewerKeyHandler.setParent(getCommonKeyHandler());
viewer.setKeyHandler(parentKeyHandler);
registDropTarget();
}
use of org.eclipse.gef.ContextMenuProvider in project cubrid-manager by CUBRID.
the class ReplicationEditor method configureGraphicalViewer.
/**
* @see org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()
*/
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
GraphicalViewer viewer = getGraphicalViewer();
ScalableRootEditPart rootEditPart = new ScalableRootEditPart();
viewer.setRootEditPart(rootEditPart);
viewer.setEditPartFactory(new PartFactory(this));
ZoomManager manager = rootEditPart.getZoomManager();
getActionRegistry().registerAction(new ZoomInAction(manager));
getActionRegistry().registerAction(new ZoomOutAction(manager));
double[] zoomLevels = new double[] { 0.25, 0.5, 0.75, 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);
KeyHandler keyHandler = new KeyHandler();
if (isEditable) {
keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId()));
}
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));
keyHandler.put(KeyStroke.getPressed('a', 97, 0), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE), MouseWheelZoomHandler.SINGLETON);
viewer.setKeyHandler(keyHandler);
ContextMenuProvider provider = new ReplEditorContextMenuProvider(viewer, getActionRegistry());
viewer.setContextMenu(provider);
}
use of org.eclipse.gef.ContextMenuProvider in project tdi-studio-se by Talend.
the class ErdiagramDiagramEditor method configureGraphicalViewer.
//$NON-NLS-1$
@SuppressWarnings("unchecked")
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer) getGraphicalViewer();
ErDiagramRootEditPart root = new ErDiagramRootEditPart();
IAction deleteAction = new ErDiagramItemDeleteAction(this);
getActionRegistry().registerAction(deleteAction);
getSelectionActions().add(deleteAction.getId());
viewer.setRootEditPart(root);
ErDiagramPartFactory partFactory = new ErDiagramPartFactory();
// set the factory to use for creating EditParts for elements in the
// model
getGraphicalViewer().setEditPartFactory(partFactory);
getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer()).setParent(getCommonKeyHandler()));
/** * Management of the context menu ** */
ContextMenuProvider cmProvider = new ErDiagramMenuProvider(this, viewer, getActionRegistry());
viewer.setContextMenu(cmProvider);
/** * Snap To Grid ** */
// Grid properties
getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(GRID_SIZE, GRID_SIZE));
getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, new Boolean(true));
// We keep grid visibility and enablement in sync
getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, new Boolean(true));
IAction showGrid = new ToggleGridAction(getGraphicalViewer());
getActionRegistry().registerAction(showGrid);
/** * Snap To Geometry ** */
getGraphicalViewer().setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, new Boolean(false));
IAction snapAction = new ToggleSnapToGeometryAction(getGraphicalViewer());
getActionRegistry().registerAction(snapAction);
}
use of org.eclipse.gef.ContextMenuProvider in project whole by wholeplatform.
the class E4Dialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
if (E4Utils.isLegacyApplication())
HandlersBehavior.registerHandlers(handlerService);
IEclipseContext params = EclipseContextFactory.create();
params.set("parent", parent);
viewer = ContextInjectionFactory.make(E4GraphicalViewer.class, context, params);
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateSelection(E4Utils.createSelectionBindings(event, context));
}
});
viewer.getControl().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent event) {
}
@SuppressWarnings("unchecked")
@Override
public void focusGained(FocusEvent event) {
context.set(IEntityPartViewer.class, viewer);
context.set(ActionRegistry.class, actionRegistry);
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
}
});
viewer.addPartFocusListener(new IPartFocusListener() {
@SuppressWarnings("unchecked")
public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
context.activateBranch();
}
});
E4KeyHandler keyHandler = new E4KeyHandler(context);
keyHandler.setParent(new E4NavigationKeyHandler(context));
context.set(IEntityPartViewer.class, viewer);
viewer.setKeyHandler(keyHandler);
viewer.setEntityContents(createDefaultContents());
actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
actionRegistry.registerWorkbenchActions();
context.set(ActionRegistry.class, actionRegistry);
JFaceMenuBuilder uiBuilder = ContextInjectionFactory.make(JFaceMenuBuilder.class, context);
contextMenuProvider = new PopupMenuProvider<IContributionItem, IMenuManager>(uiBuilder);
viewer.setContextMenu(new ContextMenuProvider(viewer) {
@Override
public void buildContextMenu(IMenuManager menuManager) {
contextMenuProvider.populate(menuManager);
}
});
return parent;
}
use of org.eclipse.gef.ContextMenuProvider in project whole by wholeplatform.
the class E4FindReplaceDialog method createReplaceArea.
protected Control createReplaceArea(Composite parent) {
IEclipseContext params = EclipseContextFactory.create();
params.set("parent", parent);
replaceViewer = ContextInjectionFactory.make(E4GraphicalViewer.class, context, params);
replaceViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
replaceViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateSelection(E4Utils.createSelectionBindings(event, context));
}
});
replaceViewer.getControl().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
}
@SuppressWarnings("unchecked")
@Override
public void focusGained(FocusEvent e) {
context.set(IEntityPartViewer.class, replaceViewer);
context.set(ActionRegistry.class, replaceActionRegistry);
updateSelection(E4Utils.createSelectionBindings(replaceViewer.getSelectedEditParts(), replaceViewer, context));
}
});
replaceViewer.addPartFocusListener(new IPartFocusListener() {
@SuppressWarnings("unchecked")
public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
updateSelection(E4Utils.createSelectionBindings(replaceViewer.getSelectedEditParts(), replaceViewer, context));
}
});
E4KeyHandler keyHandler = new E4KeyHandler(context);
keyHandler.setParent(new E4NavigationKeyHandler(context));
replaceViewer.setKeyHandler(keyHandler);
replaceViewer.setEntityContents(createDefaultContents());
context.set(IEntityPartViewer.class, replaceViewer);
replaceActionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
replaceActionRegistry.registerWorkbenchActions();
context.set(ActionRegistry.class, replaceActionRegistry);
replaceViewer.setContextMenu(new ContextMenuProvider(replaceViewer) {
@Override
public void buildContextMenu(IMenuManager menuManager) {
contextMenuProvider.populate(menuManager);
}
});
return parent;
}
Aggregations