use of org.eclipse.ui.part.ISetSelectionTarget in project Malai by arnobl.
the class ActionModelWizard method performFinish.
/**
* Do the work after everything is specified.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean performFinish() {
try {
// Remember the file.
//
final IFile modelFile = getModelFile();
// Do the work within an operation.
//
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor progressMonitor) {
try {
// Create a resource set
//
ResourceSet resourceSet = new ResourceSetImpl();
// Get the URI of the model file.
//
URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
// Create a resource for this file.
//
Resource resource = resourceSet.createResource(fileURI);
// Add the initial model object to the contents.
//
EObject rootObject = createInitialModel();
if (rootObject != null) {
resource.getContents().add(rootObject);
}
// Save the contents of the resource to the file system.
//
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
resource.save(options);
} catch (Exception exception) {
ActionEditorPlugin.INSTANCE.log(exception);
} finally {
progressMonitor.done();
}
}
};
getContainer().run(false, false, operation);
// Select the new file resource in the current view.
//
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
final IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof ISetSelectionTarget) {
final ISelection targetSelection = new StructuredSelection(modelFile);
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) activePart).selectReveal(targetSelection);
}
});
}
//
try {
page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
} catch (PartInitException exception) {
MessageDialog.openError(workbenchWindow.getShell(), ActionEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
ActionEditorPlugin.INSTANCE.log(exception);
return false;
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project Malai by arnobl.
the class EventModelWizard method performFinish.
/**
* Do the work after everything is specified.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean performFinish() {
try {
// Remember the file.
//
final IFile modelFile = getModelFile();
// Do the work within an operation.
//
WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor progressMonitor) {
try {
// Create a resource set
//
ResourceSet resourceSet = new ResourceSetImpl();
// Get the URI of the model file.
//
URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
// Create a resource for this file.
//
Resource resource = resourceSet.createResource(fileURI);
// Add the initial model object to the contents.
//
EObject rootObject = createInitialModel();
if (rootObject != null) {
resource.getContents().add(rootObject);
}
// Save the contents of the resource to the file system.
//
Map<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
resource.save(options);
} catch (Exception exception) {
MalaiEventEditorPlugin.INSTANCE.log(exception);
} finally {
progressMonitor.done();
}
}
};
getContainer().run(false, false, operation);
// Select the new file resource in the current view.
//
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
final IWorkbenchPart activePart = page.getActivePart();
if (activePart instanceof ISetSelectionTarget) {
final ISelection targetSelection = new StructuredSelection(modelFile);
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) activePart).selectReveal(targetSelection);
}
});
}
//
try {
page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
} catch (PartInitException exception) {
MessageDialog.openError(workbenchWindow.getShell(), MalaiEventEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
MalaiEventEditorPlugin.INSTANCE.log(exception);
return false;
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project erlide_eclipse by erlang.
the class NewErlangProjectWizard method selectAndReveal.
/**
* Attempts to select and reveal the specified resource in all parts within the
* supplied workbench window's active page.
* <p>
* Checks all parts in the active page to see if they implement
* <code>ISetSelectionTarget</code>, either directly or as an adapter. If so, tells
* the part to select and reveal the specified resource.
* </p>
*
* @param resource
* the resource to be selected and revealed
* @param window
* the workbench window to select and reveal the resource
*
* @see ISetSelectionTarget
*/
public static void selectAndReveal(final IResource resource, final IWorkbenchWindow window) {
// validate the input
if (window == null || resource == null) {
return;
}
final IWorkbenchPage page = window.getActivePage();
if (page == null) {
return;
}
// get all the view and editor parts
final List<IWorkbenchPart> parts = Lists.newArrayList();
IWorkbenchPartReference[] refs = page.getViewReferences();
for (IWorkbenchPartReference ref1 : refs) {
final IWorkbenchPart part = ref1.getPart(false);
if (part != null) {
parts.add(part);
}
}
refs = page.getEditorReferences();
for (IWorkbenchPartReference ref : refs) {
if (ref.getPart(false) != null) {
parts.add(ref.getPart(false));
}
}
final ISelection selection = new StructuredSelection(resource);
for (IWorkbenchPart part : parts) {
// get the part's ISetSelectionTarget implementation
ISetSelectionTarget target = null;
if (part instanceof ISetSelectionTarget) {
target = (ISetSelectionTarget) part;
} else {
target = part.getAdapter(ISetSelectionTarget.class);
}
if (target != null) {
// select and reveal resource
final ISetSelectionTarget finalTarget = target;
window.getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
finalTarget.selectReveal(selection);
}
});
}
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project webtools.sourceediting by eclipse.
the class ShowInNavigatorAction method run.
public void run(IAction action) {
IJavaScriptElement[] elements = JsElementActionProxy.getJsElementsFromSelection(getCurrentSelection());
if (elements == null || elements.length == 0) {
return;
}
IResource resource = null;
if (elements[0].isVirtual()) {
resource = getHostResource(elements[0]);
} else {
resource = elements[0].getResource();
}
if (resource == null) {
return;
}
try {
IWorkbenchPage page = targetWorkbenchPart.getSite().getPage();
IViewPart view = page.showView(IPageLayout.ID_RES_NAV);
if (view instanceof ISetSelectionTarget) {
ISelection selection = new StructuredSelection(resource);
((ISetSelectionTarget) view).selectReveal(selection);
}
} catch (PartInitException e) {
// $NON-NLS-1$ //$NON-NLS-2$
ExceptionHandler.handle(e, targetWorkbenchPart.getSite().getShell(), Messages.getString("ShowInNavigatorAction.0"), Messages.getString("ShowInNavigatorAction.1") + e);
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project webtools.sourceediting by eclipse.
the class NewXSDWizard method revealSelection.
private void revealSelection(final ISelection selection) {
if (selection != null) {
IWorkbench workbench2;
if (workbench == null) {
workbench2 = XSDEditorPlugin.getPlugin().getWorkbench();
} else {
workbench2 = workbench;
}
final IWorkbenchWindow workbenchWindow = workbench2.getActiveWorkbenchWindow();
final IWorkbenchPart focusPart = workbenchWindow.getActivePage().getActivePart();
if (focusPart instanceof ISetSelectionTarget) {
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
((ISetSelectionTarget) focusPart).selectReveal(selection);
}
});
}
}
}
Aggregations