下面列出了org.eclipse.ui.part.ViewPart#org.eclipse.ui.PartInitException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void initVirtualPage() { // called by ERDiagram
final String diagramName = diagram.getDefaultDiagramName();
if (diagramName != null) {
try {
final int pageIndex = removePage(diagramName);
final ERVirtualDiagram vdiagram = diagram.getDiagramContents().getVirtualDiagramSet().getVdiagramByName(diagramName);
diagram.setCurrentVirtualDiagram(vdiagram);
final VirtualDiagramEditor vdiagramEditor =
new VirtualDiagramEditor(diagram, vdiagram, editPartFactory, zoomComboContributionItem, outlinePage);
addPage(getNewPageIndexIfLessThanZero(pageIndex), vdiagramEditor, getEditorInput());
setPageText(getNewPageIndexIfLessThanZero(pageIndex), Format.null2blank(vdiagram.getName()));
} catch (final PartInitException e) {
Activator.showExceptionDialog(e);
}
}
}
/**
* Most SVN workspace actions modify the workspace and thus should
* save dirty editors.
* @see org.tigris.subversion.subclipse.ui.actions.SVNAction#needsToSaveDirtyEditors()
*/
protected boolean needsToSaveDirtyEditors() {
IResource[] selectedResources = getSelectedResources();
if (selectedResources != null && selectedResources.length > 0) {
IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
for (IEditorReference editorReference : editorReferences) {
if (editorReference.isDirty()) {
try {
IEditorInput editorInput = editorReference.getEditorInput();
if (editorInput instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput)editorInput).getFile();
if (needsToSave(file, selectedResources)) {
return true;
}
}
} catch (PartInitException e) {}
}
}
}
return false;
}
protected void openOutlineView() throws PartInitException, InterruptedException {
outlineView = editor.getEditorSite().getPage().showView("org.eclipse.ui.views.ContentOutline");
executeAsyncDisplayJobs();
Object adapter = editor.getAdapter(IContentOutlinePage.class);
assertTrue(adapter instanceof OutlinePage);
outlinePage = new SyncableOutlinePage((OutlinePage) adapter);
outlinePage.resetSyncer();
try {
outlinePage.waitForUpdate(EXPECTED_TIMEOUT);
} catch (TimeoutException e) {
System.out.println("Expected timeout exceeded: " + EXPECTED_TIMEOUT);// timeout is OK here
}
treeViewer = outlinePage.getTreeViewer();
assertSelected(treeViewer);
assertExpanded(treeViewer);
assertTrue(treeViewer.getInput() instanceof IOutlineNode);
IOutlineNode rootNode = (IOutlineNode) treeViewer.getInput();
List<IOutlineNode> children = rootNode.getChildren();
assertEquals(1, children.size());
modelNode = children.get(0);
}
/** Opens given file in a editor with given ID within given workbench page. Returns opened editor on null. */
public static IEditorPart openFileEditor(final IFile file, final IWorkbenchPage page, String editorId) {
checkNotNull(file, "Provided file was null.");
checkNotNull(page, "Provided page was null.");
checkNotNull(editorId, "Provided editor ID was null.");
AtomicReference<IEditorPart> refFileEditor = new AtomicReference<>();
UIUtils.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
try {
refFileEditor.set(IDE.openEditor(page, file, editorId, true));
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
return refFileEditor.get();
}
@Override
public void run() {
if (inputFile == null) {
return;
}
IWorkbenchPartSite workbenchPartSite = derivedSourceView.getSite();
IWorkbenchPage workbenchPage = workbenchPartSite.getPage();
try {
IEditorPart editorPart = workbenchPage.openEditor(new FileEditorInput(inputFile),
COMPILATION_UNIT_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
if (selectedRegion != null) {
((ITextEditor) editorPart).selectAndReveal(selectedRegion.getOffset(), selectedRegion.getLength());
}
} catch (PartInitException partInitException) {
throw new WrappedRuntimeException(partInitException);
}
}
/**
* Called when an atomic test fails.
*
* @param failure
* describes the test that failed and the exception that was thrown
*/
@Override
public void testFailure(Failure failure) throws Exception {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
N4IDEXpectView view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
view.notifyFailedExecutionOf(failure);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
}
});
}
/**
* Called when an atomic test flags that it assumes a condition that is false
*
* describes the test that failed and the {@link AssumptionViolatedException} that was thrown
*/
@Override
public void testAssumptionFailure(Failure failure) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
N4IDEXpectView view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
view.notifyFailedExecutionOf(failure);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
}
});
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
Description desc = (Description) selection.getFirstElement();
if (desc.isTest() && view.testsExecutionStatus.hasFailed(desc)) {
Throwable failureException = view.testsExecutionStatus.getFailure(desc).getException();
if (failureException instanceof ComparisonFailure) {
ComparisonFailure cf = (ComparisonFailure) failureException;
// display comparison view
displayComparisonView(cf, desc);
}
}
return null;
}
@Deprecated
public IXtextDocument getXtextDocument(IResource resource) {
IXtextDocument result = xtextDocumentUtil.getXtextDocument(resource);
if(result == null) {
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IFile file = ResourceUtil.getFile(resource);
IEditorInput input = new FileEditorInput(file);
IEditorPart newEditor = page.openEditor(input, getEditorId());
return xtextDocumentUtil.getXtextDocument(newEditor);
} catch (PartInitException e) {
return null;
}
}
return result;
}
/**
* Opens the editor asynchronously.
*
* @param file
* the file
* @param editorId
* the editor id
* @param activate
* true to activate, false otherwise
*/
protected void openEditorAsync(final IFile file, final String editorId, final boolean activate) {
asyncExec(new VoidResult() {
@Override
public void run() {
try {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
final int matchFlags = IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT;
final IEditorInput input = new FileEditorInput(file);
IEditorPart editor = activePage.openEditor(input, editorId, activate, matchFlags);
editor.setFocus();
waitForEditorJobs(editor);
} catch (PartInitException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(e.getMessage(), e);
}
}
}
});
}
@Override
public void run ( final IAction action )
{
final MultiStatus status = new MultiStatus ( Activator.PLUGIN_ID, 0, this.message, null );
for ( final Item item : this.items )
{
try
{
processItem ( item );
}
catch ( final PartInitException e )
{
status.add ( e.getStatus () );
}
}
if ( !status.isOK () )
{
showError ( status );
}
}
protected void showMatch( Match match, int currentOffset
, int currentLength, boolean activate
) throws PartInitException
{
if (match instanceof ModulaSymbolMatch) {
try {
ModulaSymbolMatch em = (ModulaSymbolMatch)match;
IFile f = em.getFile();
IWorkbenchPage page = WorkbenchUtils.getActivePage();
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(f.getName());
IEditorPart ep = page.openEditor(new FileEditorInput(f), desc.getId());
ITextEditor te = (ITextEditor)ep;
Control ctr = (Control)te.getAdapter(Control.class);
ctr.setFocus();
te.selectAndReveal(em.getOffset(), em.getLength());
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public boolean performFinish() {
IFile file = mainPage.createNewFile();
if (file == null) {
return false;
}
selectAndReveal(file);
// Open editor on new file.
IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow();
try {
if (dw != null) {
IWorkbenchPage page = dw.getActivePage();
if (page != null) {
IDE.openEditor(page, file, true);
}
}
} catch (PartInitException e) {
openError(dw.getShell(), "Problems opening editor", e.getMessage(), e);
}
return true;
}
@Override
public void init ( final IViewSite site, final IMemento memento ) throws PartInitException
{
if ( memento != null )
{
this.connectionId = memento.getString ( CONNECTION_ID );
this.connectionUri = memento.getString ( CONNECTION_URI );
}
super.init ( site, memento );
try
{
// it is OK to fail at this stage
reInitializeConnection ( this.connectionId, this.connectionUri );
}
catch ( final Exception e )
{
logger.warn ( "init () - couldn't recreate connection", e ); //$NON-NLS-1$
// just reset all values
this.connectionId = null;
this.connectionUri = null;
this.connectionService = null;
this.connectionTracker = null;
}
}
@Test
public void testTMHighlightInGenericEditorEdit() throws IOException, PartInitException {
f = File.createTempFile("test" + System.currentTimeMillis(), ".ts");
FileOutputStream fileOutputStream = new FileOutputStream(f);
fileOutputStream.write("let a = '';".getBytes());
fileOutputStream.close();
f.deleteOnExit();
editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
f.toURI(), editorDescriptor.getId(), true);
StyledText text = (StyledText)editor.getAdapter(Control.class);
Assert.assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
return text.getStyleRanges().length > 1;
}
}.waitForCondition(text.getDisplay(), 3000));
int initialNumberOfRanges = text.getStyleRanges().length;
text.setText("let a = '';\nlet b = 10;\nlet c = true;");
Assert.assertTrue("More styles should have been added", new DisplayHelper() {
@Override protected boolean condition() {
return text.getStyleRanges().length > initialNumberOfRanges + 3;
}
}.waitForCondition(text.getDisplay(), 300000));
}
public LogDocument(LogFile file, String encoding) throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, PartInitException {
super();
if (file.getEncoding() == null) {
file.setEncoding(encoding);
}
this.file = file;
this.encoding = file.getEncoding();
this.charset = Charset.forName(file.getEncoding());
IPreferenceStore store = LogViewerPlugin.getDefault().getPreferenceStore();
store.addPropertyChangeListener(new PropertyChangeListener());
backlogLines = store.getInt(ILogViewerConstants.PREF_BACKLOG);
setTextStore(new GapTextStore(50, 300, 1f));
setLineTracker(new DefaultLineTracker());
completeInitialization();
reader = new BackgroundReader(file.getType(), file.getPath(), file.getNamePattern(), charset,this);
}
private void openFile(IFile file) {
IEditorRegistry registry = PlatformUI.getWorkbench()
.getEditorRegistry();
if (registry.isSystemExternalEditorAvailable(file.getName())) {
/**
* in case of opening the exported file from an other thread e.g. in
* case of listening to an IResourceChangeEvent
*/
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
page.openEditor(new FileEditorInput(file),
IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
} catch (PartInitException e) {
DotActivatorEx.logError(e);
}
}
});
}
}
public void run() {
Display.getDefault().syncExec(new Runnable() {
public void run() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
for (String viewId : list) {
try {
activePage.showView(viewId);
} catch (PartInitException e) {
LOG.log(Level.SEVERE, "Can't open view " + viewId, e);
}
}
}
});
}
private static LSPDocumentInfo infoFromOpenEditors() {
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
for (IWorkbenchPage page : window.getPages()) {
for (IEditorReference editor : page.getEditorReferences()) {
IEditorInput input;
try {
input = editor.getEditorInput();
} catch (PartInitException e) {
continue;
}
if (input.getName().endsWith(".rs") && editor.getEditor(false) instanceof ITextEditor) { //$NON-NLS-1$
IDocument document = (((ITextEditor) editor.getEditor(false)).getDocumentProvider())
.getDocument(input);
Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(document,
capabilities -> Boolean.TRUE.equals(capabilities.getReferencesProvider()));
if (!infos.isEmpty()) {
return infos.iterator().next();
}
}
}
}
}
return null;
}
public static IEditorPart openFile(final URI uri) {
if (uri == null) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found", "Trying to open a null file");
return null;
}
try {
if (uri.isPlatformResource()) { return FileOpener.openFileInWorkspace(uri); }
if (uri.isFile()) { return FileOpener.openFileInFileSystem(uri); }
} catch (final PartInitException e) {
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
"The file'" + uri.toString() + "' does not exist on disk.");
}
MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found",
"The file'" + uri.toString() + "' cannot be found.");
return null;
}
/**
* Opens visualize.html in the default browser
*
* @throws PartInitException
* @throws MalformedURLException
*/
private void display() throws PartInitException, MalformedURLException {
// set to use external browser due to internal browser bug
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=501978
final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
browser.openURL(Paths.get(target, FILE_TO_OPEN_IN_BROWSER).toUri().toURL());
}
public void run() {
if (myDiagram == null || myDiagram.eResource() == null) {
return;
}
IEditorInput editorInput = getEditorInput();
IWorkbenchPage page = myViewerSite.getPage();
try {
page.openEditor(editorInput, ID);
} catch (PartInitException e) {
e.printStackTrace();
}
}
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
if (!(input instanceof WelcomePageEditorInput)) {
Logger.logError("The editor input is not valid for the welcome page: " + input.getClass()); //$NON-NLS-1$
throw new PartInitException(Messages.WelcomePageEditorCreateError);
}
setSite(site);
setInput(input);
setPartName(Messages.WelcomePageEditorPartName);
CodewindUIPlugin.getUpdateHandler().addUpdateListener(this);
}
@Test
public void testAction_Project_Priority_Category_PatternType_Pattern_Marker() throws PartInitException {
runAction(PROJECT_PRIORITY_CATEGORY_PATTERN_TYPE_PATTERN_MARKER_ID);
assertExpectedGroupTypes(GroupType.Project, GroupType.Confidence, GroupType.Category, GroupType.PatternType,
GroupType.Pattern, GroupType.Marker);
}
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
setInput(input);
initInfo();
}
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
if (!isEnabled()) {
MessageDialog.openInformation(
new Shell(),
"Logfile Viewer",
"Wrong Selection");
return;
}
for (int i=0;i<resource.length;i++) {
if (resource[i] == null)
continue;
String full_path = resource[i].getClass().toString().replaceFirst("class ", "") + System.getProperty("file.separator") + resource[i].getName();
LogViewer view = null;
try {
view = (LogViewer) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("de.anbos.eclipse.logviewer.plugin.LogViewer");
} catch (PartInitException e) {
e.printStackTrace();
}
view.checkAndOpenFile(LogFileType.LOGFILE_ECLIPSE_CONSOLE, full_path, null, false);
}
}
@Override
protected void addPages() {
this.jsonEditor = new StructuredTextEditor();
jsonEditor.setEditorPart(this);
try {
// Add pages like overview, etc
doAddPages();
// Add source page
jsonEditorIndex = addPage(jsonEditor, getEditorInput());
setPageText(jsonEditorIndex, "Source");
} catch (PartInitException e) {
e.printStackTrace();
}
}
/**
* Jumps to the xBookmark with the given number, if there is one.
* When necessary an editor will be opened.
* If there are multiple marks with the same number then the previous/next
* one from the current selection will be jumped to (when exactly on
* a xBookmark that mark isn't considered as a jump target).
* If after any xBookmark with that number, the search toggles around
* to the first one and vice versa.
*
* @param markerNumber the number of the mark to jump to
* @param backward true, if the previous mark should be jumped to instead
* of the next one
*/
protected void gotoBookmark (int markerNumber) {
IResource scope = XBookmarksUtils.getWorkspaceScope();
if (scope == null) {
return;
}
IMarker marker = XBookmarksUtils.fetchBookmark(scope, markerNumber);
if (marker == null) {
statusLine.showErrMessage(MessageFormat.format(Messages.BookmarkAction_BM_NotFound, markerNumber));
return;
}
IResource resource = marker.getResource();
if (! (resource instanceof IFile)) {
statusLine.showErrMessage(MessageFormat.format(Messages.BookmarkAction_BM_HbzWhere, markerNumber));
return;
}
IWorkbenchPage page = WorkbenchUtils.getActivePage();
if (page == null) {
statusLine.showErrMessage(MessageFormat.format(Messages.BookmarkAction_CantGoBM_NoActivePage, markerNumber));
return;
}
// now try to jump and open the right editor, if necessary
try {
IDE.openEditor(page, marker, OpenStrategy.activateOnOpen());
statusLine.showMessage(
MessageFormat.format(Messages.BookmarkAction_OnBM, markerNumber),
XBookmarksPlugin.IMGID_GOTO);
}
catch (PartInitException e) {
XBookmarksUtils.logError(e);
statusLine.showErrMessage(MessageFormat.format(Messages.BookmarkAction_CantGoBM, markerNumber));
}
}
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
setSite(site);
setInput(input);
initFromInput(input);
}
public void run() {
IWorkbenchPage page = TexlipsePlugin.getCurrentWorkbenchPage();
if (page == null) {
return;
}
try {
IDE.openEditor(page, marker, false);
} catch (PartInitException e) {
}
}