use of org.eclipse.ui.PartInitException in project xtext-eclipse by eclipse.
the class MarkerResolutionGenerator method getEditor.
// handled by org.eclipse.xtext.ui.editor.model.edit.IssueModificationContext.getXtextDocument(URI)
@Deprecated
public XtextEditor getEditor(IResource resource) {
XtextEditor result = findEditor(resource);
if (result == null) {
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IFile file = ResourceUtil.getFile(resource);
IEditorInput input = new FileEditorInput(file);
IEditorPart editor = page.openEditor(input, getEditorId());
if (editor instanceof XtextEditor) {
result = (XtextEditor) editor;
} else if (editor != null) {
result = (XtextEditor) editor.getAdapter(XtextEditor.class);
}
} catch (PartInitException e) {
return null;
}
}
return result;
}
use of org.eclipse.ui.PartInitException in project xtext-eclipse by eclipse.
the class JvmImplementationOpener method openImplementations.
/**
* Main parts of the logic is taken from {@link org.eclipse.jdt.internal.ui.javaeditor.JavaElementImplementationHyperlink}
*
* @param element - Element to show implementations for
* @param textviewer - Viewer to show hierarchy view on
* @param region - Region where to show hierarchy view
*/
public void openImplementations(final IJavaElement element, ITextViewer textviewer, IRegion region) {
if (element instanceof IMethod) {
ITypeRoot typeRoot = ((IMethod) element).getTypeRoot();
CompilationUnit ast = SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_YES, null);
if (ast == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
try {
ISourceRange nameRange = ((IMethod) element).getNameRange();
ASTNode node = NodeFinder.perform(ast, nameRange);
ITypeBinding parentTypeBinding = null;
if (node instanceof SimpleName) {
ASTNode parent = node.getParent();
if (parent instanceof MethodInvocation) {
Expression expression = ((MethodInvocation) parent).getExpression();
if (expression == null) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
} else {
parentTypeBinding = expression.resolveTypeBinding();
}
} else if (parent instanceof SuperMethodInvocation) {
// Directly go to the super method definition
openEditor(element);
return;
} else if (parent instanceof MethodDeclaration) {
parentTypeBinding = Bindings.getBindingOfParentType(node);
}
}
final IType type = parentTypeBinding != null ? (IType) parentTypeBinding.getJavaElement() : null;
if (type == null) {
openQuickHierarchy(textviewer, element, region);
return;
}
final String earlyExitIndicator = "EarlyExitIndicator";
final ArrayList<IJavaElement> links = Lists.newArrayList();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
try {
String methodLabel = JavaElementLabels.getElementLabel(element, JavaElementLabels.DEFAULT_QUALIFIED);
monitor.beginTask(Messages.format("Searching for implementors of ''{0}''", methodLabel), 100);
SearchRequestor requestor = new SearchRequestor() {
@Override
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
IJavaElement element = (IJavaElement) match.getElement();
if (element instanceof IMethod && !JdtFlags.isAbstract((IMethod) element)) {
links.add(element);
if (links.size() > 1) {
throw new OperationCanceledException(earlyExitIndicator);
}
}
}
}
};
int limitTo = IJavaSearchConstants.DECLARATIONS | IJavaSearchConstants.IGNORE_DECLARING_TYPE | IJavaSearchConstants.IGNORE_RETURN_TYPE;
SearchPattern pattern = SearchPattern.createPattern(element, limitTo);
Assert.isNotNull(pattern);
SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
SearchEngine engine = new SearchEngine();
engine.search(pattern, participants, SearchEngine.createHierarchyScope(type), requestor, SubMonitor.convert(monitor, 100));
if (monitor.isCanceled()) {
throw new InterruptedException();
}
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, Messages.format("An error occurred while searching for implementations of method ''{0}''. See error log for details.", element.getElementName()), e.getCause());
JavaPlugin.log(status);
ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Open Implementation", "Problems finding implementations.", status);
} catch (InterruptedException e) {
if (e.getMessage() != earlyExitIndicator) {
return;
}
}
if (links.size() == 1) {
openEditor(links.get(0));
} else {
openQuickHierarchy(textviewer, element, region);
}
} catch (JavaModelException e) {
log.error("An error occurred while searching for implementations", e.getCause());
} catch (PartInitException e) {
log.error("An error occurred while searching for implementations", e.getCause());
}
}
}
use of org.eclipse.ui.PartInitException in project archi by archimatetool.
the class ViewManager method showViewPart.
/**
* Attempt to show the given View if hidden, or bring it to focus
* @param viewID The ID of the View to show
* @return The IViewPart or null
*/
public static IViewPart showViewPart(String viewID, boolean activate) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart viewPart = null;
try {
viewPart = page.showView(viewID, null, activate ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_VISIBLE);
} catch (PartInitException ex) {
ex.printStackTrace();
}
return viewPart;
}
use of org.eclipse.ui.PartInitException in project cubrid-manager by CUBRID.
the class MonitorStatisticEditor method openDetailView.
public void openDetailView(StatisticChartItem statisticChartItem, List<StatisticData> statisticDataList) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
IWorkbenchPage page = window.getActivePage();
if (page == null) {
return;
}
StringBuilder secondaryIdSb = new StringBuilder(MonitorStatisticDetailViewPart.ID);
secondaryIdSb.append("@").append(this.pageNode.getId());
IViewReference viewReference = page.findViewReference(MonitorStatisticDetailViewPart.ID, secondaryIdSb.toString());
if (viewReference == null) {
try {
MonitorStatisticDetailViewPart viewPart = (MonitorStatisticDetailViewPart) page.showView(MonitorStatisticDetailViewPart.ID, secondaryIdSb.toString(), IWorkbenchPage.VIEW_ACTIVATE);
viewPart.setMultiHost(isMultiHost);
viewPart.init(this.pageNode, this);
viewPart.setStatisticChartItem(statisticChartItem);
viewPart.setStatisticDataList(statisticDataList);
viewPart.reloadChart();
} catch (PartInitException ex) {
viewReference = null;
}
} else {
MonitorStatisticDetailViewPart viewPart = (MonitorStatisticDetailViewPart) viewReference.getView(false);
window.getActivePage().bringToTop(viewPart);
viewPart.setStatisticChartItem(statisticChartItem);
viewPart.setStatisticDataList(statisticDataList);
viewPart.reloadChart();
}
}
use of org.eclipse.ui.PartInitException in project cubrid-manager by CUBRID.
the class MonitorReplicationPerfAction method run.
/**
* monitor replication performance
*/
public void run() {
Object[] obj = this.getSelectedObj();
if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
return;
}
ICubridNode cubridNode = (ICubridNode) obj[0];
try {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, ReplicationMonitorViewPart.ID);
if (viewPart == null) {
IWorkbenchPage page = window.getActivePage();
String secondId = cubridNode.getServer().getLabel() + "_" + cubridNode.getLabel();
viewPart = page.showView(ReplicationMonitorViewPart.ID, secondId, IWorkbenchPage.VIEW_CREATE);
window.getActivePage().bringToTop(viewPart);
} else {
window.getActivePage().bringToTop(viewPart);
}
if (viewPart != null) {
LayoutManager.getInstance().getTitleLineContrItem().changeTitleForViewOrEditPart(cubridNode, viewPart);
LayoutManager.getInstance().getStatusLineContrItem().changeStuatusLineForViewOrEditPart(cubridNode, viewPart);
}
} catch (PartInitException e) {
LOGGER.error(e.getMessage(), e);
}
}
Aggregations