use of org.eclipse.ui.WorkbenchException in project eclipse-cs by checkstyle.
the class CheckFileOnOpenPartListener method getMementoE4.
private IMemento getMementoE4(IEditorReference e) {
try {
// can't use this as long as were still supporting E3
// org.eclipse.e4.ui.model.application.MApplicationElement model =
// e.getModel();
// Map<String, String> state = model.getPersistedState()
Method getModelMethod = e.getClass().getMethod("getModel", new Class<?>[0]);
getModelMethod.setAccessible(true);
Object model = getModelMethod.invoke(e, (Object[]) null);
Method getPersistedStateMethod = model.getClass().getMethod("getPersistedState", new Class<?>[0]);
getPersistedStateMethod.setAccessible(true);
@SuppressWarnings("unchecked") Map<String, String> state = (Map<String, String>) getPersistedStateMethod.invoke(model, (Object[]) null);
String memento = state.get("memento");
if (memento != null) {
try {
return XMLMemento.createReadRoot(new StringReader(memento));
} catch (WorkbenchException e1) {
CheckstyleLog.log(e1);
}
}
} catch (NoSuchMethodException e1) {
CheckstyleLog.log(e1);
} catch (SecurityException e1) {
CheckstyleLog.log(e1);
} catch (IllegalAccessException e1) {
CheckstyleLog.log(e1);
} catch (InvocationTargetException e1) {
CheckstyleLog.log(e1);
}
return null;
}
use of org.eclipse.ui.WorkbenchException in project bndtools by bndtools.
the class ImportBndWorkspaceWizard method performFinish.
@Override
public boolean performFinish() {
final ImportSettings importSettings = new ImportSettings(mainPage.getSelectedFolder(), mainPage.isDeleteSettings(), mainPage.isInferExecutionEnvironment());
// create the new project operation
final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException {
try {
importProjects(importSettings, monitor);
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error during import of Bnd workspace!", e));
}
}
};
Job importJob = new Job("Import Bnd Workspace") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
op.run(monitor);
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t instanceof CoreException && ((CoreException) t).getStatus().getException() != null) {
// unwrap the cause of the CoreException
t = ((CoreException) t).getStatus().getException();
}
return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Could not finish import job for Bnd Workspace!", t);
} catch (InterruptedException e) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
importJob.schedule();
try {
// Prompt to switch to the BndTools perspective
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
if (!"bndtools.perspective".equals(currentPerspective.getId())) {
if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
this.workbench.showPerspective("bndtools.perspective", window);
}
}
} catch (WorkbenchException e) {
error("Unable to switch to BndTools perspective", e);
}
return true;
}
use of org.eclipse.ui.WorkbenchException in project tesb-studio-se by Talend.
the class CreateESBAction method selectRootObject.
private void selectRootObject(Properties params) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (null == workbenchWindow) {
return;
}
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (null == workbenchPage) {
return;
}
IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
// show Integration perspective
try {
workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
workbenchPage = workbenchWindow.getActivePage();
} catch (WorkbenchException e) {
ExceptionHandler.process(e);
return;
}
}
IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
if (view != null) {
Object type = params.get("type");
if (ESBRepositoryNodeType.SERVICES.name().equals(type)) {
RepositoryNode servicesNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(ESBRepositoryNodeType.SERVICES);
if (servicesNode != null) {
setWorkbenchPart(view);
final StructuredViewer viewer = view.getViewer();
if (viewer instanceof TreeViewer) {
((TreeViewer) viewer).expandToLevel(servicesNode, 1);
}
viewer.setSelection(new StructuredSelection(servicesNode));
}
}
}
}
use of org.eclipse.ui.WorkbenchException in project tesb-studio-se by Talend.
the class OpenWSDLEditorAction method run.
public void run(IIntroSite site, Properties params) {
PlatformUI.getWorkbench().getIntroManager().closeIntro(PlatformUI.getWorkbench().getIntroManager().getIntro());
IPerspectiveDescriptor currentPerspective = site.getPage().getPerspective();
if (!PERSPECTIVE_ID.equals(currentPerspective.getId())) {
// show required perspective
IWorkbenchWindow workbenchWindow = site.getWorkbenchWindow();
try {
workbenchWindow.getWorkbench().showPerspective(PERSPECTIVE_ID, workbenchWindow);
} catch (WorkbenchException e) {
ExceptionHandler.process(e);
return;
}
}
// find repository node
repositoryNode = (RepositoryNode) RepositorySeekerManager.getInstance().searchRepoViewNode(params.getProperty("nodeId"), false);
if (null != repositoryNode) {
// expand/select node item
RepositoryManagerHelper.getRepositoryView().getViewer().setSelection(new StructuredSelection(repositoryNode));
init(repositoryNode);
doRun();
}
}
use of org.eclipse.ui.WorkbenchException in project tesb-studio-se by Talend.
the class OpenTalendJobRefAction method run.
/* Will send a "open" request to the selected nodePart, so it will try to open the reference job.
* If the "open" command success, then will try to switch the perspective to Integration.
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
// diable switch perspective suggestion dialog. just for defense.
String notAskAutoSwitchToDIKey = "notAskAutoSwitchToDI";
boolean oldValueNotSwitchToDiKey = PlatformUI.getPreferenceStore().getBoolean(notAskAutoSwitchToDIKey);
PlatformUI.getPreferenceStore().setValue(notAskAutoSwitchToDIKey, true);
// need to be restore at the end .
// open in editor, type and count already checked in calculateEnabled()
List<?> selectedObjects = getSelectedObjects();
Object select = selectedObjects.get(0);
NodePart nodePart = (NodePart) select;
nodePart.performRequest(new org.eclipse.gef.Request(REQUEST_TYPE_OPEN_NODE_PART));
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage == null) {
return;
}
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor == null || activeEditor.getEditorSite() == null) {
return;
}
Node node = (Node) nodePart.getModel();
String selectedJobName = (String) node.getElementParameter(NODE_PARAM_SELECTED_JOB_NAME).getValue();
String openJobName = activeEditor.getEditorInput().getName();
if (!selectedJobName.equals(openJobName)) {
return;
}
// open/switch editor success and then try to switch perspective.
try {
// if current perspective is ORG_TALEND_RCP_INTEGRATION_PERSPECTIVE, will do nothing in under layer.
PlatformUI.getWorkbench().showPerspective(ORG_TALEND_RCP_INTEGRATION_PERSPECTIVE, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
e.printStackTrace();
} finally {
// Restore config of switch perspective suggestion dialog. just for defense.
PlatformUI.getPreferenceStore().setValue(notAskAutoSwitchToDIKey, oldValueNotSwitchToDiKey);
}
}
Aggregations