Java Examples for org.eclipse.ui.PartInitException

The following java examples will help you to understand the usage of org.eclipse.ui.PartInitException. These source code samples are taken from different open source projects.

Example 1
Project: android-essentials-toolbox-master  File: OpenPermissionUsageViewHandler.java View source code
/**
	 * Opens the permission usage view
	 */
public Object execute(final ExecutionEvent event) throws ExecutionException {
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            try {
                IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
                IViewPart view = page.showView(PermissionUsageView.ID);
                page.activate(view);
            } catch (PartInitException e) {
                DisplayUtils.showError(e, "Could not load Permissin Usage View.");
            }
        }
    });
    return null;
}
Example 2
Project: erlide-master  File: DebuggerTraceView.java View source code
// @Override
// public void createPartControl(final Composite parent) {
// viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL
// | SWT.MULTI | SWT.FULL_SELECTION));
// setViewer(viewer);
// super.createPartControl(parent);
// // parent.setLayout(new FillLayout());
//
// viewer.getTree().setLinesVisible(true);
// viewer.setUseHashlookup(true);
//
// createColumns();
//
// viewer.setContentProvider(getContentProvider());
// viewer.setLabelProvider(new ColumnLabelProvider());
// getSite().setSelectionProvider(viewer);
//
// viewer.setInput(this);
// DebugPlugin.getDefault().addDebugEventListener(this);
//
// // viewer.getTree().addTreeListener(new TreeAdapter() {
// // @Override
// // public void treeCollapsed(final TreeEvent e) {
// // removeExpandedCategory((MarkerCategory) e.item.getData());
// // }
// //
// // @Override
// // public void treeExpanded(final TreeEvent e) {
// // addExpandedCategory((MarkerCategory) e.item.getData());
// // }
// // });
//
// // // Set help on the view itself
// // viewer.getControl().addHelpListener(new HelpListener() {
// // public void helpRequested(HelpEvent e) {
// // Object provider = getAdapter(IContextProvider.class);
// // if (provider == null) {
// // return;
// // }
// //
// // IContext context = ((IContextProvider) provider)
// // .getContext(viewer.getControl());
// // PlatformUI.getWorkbench().getHelpSystem().displayHelp(context);
// // }
// //
// // });
//
// viewer.getTree().addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(final SelectionEvent e) {
// final Object o = getSelectedInTree();
// final String msg = o == null ? "" : o.toString(); //$NON-NLS-1$
// getViewSite().getActionBars().getStatusLineManager()
// .setMessage(msg);
//
// }
// });
//
// viewer.getTree().addMouseListener(new MouseListener() {
//
// public void mouseDoubleClick(final MouseEvent e) {
// final Object o = getSelectedInTree();
// if (o instanceof OtpErlangTuple) {
// final OtpErlangTuple t = (OtpErlangTuple) o;
// final OtpErlangTuple t2 = (OtpErlangTuple) t.elementAt(1);
// final OtpErlangTuple ieval = (OtpErlangTuple) t2
// .elementAt(0);
// final OtpErlangAtom mod = (OtpErlangAtom) ieval
// .elementAt(3);
// final String module = mod.atomValue();
// final OtpErlangLong lin = (OtpErlangLong) ieval
// .elementAt(2);
// try {
// final int line = lin.intValue();
// gotoModuleLine(module, line);
// } catch (final OtpErlangRangeException e1) {
// }
//
// }
// }
//
// public void mouseDown(final MouseEvent e) {
// }
//
// public void mouseUp(final MouseEvent e) {
// }
//
// });
// // PlatformUI.getWorkbench().getWorkingSetManager()
// // .addPropertyChangeListener(getWorkingSetListener());
//
// // registerContextMenu();
// // initDragAndDrop();
//
// }
protected void gotoModuleLine(final String moduleName, final int line) {
    final IWorkbenchWindow window = ErlideUIPlugin.getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    final IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    IEditorPart part = null;
    final IErlElementLocator model = ErlangEngine.getInstance().getModel();
    IErlModule module;
    try {
        module = model.findModule(moduleName);
    } catch (final ErlModelException e) {
        ErlLogger.error(e);
        return;
    }
    IEditorInput input = null;
    input = EditorUtility.getEditorInput(module);
    if (input != null) {
        final String editorId = EditorUtility.getEditorID(input, module);
        if (editorId != null) {
            try {
                part = page.openEditor(input, editorId);
            } catch (final PartInitException e) {
                ErlideUIPlugin.errorDialog(window.getShell(), "Go to File", "Exception occurred", e);
            }
        }
    }
    if (part instanceof ErlangEditor) {
        part.setFocus();
        final ErlangEditor ee = (ErlangEditor) part;
        final IDocument d = ee.getDocument();
        int lineStart, lineLength;
        try {
            lineStart = d.getLineOffset(line - 1);
            lineLength = d.getLineLength(line - 1);
            EditorUtility.revealInEditor(ee, lineStart, lineLength - 1);
        } catch (final BadLocationException e) {
            ErlLogger.error(e);
        }
    }
}
Example 3
Project: tcf-master  File: TCFModel.java View source code
/*
     * Open an editor for given editor input.
     * @param input - IEditorInput representing a source file to be shown in the editor
     * @param id - editor type ID
     * @param page - workbench page that will contain the editor
     * @return - IEditorPart if the editor was opened successfully, or null otherwise.
     */
private IEditorPart openEditor(final IEditorInput input, final String id, final IWorkbenchPage page) {
    final IEditorPart[] editor = new IEditorPart[] { null };
    Runnable r = new Runnable() {

        public void run() {
            if (!page.getWorkbenchWindow().getWorkbench().isClosing()) {
                try {
                    editor[0] = page.openEditor(input, id, false, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
                } catch (PartInitException e) {
                    Activator.log("Cannot open editor", e);
                }
            }
        }
    };
    BusyIndicator.showWhile(display, r);
    return editor[0];
}
Example 4
Project: Eclipse-Postfix-Code-Completion-master  File: JavadocView.java View source code
/**
	 * see also org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.addLinkListener(BrowserInformationControl)
	 *
	 * Add link listener to the given browser
	 * @param browser the browser to add a listener to
	 * @since 3.4
	 */
private void addLinkListener(Browser browser) {
    browser.addLocationListener(JavaElementLinks.createLocationListener(new JavaElementLinks.ILinkHandler() {

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleDeclarationLink(org.eclipse.jdt.core.IJavaElement)
			 */
        public void handleDeclarationLink(IJavaElement target) {
            try {
                JavadocHover.openDeclaration(target);
            } catch (PartInitException e) {
                JavaPlugin.log(e);
            } catch (JavaModelException e) {
                JavaPlugin.log(e);
            }
        }

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleExternalLink(java.net.URL, org.eclipse.swt.widgets.Display)
			 */
        public boolean handleExternalLink(final URL url, Display display) {
            if (fCurrent == null || !(fCurrent.getInputElement() instanceof URL && url.toExternalForm().equals(((URL) fCurrent.getInputElement()).toExternalForm()))) {
                fCurrent = new URLBrowserInput(fCurrent, url);
                if (fBackAction != null) {
                    fBackAction.update();
                    fForthAction.update();
                }
                if (fInputSelectionProvider != null)
                    fInputSelectionProvider.setSelection(new StructuredSelection(url));
            }
            return false;
        }

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleInlineJavadocLink(org.eclipse.jdt.core.IJavaElement)
			 */
        public void handleInlineJavadocLink(IJavaElement target) {
            JavaElementBrowserInput newInput = new JavaElementBrowserInput(fCurrent, target);
            JavadocView.this.setInput(newInput);
        }

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleJavadocViewLink(org.eclipse.jdt.core.IJavaElement)
			 */
        public void handleJavadocViewLink(IJavaElement target) {
            handleInlineJavadocLink(target);
        }

        /* (non-Javadoc)
			 * @see org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.ILinkHandler#handleTextSet()
			 */
        public void handleTextSet() {
            IJavaElement input = getOrignalInput();
            if (input == null)
                return;
            if (fCurrent == null || !fCurrent.getInputElement().equals(input)) {
                fCurrent = new JavaElementBrowserInput(null, input);
                if (fBackAction != null) {
                    fBackAction.update();
                    fForthAction.update();
                }
            }
        }
    }));
}
Example 5
Project: tdq-studio-se-master  File: RepositoryNodeHelper.java View source code
public static CommonViewer getDQCommonViewer(boolean open) {
    IViewPart part = null;
    CommonViewer commonViewer = null;
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow != null) {
        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        if (activePage != null) {
            part = activePage.findView(DQRESPOSITORYVIEW);
            if (part == null) {
                if (open) {
                    try {
                        part = activePage.showView(DQRESPOSITORYVIEW);
                        // open detail view at the same time
                        IViewPart detailPart = activePage.findView(DQRESPOSITORY_DETAIL_VIEW);
                        if (detailPart == null) {
                            activePage.showView(DQRESPOSITORY_DETAIL_VIEW);
                        }
                    } catch (PartInitException e) {
                        e.printStackTrace();
                    }
                    if (part == null) {
                        return null;
                    }
                } else {
                    return null;
                }
            }
            CommonNavigator dqView = (CommonNavigator) part;
            commonViewer = dqView.getCommonViewer();
        }
    }
    return commonViewer;
}
Example 6
Project: cdt-tests-runner-master  File: CPPSelectionTestsNoIndexer.java View source code
protected IASTNode testF3(IFile file, int offset, int length) throws ParserException, CoreException {
    if (offset < 0)
        //$NON-NLS-1$
        throw new ParserException("offset can not be less than 0 and was " + offset);
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart part = null;
    try {
        //$NON-NLS-1$
        part = page.openEditor(new FileEditorInput(file), "org.eclipse.cdt.ui.editor.CEditor");
        EditorTestHelper.joinReconciler(EditorTestHelper.getSourceViewer((AbstractTextEditor) part), 100, 5000, 10);
    } catch (PartInitException e) {
        assertFalse(true);
    }
    if (part instanceof ITextEditor) {
        ITextEditor editor = (ITextEditor) part;
        editor.getSelectionProvider().setSelection(new TextSelection(offset, length));
        //$NON-NLS-1$
        final OpenDeclarationsAction action = (OpenDeclarationsAction) ((AbstractTextEditor) part).getAction("OpenDeclarations");
        action.runSync();
        // the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
        ISelection sel = ((AbstractTextEditor) part).getSelectionProvider().getSelection();
        final IASTName[] result = { null };
        if (sel instanceof ITextSelection) {
            final ITextSelection textSel = (ITextSelection) sel;
            ITranslationUnit tu = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
            IStatus ok = ASTProvider.getASTProvider().runOnAST(tu, ASTProvider.WAIT_IF_OPEN, monitor, new ASTRunnable() {

                public IStatus runOnAST(ILanguage language, IASTTranslationUnit ast) throws CoreException {
                    result[0] = ast.getNodeSelector(null).findName(textSel.getOffset(), textSel.getLength());
                    return Status.OK_STATUS;
                }
            });
            assertTrue(ok.isOK());
            return result[0];
        }
    }
    return null;
}
Example 7
Project: codemap-master  File: NewCodemapCreationWizard.java View source code
@Override
public boolean performFinish() {
    String containerName = page.getContainerPath();
    String fileName = page.getFilename();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IResource resource = root.findMember(new Path(containerName));
    IContainer container = (IContainer) resource;
    final IFile file = container.getFile(new Path(fileName));
    try {
        InputStream stream = openContentStream();
        if (file.exists()) {
            file.setContents(stream, true, true, null);
        } else {
            file.create(stream, true, null);
        }
        stream.close();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            try {
                IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, true);
            } catch (PartInitException ex) {
                throw new RuntimeException(ex);
            }
        }
    });
    return true;
}
Example 8
Project: tmdm-studio-se-master  File: TransformerMainPage.java View source code
public void openInXSLTEditor() {
    refreshEnableState(false);
    try {
        //$NON-NLS-1$
        IPreferenceStore preference = new ScopedPreferenceStore(new InstanceScope(), "org.eclipse.wst.xsl.ui");
        //$NON-NLS-1$
        String charSet = preference.getString("outputCodeset");
        String xslcontent = parameterEditor.getContent().getContent();
        IFile file = FileProvider.createdTempFile(xslcontent, getXSLTFileName(), charSet);
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        xsltEditorInput = new XSLTFileEditorInput(file, new MainPageRefresher(), true);
        page.openEditor(xsltEditorInput, XSLTEditor.ID);
    } catch (PartInitException e) {
        log.error(e.getMessage(), e);
    }
}
Example 9
Project: aws-toolkit-eclipse-master  File: ConfigureAccountWizardPage.java View source code
private void openAwsExplorer() {
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            try {
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(AwsToolkitCore.EXPLORER_VIEW_ID);
            } catch (PartInitException e) {
                String errorMessage = "Unable to open the AWS Explorer view: " + e.getMessage();
                Status status = new Status(Status.ERROR, AwsToolkitCore.PLUGIN_ID, errorMessage, e);
                StatusManager.getManager().handle(status, StatusManager.LOG);
            }
        }
    });
}
Example 10
Project: eclipse-integration-commons-master  File: PluginManagerDialog.java View source code
/**
	 * Handles navigation from a hyperlink in the description area.
	 * 
	 * @param urlExpression
	 */
protected void handleNavigation(String urlExpression) {
    String errorMessage = null;
    try {
        URL url = new URL(urlExpression);
        boolean launched = Program.launch(url.toString());
        if (!launched) {
            IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
            try {
                if (support != null) {
                    IWebBrowser browser = support.getExternalBrowser();
                    if (browser != null) {
                        browser.openURL(url);
                        return;
                    } else {
                        errorMessage = "Unable to find browser support to navigate to URL. Check default browser support in Eclipse or OS";
                    }
                }
            } catch (PartInitException e) {
                errorMessage = "Unable to navigate to URL: " + e.getLocalizedMessage();
            }
        }
    } catch (MalformedURLException e) {
        errorMessage = "Unable to navigate to URL: " + e.getLocalizedMessage();
    }
    if (errorMessage != null) {
        InternalMessageDialogue dialog = new InternalMessageDialogue("Problems navigating to URL", errorMessage + ": " + urlExpression, MessageDialog.ERROR, false);
        dialog.open();
    }
}
Example 11
Project: platform_tools_motodev-master  File: AbstractAndroidView.java View source code
/**
     * Shows the Android Emulator view, if not being shown
     */
public static void showView() {
    info("Open and move focus to the emulator view");
    boolean emulatorViewOpened = !EclipseUtils.getAllOpenedViewsWithId(AndroidView.ANDROID_VIEW_ID).isEmpty();
    try {
        // show / refresh the emulator view.
        if (emulatorViewOpened) {
            EclipseUtils.showView(AndroidView.ANDROID_VIEW_ID);
        } else {
            if (showViewLock.tryLock()) {
                try {
                    boolean openEmulatorView = DialogWithToggleUtils.showQuestion(SHOW_EMULATOR_IN_THE_IDE_KEY_PREFERENCE, EmulatorNLS.QUESTION_AbstractAndroidView_OpenViewForStartedEmulatorsTitle, EmulatorNLS.QUESTION_AbstractAndroidView_OpenViewForStartedEmulatorsMessage);
                    if (openEmulatorView) {
                        EclipseUtils.showView(AndroidView.ANDROID_VIEW_ID);
                    }
                } finally {
                    showViewLock.unlock();
                }
            }
        }
    } catch (PartInitException e) {
        error("The Android Emulator View could not be opened programatically");
        EclipseUtils.showErrorDialog(EmulatorNLS.GEN_Error, EmulatorNLS.EXC_AbstractAndroidView_ViewNotAccessibleProgramatically);
    }
}
Example 12
Project: xmind-master  File: BlackBoxDialog.java View source code
private void handleOpen(File reversionFile, IBlackBoxMap map) {
    try {
        IWorkbook workbook = Core.getWorkbookBuilder().loadFromFile(reversionFile);
        IEditorInput input = MindMapUI.getEditorInputFactory().createEditorInputForPreLoadedWorkbook(workbook, new File(map.getSource()).getName());
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, MindMapUI.MINDMAP_EDITOR_ID);
        if (workbook instanceof ICoreEventSource2) {
            ((ICoreEventSource2) workbook).registerOnceCoreEventListener(Core.WorkbookPreSaveOnce, ICoreEventListener.NULL);
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (CoreException e1) {
        e1.printStackTrace();
    } catch (PartInitException e) {
        e.printStackTrace();
    }
}
Example 13
Project: CodingSpectator-master  File: TextMergeViewer.java View source code
/**
	 * This method returns [email protected] ITextEditor} used in the
	 * [email protected] ChangeEncodingAction}. It provides implementation of methods that
	 * are used by the action by delegating them to [email protected] ContributorInfo} that
	 * corresponds to the side that has focus.
	 * 
	 * @return the text editor adapter
	 */
private ITextEditor getTextEditorAdapter() {
    return new ITextEditor() {

        public void close(boolean save) {
        // Implementing interface method
        }

        public void doRevertToSaved() {
        // Implementing interface method
        }

        public IAction getAction(String actionId) {
            // Implementing interface method
            return null;
        }

        public IDocumentProvider getDocumentProvider() {
            // Implementing interface method
            return null;
        }

        public IRegion getHighlightRange() {
            // Implementing interface method
            return null;
        }

        public ISelectionProvider getSelectionProvider() {
            // Implementing interface method
            return null;
        }

        public boolean isEditable() {
            // Implementing interface method
            return false;
        }

        public void removeActionActivationCode(String actionId) {
        // Implementing interface method
        }

        public void resetHighlightRange() {
        // Implementing interface method
        }

        public void selectAndReveal(int offset, int length) {
        // Implementing interface method
        }

        public void setAction(String actionId, IAction action) {
        // Implementing interface method
        }

        public void setActionActivationCode(String actionId, char activationCharacter, int activationKeyCode, int activationStateMask) {
        // Implementing interface method
        }

        public void setHighlightRange(int offset, int length, boolean moveCursor) {
        // Implementing interface method
        }

        public void showHighlightRangeOnly(boolean showHighlightRangeOnly) {
        // Implementing interface method
        }

        public boolean showsHighlightRangeOnly() {
            // Implementing interface method
            return false;
        }

        public IEditorInput getEditorInput() {
            if (fFocusPart == fAncestor && fAncestorContributor != null) {
                return fAncestorContributor.getDocumentKey();
            } else if (fFocusPart == fLeft && fLeftContributor != null) {
                return fLeftContributor.getDocumentKey();
            } else if (fFocusPart == fRight && fRightContributor != null) {
                return fRightContributor.getDocumentKey();
            } else {
                return null;
            }
        }

        public IEditorSite getEditorSite() {
            // Implementing interface method
            return null;
        }

        public void init(IEditorSite site, IEditorInput input) throws PartInitException {
        // Implementing interface method
        }

        public void addPropertyListener(IPropertyListener listener) {
        // Implementing interface method
        }

        public void createPartControl(Composite parent) {
        // Implementing interface method
        }

        public void dispose() {
        // Implementing interface method
        }

        public IWorkbenchPartSite getSite() {
            // Implementing interface method
            return new IWorkbenchPartSite() {

                public String getId() {
                    // Implementing interface method
                    return null;
                }

                public IKeyBindingService getKeyBindingService() {
                    // Implementing interface method
                    return null;
                }

                public IWorkbenchPart getPart() {
                    // Implementing interface method
                    return null;
                }

                public String getPluginId() {
                    // Implementing interface method
                    return null;
                }

                public String getRegisteredName() {
                    // Implementing interface method
                    return null;
                }

                public void registerContextMenu(MenuManager menuManager, ISelectionProvider selectionProvider) {
                // Implementing interface method
                }

                public void registerContextMenu(String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) {
                // Implementing interface method
                }

                public IWorkbenchPage getPage() {
                    // Implementing interface method
                    return null;
                }

                public ISelectionProvider getSelectionProvider() {
                    // Implementing interface method
                    return null;
                }

                public Shell getShell() {
                    return fComposite.getShell();
                }

                public IWorkbenchWindow getWorkbenchWindow() {
                    // Implementing interface method
                    return null;
                }

                public void setSelectionProvider(ISelectionProvider provider) {
                // Implementing interface method
                }

                public Object getAdapter(Class adapter) {
                    // Implementing interface method
                    return null;
                }

                public Object getService(Class api) {
                    // Implementing interface method
                    return null;
                }

                public boolean hasService(Class api) {
                    // Implementing interface method
                    return false;
                }
            };
        }

        public String getTitle() {
            // Implementing interface method
            return null;
        }

        public Image getTitleImage() {
            // Implementing interface method
            return null;
        }

        public String getTitleToolTip() {
            // Implementing interface method
            return null;
        }

        public void removePropertyListener(IPropertyListener listener) {
        // Implementing interface method
        }

        public void setFocus() {
        // Implementing interface method
        }

        public Object getAdapter(Class adapter) {
            if (adapter == IEncodingSupport.class) {
                if (fFocusPart == fAncestor) {
                    return getEncodingSupport(fAncestorContributor);
                } else if (fFocusPart == fLeft) {
                    return getEncodingSupport(fLeftContributor);
                } else if (fFocusPart == fRight) {
                    return getEncodingSupport(fRightContributor);
                }
            }
            return null;
        }

        private IEncodingSupport getEncodingSupport(ContributorInfo contributor) {
            if (contributor != null && contributor.getDefaultEncoding() != null) {
                return contributor;
            }
            return null;
        }

        public void doSave(IProgressMonitor monitor) {
        // Implementing interface method
        }

        public void doSaveAs() {
        // Implementing interface method
        }

        public boolean isDirty() {
            if (fFocusPart == fLeft) {
                return isLeftDirty();
            } else if (fFocusPart == fRight) {
                return isRightDirty();
            }
            return false;
        }

        public boolean isSaveAsAllowed() {
            // Implementing interface method
            return false;
        }

        public boolean isSaveOnCloseNeeded() {
            // Implementing interface method
            return false;
        }
    };
}
Example 14
Project: substeps-eclipse-plugin-master  File: FeatureRunnerPlugin.java View source code
public SubstepsFeatureTestRunnerViewPart showTestRunnerViewPartInActivePage() {
    try {
        // Have to force the creation of view part contents
        // otherwise the UI will not be updated
        final IWorkbenchWindow window = getActiveWorkbenchWindow();
        final IWorkbenchPage page = window != null ? window.getActivePage() : null;
        if (page == null)
            return null;
        final SubstepsFeatureTestRunnerViewPart view = (SubstepsFeatureTestRunnerViewPart) page.findView(SubstepsFeatureTestRunnerViewPart.NAME);
        if (view == null) {
            // create and show the result view if it isn't created yet.
            return (SubstepsFeatureTestRunnerViewPart) page.showView(SubstepsFeatureTestRunnerViewPart.NAME, null, IWorkbenchPage.VIEW_VISIBLE);
        }
        return view;
    } catch (final PartInitException pie) {
        log(pie);
        return null;
    }
}
Example 15
Project: WS171-development-master  File: GraphicalLayoutEditor.java View source code
/**
     * Looks for a file matching the new [email protected] FolderConfiguration} and attempts to open it.
     * <p/>If there is no match, notify the user.
     */
private void onConfigurationChange() {
    mConfiguredFrameworkRes = mConfiguredProjectRes = null;
    if (mEditedFile == null || mEditedConfig == null) {
        return;
    }
    // get the resources of the file's project.
    ProjectResources resources = ResourceManager.getInstance().getProjectResources(mEditedFile.getProject());
    // from the resources, look for a matching file
    ResourceFile match = null;
    if (resources != null) {
        match = resources.getMatchingFile(mEditedFile.getName(), ResourceFolderType.LAYOUT, mCurrentConfig);
    }
    if (match != null) {
        if (match.getFile().equals(mEditedFile) == false) {
            try {
                IDE.openEditor(getSite().getWorkbenchWindow().getActivePage(), match.getFile().getIFile());
                // we're done!
                return;
            } catch (PartInitException e) {
            }
        }
        // at this point, we have not opened a new file.
        // update the configuration icons with the new edited config.
        setConfiguration(mEditedConfig, false);
        // enable the create button if the current and edited config are not equals
        mCreateButton.setEnabled(mEditedConfig.equals(mCurrentConfig) == false);
        // Even though the layout doesn't change, the config changed, and referenced
        // resources need to be updated.
        recomputeLayout();
    } else {
        // update the configuration icons with the new edited config.
        displayConfigError();
        // enable the Create button
        mCreateButton.setEnabled(true);
        // display the error.
        String message = String.format("No resources match the configuration\n \n\t%1$s\n \nChange the configuration or create:\n \n\tres/%2$s/%3$s\n \nYou can also click the 'Create' button above.", mCurrentConfig.toDisplayString(), mCurrentConfig.getFolderName(ResourceFolderType.LAYOUT), mEditedFile.getName());
        showErrorInEditor(message);
    }
}
Example 16
Project: teiid-designer-master  File: XsdEditor.java View source code
/**
     * This is called during startup.
     */
@Override
public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
    if (editorInput instanceof IFileEditorInput) {
        // get the XSD resource.
        try {
            // Get the IFile associated with the editor
            final IResource xsdFile = ((IFileEditorInput) editorInput).getFile();
            if (xsdFile == null) {
                //$NON-NLS-1$
                final String msg = XsdUiPlugin.Util.getString("XsdEditor.Input_Error__Model_Editor_cannot_open_{0}_2", editorInput.getName());
                throw new PartInitException(msg);
            }
            // Get the EMF resource for the IFile in the workspace
            final String xsdLocation = xsdFile.getLocation().toString();
            final URI xsdUri = URI.createFileURI(xsdLocation);
            xsdResource = ModelerCore.getModelContainer().getResource(xsdUri, true);
            // The resource must exist in the container
            if (xsdResource == null) {
                //$NON-NLS-1$
                final String msg = XsdUiPlugin.Util.getString("XsdEditor.Input_Error__Model_Editor_cannot_open_{0}_1", editorInput.getName());
                throw new PartInitException(msg);
            }
            // modelProject =
            xsdFile.getProject();
        } catch (ModelWorkspaceException e) {
            final String msg = XsdUiPlugin.Util.getString("XsdEditor.Input_Error__Model_Editor_cannot_open_{0}_2", editorInput.getName());
            throw new PartInitException(msg, e);
        } catch (CoreException e) {
            final String msg = XsdUiPlugin.Util.getString("XsdEditor.Input_Error__Model_Editor_cannot_open_{0}_2", editorInput.getName());
            throw new PartInitException(msg, e);
        }
        setSite(site);
        setInput(editorInput);
        setPartName(((IFileEditorInput) editorInput).getFile().getName());
        // EATM
        site.setSelectionProvider(new MultiPageSelectionProvider(this));
        site.getPage().addPartListener(partListener);
    } else {
        throw new PartInitException(//$NON-NLS-1$
        XsdUiPlugin.Util.getString("XsdEditor.Invalid_Input__Must_be_IFileEditorInput._33"));
    }
}
Example 17
Project: warlock2-master  File: StormFrontGameView.java View source code
protected Menu createProfileMenu(final Button connections) {
    Menu menu = new Menu(connections);
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent e) {
            connections.setSelection(true);
        }

        public void menuHidden(MenuEvent e) {
            connections.setSelection(false);
        }
    });
    for (final Profile profile : ProfileConfiguration.instance().getAllProfiles()) {
        MenuItem item = new MenuItem(menu, SWT.PUSH);
        item.setText(profile.getName());
        item.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_CHARACTER));
        item.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent e) {
                ProfileConnectAction action = new ProfileConnectAction(profile);
                action.setGameView(StormFrontGameView.this);
                action.run();
                hidePopup(reconnectPopup);
            //					reconnectPopup.setVisible(false);
            }
        });
    }
    MenuItem item = new MenuItem(menu, SWT.SEPARATOR);
    item = new MenuItem(menu, SWT.PUSH);
    item.setText("All Connections...");
    item.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_CONNECT));
    item.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            try {
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ConnectionView.VIEW_ID);
            } catch (PartInitException e1) {
                e1.printStackTrace();
            }
        }
    });
    return menu;
}
Example 18
Project: eclipse-commons-master  File: EditorUtils.java View source code
/**
	 * Returns the editor in which the given file is open, if there is any.
	 */
public static IEditorPart getEditorWithFile(IFile file) {
    IEditorReference[] editorReferences = EditorUtils.getOpenEditors();
    for (IEditorReference editorReference : editorReferences) {
        IEditorInput editorInput;
        try {
            editorInput = editorReference.getEditorInput();
        } catch (PartInitException e) {
            continue;
        }
        if (editorInput instanceof FileEditorInput) {
            FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
            if (fileEditorInput.getFile().equals(file)) {
                return editorReference.getEditor(false);
            }
        }
    }
    return null;
}
Example 19
Project: windowtester-master  File: WTConvertAPIContextBuilderTool.java View source code
/**
	 * Scan the workspace and create the files.
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    wbShell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
    // Instantiate the files to be written
    String ymdhms = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    IFile wtTypesFile = getFile("wt-types", ymdhms);
    if (wtTypesFile == null)
        return null;
    IFile wtStaticMembersFile = getFile("wt-static-members", ymdhms);
    if (wtStaticMembersFile == null)
        return null;
    try {
        new ProgressMonitorDialog(wbShell).run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    scanWorkspace(monitor);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (Exception e) {
        if (e instanceof InvocationTargetException)
            e = (InvocationTargetException) e;
        new ExceptionDetailsDialog(wbShell, "Exception", "Failed to generate content for " + wtTypesFile.getFullPath(), e).open();
        return null;
    }
    // Write the results to the files
    writeFile(wtTypesFile, wtTypes);
    writeFile(wtStaticMembersFile, wtStaticMembers);
    try {
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IDE.openEditor(activePage, wtTypesFile);
        IDE.openEditor(activePage, wtStaticMembersFile);
    } catch (PartInitException e) {
        new ExceptionDetailsDialog(wbShell, "Exception", "Failed to open editors for generated files.", e);
    }
    return null;
}
Example 20
Project: tern.java-master  File: CallHierarchyUI.java View source code
/**
     * @return <code>true</code> iff no error occurred while trying to
     *  open the editor, <code>false</code> iff an error dialog was raised.
     */
public static boolean openInEditor(Object element, Shell shell, String title) {
    CallLocation callLocation = CallHierarchy.getCallLocation(element);
    try {
        IMember enclosingMember;
        int selectionStart;
        int selectionLength;
        if (callLocation != null) {
            enclosingMember = callLocation.getMember();
            selectionStart = callLocation.getStart();
            selectionLength = callLocation.getEnd() - selectionStart;
        } else if (element instanceof MethodWrapper) {
            enclosingMember = ((MethodWrapper) element).getMember();
            if (enclosingMember.isVirtual()) {
                selectionStart = 0;
                selectionLength = 0;
            } else {
                ISourceRange selectionRange = enclosingMember.getNameRange();
                if (selectionRange == null)
                    selectionRange = enclosingMember.getSourceRange();
                if (selectionRange == null)
                    return true;
                selectionStart = selectionRange.getOffset();
                selectionLength = selectionRange.getLength();
            }
        } else {
            return true;
        }
        boolean activateOnOpen = OpenStrategy.activateOnOpen();
        IEditorPart methodEditor = JavaScriptUI.openInEditor(enclosingMember, activateOnOpen, false);
        if (methodEditor instanceof ITextEditor) {
            ITextEditor editor = (ITextEditor) methodEditor;
            editor.selectAndReveal(selectionStart, selectionLength);
        }
        return true;
    } catch (JavaScriptModelException e) {
        JavaScriptPlugin.log(new Status(IStatus.ERROR, JavaScriptPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, CallHierarchyMessages.CallHierarchyUI_open_in_editor_error_message, e));
        ErrorDialog.openError(shell, title, CallHierarchyMessages.CallHierarchyUI_open_in_editor_error_message, e.getStatus());
        return false;
    } catch (PartInitException x) {
        String name;
        if (callLocation != null)
            name = callLocation.getCalledMember().getElementName();
        else if (element instanceof MethodWrapper)
            name = ((MethodWrapper) element).getName();
        else
            name = "";
        MessageDialog.openError(shell, title, Messages.format(CallHierarchyMessages.CallHierarchyUI_open_in_editor_error_messageArgs, new String[] { name, x.getMessage() }));
        return false;
    }
}
Example 21
Project: eclipse.jdt.ui-master  File: TestRunnerViewPart.java View source code
public void showTestResultsView() {
    IWorkbenchWindow window = getSite().getWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();
    TestRunnerViewPart testRunner = null;
    if (page != null) {
        // show the result view
        try {
            testRunner = (TestRunnerViewPart) page.findView(TestRunnerViewPart.NAME);
            if (testRunner == null) {
                IWorkbenchPart activePart = page.getActivePart();
                testRunner = (TestRunnerViewPart) page.showView(TestRunnerViewPart.NAME, null, IWorkbenchPage.VIEW_VISIBLE);
                //restore focus
                page.activate(activePart);
            } else {
                page.bringToTop(testRunner);
            }
        } catch (PartInitException pie) {
            JUnitPlugin.log(pie);
        }
    }
}
Example 22
Project: EclipseTrader-master  File: WatchListView.java View source code
/* (non-Javadoc)
     * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
     */
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
    super.init(site, memento);
    ImageRegistry imageRegistry = UIActivator.getDefault().getImageRegistry();
    BundleContext bundleContext = UIActivator.getDefault().getBundle().getBundleContext();
    ServiceReference<IRepositoryService> serviceReference = bundleContext.getServiceReference(IRepositoryService.class);
    repositoryService = bundleContext.getService(serviceReference);
    try {
        dialogSettings = UIActivator.getDefault().getDialogSettings().getSection(K_VIEWS).getSection(site.getSecondaryId());
        uri = new URI(dialogSettings.get(K_URI));
        IWatchList watchList = repositoryService.getWatchListFromURI(uri);
        if (watchList instanceof WatchList) {
            this.watchList = (WatchList) watchList;
        }
    } catch (Exception e) {
        if (uri == null || watchList == null) {
            throw new PartInitException(NLS.bind("Unable to load view {0}", new Object[] { uri != null ? uri.toString() : "" }), e);
        }
    }
    if (uri == null || watchList == null) {
        throw new PartInitException(NLS.bind("Unable to load view {0}", new Object[] { uri != null ? uri.toString() : "" }));
    }
    columnsSection = dialogSettings.getSection(COLUMNS_SECTION);
    if (columnsSection == null) {
        columnsSection = dialogSettings.addNewSection(COLUMNS_SECTION);
    }
    preferenceStore = UIActivator.getDefault().getPreferenceStore();
    pricingEnvironment = new MarketPricingEnvironment(UIActivator.getDefault().getMarketService());
    deleteAction = new Action("Delete") {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (selection.size() != 0) {
                model.getObservableItems().removeAll(selection.toList());
            }
        }
    };
    deleteAction.setImageDescriptor(imageRegistry.getDescriptor(UIConstants.DELETE_EDIT_ICON));
    deleteAction.setDisabledImageDescriptor(imageRegistry.getDescriptor(UIConstants.DELETE_EDIT_DISABLED_ICON));
    deleteAction.setId(ActionFactory.DELETE.getId());
    //$NON-NLS-1$
    deleteAction.setActionDefinitionId("org.eclipse.ui.edit.delete");
    deleteAction.setEnabled(false);
    settingsAction = new SettingsAction(site.getShell(), this);
    IActionBars actionBars = site.getActionBars();
    actionBars.setGlobalActionHandler(settingsAction.getId(), settingsAction);
    actionBars.setGlobalActionHandler(deleteAction.getId(), deleteAction);
    actionBars.updateActionBars();
}
Example 23
Project: c4jplugin-master  File: NewContractWizard.java View source code
protected void openResource(final IResource resource) {
    if (resource.getType() == IResource.FILE) {
        IWorkbench workbench = C4JActivator.getDefault().getWorkbench();
        if (workbench == null)
            return;
        IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow();
        if (activeWindow == null)
            return;
        final IWorkbenchPage activePage = activeWindow.getActivePage();
        if (activePage != null) {
            final Display display = Display.getDefault();
            if (display != null) {
                display.asyncExec(new Runnable() {

                    public void run() {
                        try {
                            IDE.openEditor(activePage, (IFile) resource, true);
                        } catch (PartInitException e) {
                            C4JActivator.log(e);
                        }
                    }
                });
            }
        }
    }
}
Example 24
Project: liferay-ide-master  File: UpgradeView.java View source code
private void restartUpgradeTool() {
    boolean openNewLiferayProjectWizard = MessageDialog.openQuestion(UIUtil.getActiveShell(), "Restart code upgrade?", "All previous configuration files will be deleted. Do you want to restart the code upgrade tool?");
    if (openNewLiferayProjectWizard) {
        CustomJspConverter.clearConvertResults();
        try {
            MigrationProblemsContainer container = UpgradeAssistantSettingsUtil.getObjectFromStore(MigrationProblemsContainer.class);
            if (container != null) {
                UpgradeAssistantSettingsUtil.setObjectToStore(MigrationProblemsContainer.class, null);
            }
        } catch (IOException excepiton) {
            ProjectUI.logError(excepiton);
        }
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        UpgradeView view = (UpgradeView) UIUtil.findView(UpgradeView.ID);
        CustomJspConverter.clearConvertResults();
        page.hideView(view);
        UpgradeSettingsUtil.resetStoreProperties();
        try {
            page.showView(UpgradeView.ID);
        } catch (PartInitException e1) {
            e1.printStackTrace();
        }
    }
}
Example 25
Project: Curators-Workbench-master  File: EditAccessControlsCommand.java View source code
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IWorkbenchPage page = window.getActivePage();
    IViewPart view = page.findView(MetsProjectNavigator.ID);
    // Get the selection
    ISelection selection = view.getSite().getSelectionProvider().getSelection();
    if (selection != null && selection instanceof IStructuredSelection) {
        IStructuredSelection s = (IStructuredSelection) selection;
        DivType d = (DivType) s.getFirstElement();
        MetsProjectNature n = MetsProjectNature.getNatureForMetsObject(d);
        MdSecType rightsSec = null;
        for (MdSecType md : d.getMdSec()) {
            if (METSConstants.MD_STATUS_USER_EDITED.equals(md.getSTATUS())) {
                if (MetsPackage.eINSTANCE.getAmdSecType_RightsMD().equals(md.eContainingFeature())) {
                    rightsSec = md;
                    break;
                }
            }
        }
        if (rightsSec == null) {
            AmdSecType amdSec = MetsFactory.eINSTANCE.createAmdSecType();
            n.getMets().getAmdSec().add(amdSec);
            rightsSec = MetsFactory.eINSTANCE.createMdSecType();
            rightsSec.setSTATUS(METSConstants.MD_STATUS_USER_EDITED);
            rightsSec.setCREATED(new XMLCalendar(new java.util.Date(System.currentTimeMillis()), XMLCalendar.DATETIME));
            rightsSec.setID(METSUtils.makeXMLUUID());
            amdSec.getRightsMD().add(rightsSec);
            // link div to rightsMD
            d.getMdSec().add(rightsSec);
        }
        AccessControlType acl = null;
        try {
            Object o = rightsSec.getMdWrap().getXmlData().getAny().getValue(0);
            if (o != null && o instanceof AccessControlType) {
                acl = (AccessControlType) o;
            }
        } catch (NullPointerException e) {
        }
        if (acl == null) {
            XmlDataType1 xml = MetsFactory.eINSTANCE.createXmlDataType1();
            acl = AclFactory.eINSTANCE.createAccessControlType();
            // acl.setID(METSUtils.makeXMLUUID());
            xml.getAny().add(AclPackage.eINSTANCE.getDocumentRoot_AccessControl(), acl);
            MdWrapType wrap = MetsFactory.eINSTANCE.createMdWrapType();
            wrap.setMDTYPE(MDTYPEType.OTHER);
            wrap.setXmlData(xml);
            rightsSec.setMdWrap(wrap);
        }
        try {
            n.save();
        } catch (CoreException e) {
            throw new ExecutionException("There were unexpected problems opening the MODS Editor", e);
        }
        String uriFrag = acl.eResource().getURIFragment(acl);
        URIFragmentEditorInput input = new URIFragmentEditorInput(n.getProject().getName(), uriFrag, "Access Controls for '" + d.getLABEL1() + "'", acl);
        try {
            page.openEditor(input, "workbench_plugin.accessControlEditor");
        } catch (PartInitException e) {
            throw new ExecutionException("There were unexpected problems opening the ACL Editor", e);
        }
    }
    return null;
}
Example 26
Project: cdo-master  File: CDOEditor.java View source code
/**
   * Updates the problems indication with the information described in the specified diagnostic.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
protected void updateProblemIndication() {
    if (updateProblemIndication) {
        BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.OK, "org.eclipse.emf.cdo.ui", 0, null, new Object[] { editingDomain.getResourceSet() });
        for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values()) {
            if (childDiagnostic.getSeverity() != Diagnostic.OK) {
                diagnostic.add(childDiagnostic);
            }
        }
        int lastEditorPage = getPageCount() - 1;
        if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) {
            ((ProblemEditorPart) getEditor(lastEditorPage)).setDiagnostic(diagnostic);
            if (diagnostic.getSeverity() != Diagnostic.OK) {
                setActivePage(lastEditorPage);
            }
        } else if (diagnostic.getSeverity() != Diagnostic.OK) {
            ProblemEditorPart problemEditorPart = new ProblemEditorPart();
            problemEditorPart.setDiagnostic(diagnostic);
            try {
                addPage(++lastEditorPage, problemEditorPart, getEditorInput());
                setPageText(lastEditorPage, problemEditorPart.getPartName());
                setActivePage(lastEditorPage);
                showTabs();
            } catch (PartInitException exception) {
                PluginDelegator.INSTANCE.log(exception);
            }
        }
    }
}
Example 27
Project: swtbot-master  File: SWTBotView.java View source code
@Override
public void show() {
    UIThreadRunnable.syncExec(new VoidResult() {

        public void run() {
            try {
                partReference.getPage().activate(partReference.getPart(true));
                partReference.getPage().showView(partReference.getId(), partReference.getSecondaryId(), IWorkbenchPage.VIEW_ACTIVATE);
            } catch (PartInitException e) {
                throw new RuntimeException("Could not show partReference - " + partReference.getPartName(), e);
            }
        }
    });
}
Example 28
Project: cdt-master  File: BaseSelectionTestsIndexer.java View source code
protected ISelection testF3Selection(IFile file, int offset, int length) throws ParserException {
    if (offset < 0)
        //$NON-NLS-1$
        throw new ParserException("offset can not be less than 0 and was " + offset);
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart part = null;
    try {
        part = page.openEditor(new FileEditorInput(file), getEditorID());
    } catch (PartInitException e) {
        assertFalse(true);
    }
    if (part instanceof AbstractTextEditor) {
        ((AbstractTextEditor) part).getSelectionProvider().setSelection(new TextSelection(offset, length));
        //$NON-NLS-1$
        final IAction action = ((AbstractTextEditor) part).getAction("OpenDeclarations");
        action.run();
        // update the file/part to point to the newly opened IFile/IEditorPart
        part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        IEditorInput input = part.getEditorInput();
        if (input instanceof FileEditorInput) {
            file = ((FileEditorInput) input).getFile();
        } else {
            // bail!
            assertFalse(true);
        }
        // the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU
        return ((AbstractTextEditor) part).getSelectionProvider().getSelection();
    }
    return null;
}
Example 29
Project: extFM-Tooling-master  File: StageconfigEditor.java View source code
/**
    * Updates the problems indication with the information described in the specified diagnostic.
    * <!-- begin-user-doc -->
    * <!-- end-user-doc -->
    * @generated
    */
protected void updateProblemIndication() {
    if (updateProblemIndication) {
        BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.OK, "org.js.model.stageconfig.editor", 0, null, new Object[] { editingDomain.getResourceSet() });
        for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values()) {
            if (childDiagnostic.getSeverity() != Diagnostic.OK) {
                diagnostic.add(childDiagnostic);
            }
        }
        int lastEditorPage = getPageCount() - 1;
        if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) {
            ((ProblemEditorPart) getEditor(lastEditorPage)).setDiagnostic(diagnostic);
            if (diagnostic.getSeverity() != Diagnostic.OK) {
                setActivePage(lastEditorPage);
            }
        } else if (diagnostic.getSeverity() != Diagnostic.OK) {
            ProblemEditorPart problemEditorPart = new ProblemEditorPart();
            problemEditorPart.setDiagnostic(diagnostic);
            problemEditorPart.setMarkerHelper(markerHelper);
            try {
                addPage(++lastEditorPage, problemEditorPart, getEditorInput());
                setPageText(lastEditorPage, problemEditorPart.getPartName());
                setActivePage(lastEditorPage);
                showTabs();
            } catch (PartInitException exception) {
                StageconfigEditorPlugin.INSTANCE.log(exception);
            }
        }
        if (markerHelper.hasMarkers(editingDomain.getResourceSet())) {
            markerHelper.deleteMarkers(editingDomain.getResourceSet());
            if (diagnostic.getSeverity() != Diagnostic.OK) {
                try {
                    markerHelper.createMarkers(diagnostic);
                } catch (CoreException exception) {
                    StageconfigEditorPlugin.INSTANCE.log(exception);
                }
            }
        }
    }
}
Example 30
Project: arquillian-eclipse-master  File: ArquillianWizard.java View source code
protected void openResource(final IResource resource) {
    if (resource.getType() == IResource.FILE) {
        final IWorkbenchPage activePage = ArquillianUIUtil.getActivePage();
        if (activePage != null) {
            final Display display = Display.getDefault();
            if (display != null) {
                display.asyncExec(new Runnable() {

                    public void run() {
                        try {
                            IDE.openEditor(activePage, (IFile) resource, true);
                        } catch (PartInitException e) {
                            ArquillianUIActivator.log(e);
                        }
                    }
                });
            }
        }
    }
}
Example 31
Project: LanguageBuddy-master  File: TestView.java View source code
protected void restoreView() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();
    try {
        IPerspectiveDescriptor editPerspective = PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(EditPerspective.ID);
        page.setPerspective(editPerspective);
        page.showView(EditPerspective.TEST_VIEW);
        IViewReference viewRef = (IViewReference) page.getReference(this);
        if (viewRef != null && page.isPageZoomed() == true) {
            // should we add a page listener to watch for when the zoom is lost?
            page.toggleZoom(viewRef);
        }
    } catch (PartInitException e) {
        e.printStackTrace();
    }
}
Example 32
Project: pmd-eclipse-plugin-master  File: RuleDialog.java View source code
/**
     * Build the open external info url button
     */
private Button buildOpenExternalInfoUrlButton(Composite parent) {
    final Button button = new Button(parent, SWT.PUSH);
    button.setText(getMessage(StringKeys.PREF_RULEEDIT_BUTTON_OPEN_EXTERNAL_INFO_URL));
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String url = externalInfoUrlText.getText().trim();
            if (url.length() > 0) {
                try {
                    IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
                    browser.openURL(new URL(url));
                } catch (PartInitException e) {
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    return button;
}
Example 33
Project: rinzo-xml-editor-master  File: OpenElementAction.java View source code
private void openFile(String filePath) {
    try {
        IFile file = this.getSelectedFile(filePath);
        if (file == null) {
            return;
        }
        if (this.activePage == null) {
            IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (activeWorkbenchWindow == null) {
                return;
            }
            this.activePage = activeWorkbenchWindow.getActivePage();
            if (this.activePage == null) {
                return;
            }
        }
        IDE.openEditor(this.activePage, file);
    // this.activePage.openEditor(editorInput,
    // this.getDefauiltEditor(fileName).getId());
    } catch (PartInitException exception) {
        throw new RuntimeException(exception);
    }
}
Example 34
Project: Disco-Build-System-master  File: MainEditor.java View source code
/*=====================================================================================*
	 * PUBLIC METHODS
	 *=====================================================================================*/
/* (non-Javadoc)
	 * @see org.eclipse.ui.part.MultiPageEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
	 */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    if (!(input instanceof IURIEditorInput)) {
        throw new PartInitException("Invalid Input: Must be IURIEditorInput");
    }
    super.init(site, input);
    /* open the BuildStore file we're editing */
    IURIEditorInput editorInput = (IURIEditorInput) input;
    URI uri = editorInput.getURI();
    if (uri == null) {
        throw new PartInitException("Invalid Input: File URI is invalid");
    }
    fileInput = new File(uri.getPath());
    // TODO: handle the case where multiple editors have the same BuildStore open.
    // TODO: put a top-level catch for FatalBuildStoreException() (and other
    // exceptions) to display a meaningful error.
    buildStore = EclipsePartUtils.getNewBuildStore(fileInput.getPath());
    if (buildStore == null) {
        throw new PartInitException("Can't open the BuildML database.");
    }
    pkgMgr = buildStore.getPackageMgr();
    pkgRootMgr = buildStore.getPackageRootMgr();
    /* 
		 * Register to learn about changes to resources in our workspace. We might need to
		 * know if somebody deletes or renames the file we're editing.
		 */
    ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
    /* Listen to changes in the package naming */
    pkgMgr.addListener(this);
    /*
		 * Create a refactor manager that will be responsible for doing refactoring
		 * (deletion, merging, etc) for this BuildStore. This also handles the undo/redo
		 * of those operations.
		 */
    importRefactorer = new ImportRefactorer(buildStore);
    /* Ensure that our focus-gain activities are enabled */
    setFocus();
}
Example 35
Project: violetumleditor-master  File: NewWizard.java View source code
/**
     * Called by performFinish(). Create new file wirh default content and then open editor
     * 
     * @param file
     * @param monitor
     * @throws CoreException
     */
private void doFinish(final IFile file, IProgressMonitor monitor) throws CoreException {
    ByteArrayOutputStream bos = null;
    ByteArrayInputStream bis = null;
    try {
        IGraph graph = this.getUMLGraph();
        bos = new ByteArrayOutputStream();
        this.filePersistenceService.write(graph, bos);
        byte[] content = bos.toByteArray();
        bis = new ByteArrayInputStream(content);
        file.setContents(bis, true, true, monitor);
    } finally {
        try {
            if (bos != null) {
                bos.close();
            }
            if (bis != null) {
                bis.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    monitor.worked(1);
    monitor.setTaskName("Opening file for editing...");
    getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            try {
                IDE.setDefaultEditor(file, "com.horstmann.violet.eclipseplugin.editors.VioletUMLEditor");
                IDE.openEditor(page, file, "com.horstmann.violet.eclipseplugin.editors.VioletUMLEditor", true);
            } catch (PartInitException e) {
            }
        }
    });
    monitor.worked(1);
}
Example 36
Project: turmeric-eclipse-master  File: ErrorRegistryView.java View source code
private void createClientArea(Composite parent, FormToolkit toolkit) throws Exception {
    // TypeLibrary viewer
    final Group errorLibGroup = new Group(parent, SWT.SHADOW_ETCHED_OUT);
    errorLibGroup.setBackground(toolkit.getColors().getBackground());
    errorLibGroup.setText(SOAMessages.ERROR_LIBRARIES);
    errorLibGroup.setToolTipText(SOAMessages.ERROR_LIBRARIES);
    errorLibGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    final FillLayout layout = new FillLayout(SWT.VERTICAL);
    layout.marginHeight = 5;
    errorLibGroup.setLayout(layout);
    final Tree typeLibTree = toolkit.createTree(errorLibGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE);
    // typeLibTree.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    errorLibraryViewer = new TreeViewer(typeLibTree);
    errorLibraryViewer.setContentProvider(new ErrorLibViewContentProvider());
    errorLibraryViewer.setLabelProvider(new ErrorLibViewLabelProvider());
    errorLibraryViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IViewPart view = UIUtil.getActivePage().findView(SOAPerspectiveFactory.VIEWID_PROPERTY);
            if (view == null) {
                //if the Properties view is not opened yet, then open it automatically
                try {
                    UIUtil.getActivePage().showView(SOAPerspectiveFactory.VIEWID_PROPERTY);
                } catch (PartInitException e) {
                    logger.error(e);
                }
            }
        }
    });
    errorLibraryViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            boolean result = false;
            if (searchError != null && StringUtils.isNotBlank(searchError.getText())) {
                if (element instanceof ISOAError) {
                    return isMatch(((ISOAError) element).getName(), searchError.getText());
                } else if (element instanceof ISOAErrDomain) {
                    if (!isMatch(((ISOAErrDomain) element).getName(), searchError.getText())) {
                        for (ISOAError err : ((ISOAErrDomain) element).getErrors()) {
                            if (StringUtils.contains(err.getName(), searchError.getText())) {
                                return true;
                            }
                        }
                    } else {
                        return true;
                    }
                } else if (element instanceof ISOAErrLibrary) {
                    result = isMatch(((ISOAErrLibrary) element).getName(), searchError.getText());
                    if (result != true) {
                        for (ISOAErrDomain domain : ((ISOAErrLibrary) element).getDomains()) {
                            if (!isMatch(domain.getName(), searchError.getText())) {
                                for (ISOAError err : domain.getErrors()) {
                                    if (isMatch(err.getName(), searchError.getText())) {
                                        return true;
                                    }
                                }
                            } else {
                                return true;
                            }
                        }
                    }
                }
                return result;
            }
            return true;
        }
    });
    errorLibraryViewer.setInput(SOAErrContentFactory.getProvider());
    errorLibraryViewer.getControl().setToolTipText(SOAMessages.TREE_TIP);
    {
        int ops = DND.DROP_COPY | DND.DROP_MOVE;
        Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
        errorLibraryViewer.addDragSupport(ops, transfers, new ErrorViewerDragListener(errorLibraryViewer));
    }
    getSite().setSelectionProvider(errorLibraryViewer);
}
Example 37
Project: earthsci-master  File: WorkbenchPage.java View source code
/**
	 * Shows a view.
	 * 
	 * Assumes that a busy cursor is active.
	 */
protected IViewPart busyShowView(String viewId, int mode) throws PartInitException {
    switch(mode) {
        case VIEW_ACTIVATE:
        case VIEW_VISIBLE:
        case VIEW_CREATE:
            break;
        default:
            throw new IllegalArgumentException(WorkbenchMessages.WorkbenchPage_IllegalViewMode);
    }
    MPart part = findPart(viewId, EModelService.ANYWHERE);
    if (part == null) {
        MPlaceholder ph = partService.createSharedPart(viewId, false);
        if (ph == null) {
            throw new PartInitException(NLS.bind(WorkbenchMessages.ViewFactory_couldNotCreate, viewId));
        }
        part = (MPart) ph.getRef();
        part.setCurSharedRef(ph);
        part = showPart(mode, part);
        CompatibilityView compatibilityView = (CompatibilityView) part.getObject();
        if (compatibilityView != null) {
            IWorkbenchPartReference ref = compatibilityView.getReference();
            legacyWindow.firePerspectiveChanged(this, getPerspective(), ref, CHANGE_VIEW_SHOW);
            legacyWindow.firePerspectiveChanged(this, getPerspective(), CHANGE_VIEW_SHOW);
        }
        return compatibilityView.getView();
    }
    part = showPart(mode, part);
    CompatibilityView compatibilityView = (CompatibilityView) part.getObject();
    if (compatibilityView != null) {
        IWorkbenchPartReference ref = compatibilityView.getReference();
        legacyWindow.firePerspectiveChanged(this, getPerspective(), ref, CHANGE_VIEW_SHOW);
        legacyWindow.firePerspectiveChanged(this, getPerspective(), CHANGE_VIEW_SHOW);
    }
    return compatibilityView.getView();
}