use of org.eclipse.ui.part.ISetSelectionTarget in project tdq-studio-se by Talend.
the class DuplicateAction method selectAndReveal.
/**
* DOC bZhou Comment method "selectAndReveal".
*
* Selects and reveals the newly added resource in all parts of the active workbench window's active page.
*
* @param newLabel
*
* @param duplicateObject
* @throws BusinessException
*/
private void selectAndReveal(String newLabel, Item duplicateItem) throws BusinessException {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
IWorkbenchPart activePart = page.getActivePart();
RepositoryNode recursiveFind = null;
recursiveFind = getSelctionNode(newLabel, duplicateItem.getProperty());
if (recursiveFind != null) {
if (recursiveFind instanceof AnalysisRepNode || recursiveFind instanceof AnalysisSubFolderRepNode || recursiveFind instanceof ReportRepNode || recursiveFind instanceof ReportSubFolderRepNode) {
CorePlugin.getDefault().refreshDQView(RepositoryNodeHelper.findNearestSystemFolderNode(recursiveFind));
} else {
CorePlugin.getDefault().refreshDQView(recursiveFind.getParent());
refreshHiveConnectionParent(recursiveFind);
}
// MOD qiongli TDQ-5391 Avoid 'recursiveFind' to casue NPE .
if (activePart instanceof ISetSelectionTarget) {
ISelection selection = new StructuredSelection(recursiveFind);
((ISetSelectionTarget) activePart).selectReveal(selection);
}
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project tdq-studio-se by Talend.
the class NewSQLEditorPage method selectAndReveal.
public static void selectAndReveal(IResource resource, IWorkbenchWindow window) {
// validate the input
if (window == null || resource == null)
return;
IWorkbenchPage page = window.getActivePage();
if (page == null)
return;
// get all the view and editor parts
List parts = new ArrayList();
IWorkbenchPartReference[] refs = page.getViewReferences();
for (int i = 0; i < refs.length; i++) {
IWorkbenchPart part = refs[i].getPart(false);
if (part != null)
parts.add(part);
}
refs = page.getEditorReferences();
for (int i = 0; i < refs.length; i++) {
if (refs[i].getPart(false) != null)
parts.add(refs[i].getPart(false));
}
final ISelection selection = new StructuredSelection(resource);
Iterator it = parts.iterator();
while (it.hasNext()) {
IWorkbenchPart part = (IWorkbenchPart) it.next();
// get the part's ISetSelectionTarget implementation
ISetSelectionTarget target = null;
if (part instanceof ISetSelectionTarget)
target = (ISetSelectionTarget) part;
else
target = (ISetSelectionTarget) part.getAdapter(ISetSelectionTarget.class);
if (target != null) {
// select and reveal resource
final ISetSelectionTarget finalTarget = target;
window.getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
finalTarget.selectReveal(selection);
}
});
}
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project iobserve-analysis by research-iobserve.
the class systemadaptationModelWizard 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) {
systemadaptationEditorPlugin.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(), systemadaptationEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
systemadaptationEditorPlugin.INSTANCE.log(exception);
return false;
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project iobserve-analysis by research-iobserve.
the class cloudprofileModelWizard 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) {
CloudProfileEditorPlugin.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(), CloudProfileEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
CloudProfileEditorPlugin.INSTANCE.log(exception);
return false;
}
}
use of org.eclipse.ui.part.ISetSelectionTarget in project Malai by arnobl.
the class InstrumentModelWizard 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) {
InstrumentEditorPlugin.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(), InstrumentEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
return false;
}
return true;
} catch (Exception exception) {
InstrumentEditorPlugin.INSTANCE.log(exception);
return false;
}
}
Aggregations