Search in sources :

Example 31 with WorkbenchException

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

the class CheckFileOnOpenPartListener method getMementoE4.

private IMemento getMementoE4(IEditorReference e) {
    try {
        // can't use this as long as were still supporting E3
        // org.eclipse.e4.ui.model.application.MApplicationElement model =
        // e.getModel();
        // Map<String, String> state = model.getPersistedState()
        Method getModelMethod = e.getClass().getMethod("getModel", new Class<?>[0]);
        getModelMethod.setAccessible(true);
        Object model = getModelMethod.invoke(e, (Object[]) null);
        Method getPersistedStateMethod = model.getClass().getMethod("getPersistedState", new Class<?>[0]);
        getPersistedStateMethod.setAccessible(true);
        @SuppressWarnings("unchecked") Map<String, String> state = (Map<String, String>) getPersistedStateMethod.invoke(model, (Object[]) null);
        String memento = state.get("memento");
        if (memento != null) {
            try {
                return XMLMemento.createReadRoot(new StringReader(memento));
            } catch (WorkbenchException e1) {
                CheckstyleLog.log(e1);
            }
        }
    } catch (NoSuchMethodException e1) {
        CheckstyleLog.log(e1);
    } catch (SecurityException e1) {
        CheckstyleLog.log(e1);
    } catch (IllegalAccessException e1) {
        CheckstyleLog.log(e1);
    } catch (InvocationTargetException e1) {
        CheckstyleLog.log(e1);
    }
    return null;
}
Also used : StringReader(java.io.StringReader) Method(java.lang.reflect.Method) WorkbenchException(org.eclipse.ui.WorkbenchException) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project bndtools by bndtools.

the class ImportBndWorkspaceWizard method performFinish.

@Override
public boolean performFinish() {
    final ImportSettings importSettings = new ImportSettings(mainPage.getSelectedFolder(), mainPage.isDeleteSettings(), mainPage.isInferExecutionEnvironment());
    // create the new project operation
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException {
            try {
                importProjects(importSettings, monitor);
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error during import of Bnd workspace!", e));
            }
        }
    };
    Job importJob = new Job("Import Bnd Workspace") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                op.run(monitor);
            } catch (InvocationTargetException e) {
                Throwable t = e.getCause();
                if (t instanceof CoreException && ((CoreException) t).getStatus().getException() != null) {
                    // unwrap the cause of the CoreException
                    t = ((CoreException) t).getStatus().getException();
                }
                return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Could not finish import job for Bnd Workspace!", t);
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    importJob.schedule();
    try {
        // Prompt to switch to the BndTools perspective
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
        if (!"bndtools.perspective".equals(currentPerspective.getId())) {
            if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
                this.workbench.showPerspective("bndtools.perspective", window);
            }
        }
    } catch (WorkbenchException e) {
        error("Unable to switch to BndTools perspective", e);
    }
    return true;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) WorkbenchException(org.eclipse.ui.WorkbenchException) WorkbenchException(org.eclipse.ui.WorkbenchException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) Job(org.eclipse.core.runtime.jobs.Job)

Example 33 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project tesb-studio-se by Talend.

the class CreateESBAction method selectRootObject.

private void selectRootObject(Properties params) {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (null == workbenchWindow) {
        return;
    }
    IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
    if (null == workbenchPage) {
        return;
    }
    IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
    if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
        // show Integration perspective
        try {
            workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
            workbenchPage = workbenchWindow.getActivePage();
        } catch (WorkbenchException e) {
            ExceptionHandler.process(e);
            return;
        }
    }
    IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
    if (view != null) {
        Object type = params.get("type");
        if (ESBRepositoryNodeType.SERVICES.name().equals(type)) {
            RepositoryNode servicesNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(ESBRepositoryNodeType.SERVICES);
            if (servicesNode != null) {
                setWorkbenchPart(view);
                final StructuredViewer viewer = view.getViewer();
                if (viewer instanceof TreeViewer) {
                    ((TreeViewer) viewer).expandToLevel(servicesNode, 1);
                }
                viewer.setSelection(new StructuredSelection(servicesNode));
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) WorkbenchException(org.eclipse.ui.WorkbenchException) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 34 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project tesb-studio-se by Talend.

the class OpenWSDLEditorAction method run.

public void run(IIntroSite site, Properties params) {
    PlatformUI.getWorkbench().getIntroManager().closeIntro(PlatformUI.getWorkbench().getIntroManager().getIntro());
    IPerspectiveDescriptor currentPerspective = site.getPage().getPerspective();
    if (!PERSPECTIVE_ID.equals(currentPerspective.getId())) {
        // show required perspective
        IWorkbenchWindow workbenchWindow = site.getWorkbenchWindow();
        try {
            workbenchWindow.getWorkbench().showPerspective(PERSPECTIVE_ID, workbenchWindow);
        } catch (WorkbenchException e) {
            ExceptionHandler.process(e);
            return;
        }
    }
    // find repository node
    repositoryNode = (RepositoryNode) RepositorySeekerManager.getInstance().searchRepoViewNode(params.getProperty("nodeId"), false);
    if (null != repositoryNode) {
        // expand/select node item
        RepositoryManagerHelper.getRepositoryView().getViewer().setSelection(new StructuredSelection(repositoryNode));
        init(repositoryNode);
        doRun();
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) WorkbenchException(org.eclipse.ui.WorkbenchException)

Example 35 with WorkbenchException

use of org.eclipse.ui.WorkbenchException in project tesb-studio-se by Talend.

the class OpenTalendJobRefAction method run.

/* Will send a "open" request to the selected nodePart, so it will try to open the reference job.
     * If the "open" command success, then will try to switch the perspective to Integration.
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    // diable switch perspective suggestion dialog. just for defense.
    String notAskAutoSwitchToDIKey = "notAskAutoSwitchToDI";
    boolean oldValueNotSwitchToDiKey = PlatformUI.getPreferenceStore().getBoolean(notAskAutoSwitchToDIKey);
    PlatformUI.getPreferenceStore().setValue(notAskAutoSwitchToDIKey, true);
    // need to be  restore at the end .
    // open in editor, type and count already checked in calculateEnabled()
    List<?> selectedObjects = getSelectedObjects();
    Object select = selectedObjects.get(0);
    NodePart nodePart = (NodePart) select;
    nodePart.performRequest(new org.eclipse.gef.Request(REQUEST_TYPE_OPEN_NODE_PART));
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (activePage == null) {
        return;
    }
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor == null || activeEditor.getEditorSite() == null) {
        return;
    }
    Node node = (Node) nodePart.getModel();
    String selectedJobName = (String) node.getElementParameter(NODE_PARAM_SELECTED_JOB_NAME).getValue();
    String openJobName = activeEditor.getEditorInput().getName();
    if (!selectedJobName.equals(openJobName)) {
        return;
    }
    // open/switch editor success and then  try to switch perspective.
    try {
        // if current perspective is ORG_TALEND_RCP_INTEGRATION_PERSPECTIVE, will do nothing in under layer.
        PlatformUI.getWorkbench().showPerspective(ORG_TALEND_RCP_INTEGRATION_PERSPECTIVE, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
    } catch (WorkbenchException e) {
        e.printStackTrace();
    } finally {
        // Restore config of switch perspective suggestion dialog. just for defense.
        PlatformUI.getPreferenceStore().setValue(notAskAutoSwitchToDIKey, oldValueNotSwitchToDiKey);
    }
}
Also used : Node(org.talend.designer.core.ui.editor.nodes.Node) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) WorkbenchException(org.eclipse.ui.WorkbenchException)

Aggregations

WorkbenchException (org.eclipse.ui.WorkbenchException)37 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)16 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)15 IPerspectiveDescriptor (org.eclipse.ui.IPerspectiveDescriptor)11 IMemento (org.eclipse.ui.IMemento)7 IOException (java.io.IOException)6 IWorkbench (org.eclipse.ui.IWorkbench)5 IRepositoryView (org.talend.repository.ui.views.IRepositoryView)5 StringReader (java.io.StringReader)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 ProcessExplorerView (com.centurylink.mdw.plugin.designer.views.ProcessExplorerView)2 BufferedReader (java.io.BufferedReader)2