Search in sources :

Example 66 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project core by jcryptool.

the class ApplicationWorkbenchAdvisor method postStartup.

/**
 * Performs arbitrary actions after the workbench windows have been opened (or restored), but before the main event
 * loop is run.
 *
 * Specifically a part listener is added to the workbench page. The algorithm actions will be enabled if at least
 * the text or hex editor is active. Otherwise the will be disabled.
 */
public void postStartup() {
    super.postStartup();
    if (OperationsPlugin.getDefault().getAlgorithmsManager() != null) {
        IWorkbenchPage activePage = getWorkbenchConfigurer().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        activePage.addPartListener(new IPartListener() {

            public void partActivated(IWorkbenchPart part) {
                setAlgorithmActionStatus(part);
            }

            public void partBroughtToTop(IWorkbenchPart part) {
            }

            public void partClosed(IWorkbenchPart part) {
            }

            public void partDeactivated(IWorkbenchPart part) {
                setAlgorithmActionStatus(part);
            }

            public void partOpened(IWorkbenchPart part) {
            }
        });
        if (getWorkbenchConfigurer().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() != null) {
            OperationsPlugin.getDefault().getAlgorithmsManager().setCommandsEnabled(true);
        }
    }
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IPartListener(org.eclipse.ui.IPartListener) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 67 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project jbosstools-hibernate by jbosstools.

the class DiagramViewer method createActions.

@SuppressWarnings("unchecked")
protected void createActions() {
    // super.createActions();
    // BEGIN: redefine super.createActions
    ActionRegistry registry = getActionRegistry();
    IAction action;
    action = new RefreshAction(this);
    registry.registerAction(action);
    getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REFRESH.getId(), action);
    action = new UndoAction(this);
    registry.registerAction(action);
    getStackActions().add(action.getId());
    action = new RedoAction(this);
    registry.registerAction(action);
    getStackActions().add(action.getId());
    action = new SelectAllAction(this);
    registry.registerAction(action);
    action = new DeleteAction((IWorkbenchPart) this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new SaveAction(this);
    registry.registerAction(action);
    getPropertyActions().add(action.getId());
    registry.registerAction(new PrintDiagramViewerAction(this));
    // END: redefine super.createActions
    getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.PRINT.getId(), getActionRegistry().getAction(ActionFactory.PRINT.getId()));
    getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
    action = new OpenMappingAction(this);
    registry.registerAction(action);
    action = new OpenSourceAction(this);
    registry.registerAction(action);
    action = new ExportImageAction(this);
    registry.registerAction(action);
    action = new AutoLayoutAction(this);
    registry.registerAction(action);
    ToggleConnectionsAction actionToggleConnections = new ToggleConnectionsAction(this);
    registry.registerAction(actionToggleConnections);
    action = new ToggleAssociationAction(this);
    registry.registerAction(action);
    action = new ToggleClassMappingAction(this);
    registry.registerAction(action);
    action = new ToggleForeignKeyConstraintAction(this);
    registry.registerAction(action);
    action = new TogglePropertyMappingAction(this);
    registry.registerAction(action);
    action = new ConnectionRouterFanAction(this);
    registry.registerAction(action);
    getPropertyActions().add(action.getId());
    action = new ConnectionRouterManhattanAction(this);
    registry.registerAction(action);
    getPropertyActions().add(action.getId());
    ToggleShapeExpandStateAction actionToggleShapeExpandState = new ToggleShapeExpandStateAction(this);
    registry.registerAction(actionToggleShapeExpandState);
    getSelectionActions().add(actionToggleShapeExpandState.getId());
    action = new ShapeExpandAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new ShapeCollapseAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    ToggleShapeVisibleStateAction actionToggleShapeVisibleState = new ToggleShapeVisibleStateAction(this);
    registry.registerAction(actionToggleShapeVisibleState);
    getSelectionActions().add(actionToggleShapeVisibleState.getId());
    action = new ShapeHideAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new ShapeShowAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    // action = new CollapseAllAction(this);
    // registry.registerAction(action);
    // action = new ExpandAllAction(this);
    // registry.registerAction(action);
    action = new ZoomInAction(gefRootEditPart.getZoomManager());
    registry.registerAction(action);
    action = new ZoomOutAction(gefRootEditPart.getZoomManager());
    registry.registerAction(action);
    action = new LexicalSortingAction(this, null);
    registry.registerAction(action);
    Action[] act = new Action[4];
    act[0] = (Action) registry.getAction(TogglePropertyMappingAction.ACTION_ID);
    act[1] = (Action) registry.getAction(ToggleClassMappingAction.ACTION_ID);
    act[2] = (Action) registry.getAction(ToggleAssociationAction.ACTION_ID);
    act[3] = (Action) registry.getAction(ToggleForeignKeyConstraintAction.ACTION_ID);
    // act[4] = null;
    // act[5] = (Action)registry.getAction(ConnectionRouterManhattanAction.ACTION_ID);
    // act[6] = (Action)registry.getAction(ConnectionRouterFanAction.ACTION_ID);
    actionToggleConnections.setMenuCreator(new ActionMenu(act));
// act = new Action[2];
// act[0] = (Action)registry.getAction(ShapeExpandAction.ACTION_ID);
// act[1] = (Action)registry.getAction(ShapeCollapseAction.ACTION_ID);
// actionToggleShapeExpandState.setMenuCreator(new ActionMenu(act));
// act = new Action[2];
// act[0] = (Action)registry.getAction(ShapeShowAction.ACTION_ID);
// act[1] = (Action)registry.getAction(ShapeHideAction.ACTION_ID);
// actionToggleShapeVisibleState.setMenuCreator(new ActionMenu(act));
}
Also used : SaveAction(org.eclipse.gef.ui.actions.SaveAction) ToggleAssociationAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleAssociationAction) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) TogglePropertyMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.TogglePropertyMappingAction) ToggleRulerVisibilityAction(org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction) ToggleConnectionsAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleConnectionsAction) ToggleClassMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleClassMappingAction) RedoAction(org.eclipse.gef.ui.actions.RedoAction) RefreshAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.RefreshAction) ShapeCollapseAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeCollapseAction) ShapeShowAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeShowAction) OpenMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenMappingAction) UndoAction(org.eclipse.gef.ui.actions.UndoAction) PrintDiagramViewerAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.PrintDiagramViewerAction) ConnectionRouterFanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterFanAction) ExportImageAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction) ToggleShapeVisibleStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeVisibleStateAction) AutoLayoutAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.AutoLayoutAction) LexicalSortingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.LexicalSortingAction) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) OpenSourceAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenSourceAction) SelectAllAction(org.eclipse.gef.ui.actions.SelectAllAction) ToggleShapeExpandStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeExpandStateAction) SaveAction(org.eclipse.gef.ui.actions.SaveAction) Action(org.eclipse.jface.action.Action) DeleteAction(org.eclipse.gef.ui.actions.DeleteAction) ShapeExpandAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeExpandAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) ShapeHideAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeHideAction) ToggleForeignKeyConstraintAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleForeignKeyConstraintAction) ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) ConnectionRouterManhattanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterManhattanAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ShapeExpandAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeExpandAction) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry) ToggleShapeExpandStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeExpandStateAction) ToggleShapeVisibleStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeVisibleStateAction) PrintDiagramViewerAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.PrintDiagramViewerAction) OpenMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenMappingAction) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) RedoAction(org.eclipse.gef.ui.actions.RedoAction) AutoLayoutAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.AutoLayoutAction) ShapeHideAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeHideAction) ShapeShowAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeShowAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) OpenSourceAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenSourceAction) ToggleConnectionsAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleConnectionsAction) IAction(org.eclipse.jface.action.IAction) ToggleAssociationAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleAssociationAction) ExportImageAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction) ToggleForeignKeyConstraintAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleForeignKeyConstraintAction) LexicalSortingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.LexicalSortingAction) ConnectionRouterFanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterFanAction) RefreshAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.RefreshAction) TogglePropertyMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.TogglePropertyMappingAction) SelectAllAction(org.eclipse.gef.ui.actions.SelectAllAction) ConnectionRouterManhattanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterManhattanAction) DeleteAction(org.eclipse.gef.ui.actions.DeleteAction) ShapeCollapseAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeCollapseAction) ActionMenu(org.jboss.tools.hibernate.ui.diagram.editors.actions.ActionMenu) ToggleClassMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleClassMappingAction) UndoAction(org.eclipse.gef.ui.actions.UndoAction)

Example 68 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project jbosstools-hibernate by jbosstools.

the class DiagramBaseAction method getDiagramViewer.

protected DiagramViewer getDiagramViewer() {
    DiagramViewer res = editor;
    final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (workbenchWindow == null) {
        return res;
    }
    final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
    if (workbenchPage == null) {
        return res;
    }
    IWorkbenchPart part = workbenchPage.getActivePart();
    if (part instanceof DiagramViewer) {
        res = (DiagramViewer) part;
    } else if (part instanceof ContentOutline) {
        ContentOutline co = (ContentOutline) part;
        if (co.getCurrentPage() instanceof DiagramContentOutlinePage) {
            DiagramContentOutlinePage dcop = (DiagramContentOutlinePage) co.getCurrentPage();
            res = dcop.getEditor();
        }
    }
    return res;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ContentOutline(org.eclipse.ui.views.contentoutline.ContentOutline) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) DiagramContentOutlinePage(org.jboss.tools.hibernate.ui.diagram.editors.DiagramContentOutlinePage)

Example 69 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project eclipse-cs by checkstyle.

the class CheckFileOnOpenPartListener method getEditorFile.

/**
 * Returns the file behind the referenced workbench part.
 *
 * @param partRef
 *          the workbench part in question
 * @return the editors file or <code>null</code> if the workbench part is no file based editor
 */
private IFile getEditorFile(IWorkbenchPartReference partRef) {
    if (!(partRef instanceof IEditorReference)) {
        return null;
    }
    IFile file = null;
    // fix for 3522695
    IWorkbenchPart part = partRef.getPart(false);
    // do *NOT* restore the part here to prevent startup issues with large
    // number of opened files
    // instead use a different path the rip the input file reference
    IEditorInput input = null;
    if (part != null && part instanceof IEditorPart) {
        IEditorPart editor = (IEditorPart) part;
        input = editor.getEditorInput();
    } else {
        // fix for 3522695 - rip input file from editor ref without initializing
        // the actual part
        IEditorReference editRef = (IEditorReference) partRef;
        input = getRestoredInput(editRef);
    }
    if (input instanceof FileEditorInput) {
        file = ((FileEditorInput) input).getFile();
    }
    return file;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput)

Example 70 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project eclipse-cs by checkstyle.

the class AbstractStatsView method createPartControl.

// 
// methods
// 
/**
 * {@inheritDoc}
 *
 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createPartControl(Composite parent) {
    mMainComposite = parent;
    // create and register the workspace focus listener
    mFocusListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            AbstractStatsView.this.focusSelectionChanged(part, selection);
        }
    };
    getSite().getPage().addSelectionListener(mFocusListener);
    focusSelectionChanged(getSite().getPage().getActivePart(), getSite().getPage().getSelection());
    // create and register the listener for resource changes
    mResourceListener = new IResourceChangeListener() {

        @Override
        public void resourceChanged(IResourceChangeEvent event) {
            IMarkerDelta[] markerDeltas = event.findMarkerDeltas(CheckstyleMarker.MARKER_ID, true);
            if (markerDeltas.length > 0) {
                refresh();
            }
        }
    };
    ResourcesPlugin.getWorkspace().addResourceChangeListener(mResourceListener);
    makeActions();
    initActionBars(getViewSite().getActionBars());
}
Also used : IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ISelectionListener(org.eclipse.ui.ISelectionListener)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)289 ISelection (org.eclipse.jface.viewers.ISelection)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)112 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)72 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)69 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)59 IEditorPart (org.eclipse.ui.IEditorPart)57 IFile (org.eclipse.core.resources.IFile)52 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)44 IResource (org.eclipse.core.resources.IResource)42 PartInitException (org.eclipse.ui.PartInitException)41 ArrayList (java.util.ArrayList)36 ISetSelectionTarget (org.eclipse.ui.part.ISetSelectionTarget)35 FileEditorInput (org.eclipse.ui.part.FileEditorInput)33 HashMap (java.util.HashMap)32 EObject (org.eclipse.emf.ecore.EObject)31 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)31 URI (org.eclipse.emf.common.util.URI)30 MissingResourceException (java.util.MissingResourceException)29 Resource (org.eclipse.emf.ecore.resource.Resource)29