use of org.eclipse.ui.IViewReference in project linuxtools by eclipse.
the class PrepareChangelogKeyHandler method execute.
@Override
public Object execute(ExecutionEvent event) {
IStructuredSelection tempResult = null;
// try getting currently selected project
IWorkbenchPage ref = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part instanceof IEditorPart) {
// If we are in an editor, check if the file being edited is an IResource
// that belongs to a project in the workspace
IEditorPart editorPart = (IEditorPart) part;
IEditorInput input = editorPart.getEditorInput();
IResource r = input.getAdapter(IResource.class);
if (r != null) {
// We have an IResource to work with, so create a selection we can use
// in PrepareChangeLogAction
tempResult = new StructuredSelection(r);
}
} else {
// Otherwise, our view is not an editor, see if we have an IResource or something
// that will lead us to an IResource
ISelection selected = ref.getSelection();
if (selected instanceof IStructuredSelection) {
IResource r = null;
IStructuredSelection iss = (IStructuredSelection) selected;
Object o = ((IStructuredSelection) selected).getFirstElement();
if (o instanceof ISynchronizeModelElement) {
r = ((ISynchronizeModelElement) o).getResource();
} else if (o instanceof IAdaptable) {
r = ((IAdaptable) o).getAdapter(IResource.class);
}
if (r != null)
tempResult = iss;
}
}
if (tempResult == null) {
// choice to fall back on.
for (IViewReference view : ref.getViewReferences()) {
if (view.getId().equals("org.eclipse.team.sync.views.SynchronizeView")) {
// $NON-NLS-1$
IViewPart v = view.getView(false);
ISelection s = null;
ISelectionProvider sp = v.getViewSite().getSelectionProvider();
if (sp != null) {
s = sp.getSelection();
}
if (s instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) s;
Object element = ss.getFirstElement();
IResource r = null;
if (element instanceof ISynchronizeModelElement) {
r = ((ISynchronizeModelElement) element).getResource();
} else if (element instanceof IAdaptable) {
r = ((IAdaptable) element).getAdapter(IResource.class);
}
if (r != null) {
tempResult = ss;
}
}
}
}
}
// If we can't find the project directly, let the user know.
if (tempResult == null) {
// $NON-NLS-1$,
MessageDialog.openInformation(// $NON-NLS-1$,
getActiveWorkbenchShell(), // $NON-NLS-1$,
Messages.getString("ChangeLog.PrepareChangeLog"), // $NON-NLS-1$
Messages.getString("PrepareChangeLog.InfoNoProjectFound"));
return null;
}
final IStructuredSelection result = tempResult;
IAction exampleAction = new PrepareChangeLogAction() {
@Override
public void run() {
setSelection(result);
doRun();
}
};
exampleAction.run();
return null;
}
use of org.eclipse.ui.IViewReference in project linuxtools by eclipse.
the class AbstractStyledTextViewTest method testPerfView.
@Override
protected void testPerfView() {
SWTWorkbenchBot bot = new SWTWorkbenchBot();
Matcher<IViewReference> withPartName = withPartName(getViewId());
SWTBotView view = bot.view(withPartName);
assertNotNull(view);
view.setFocus();
SWTBotStyledText text = bot.styledText();
assertNotNull(text);
assertEquals(getExpectedText(), text.getText());
}
use of org.eclipse.ui.IViewReference in project knime-core by knime.
the class IntroPage method newWorkflow.
private void newWorkflow() {
ExplorerView explorerView = null;
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
for (IWorkbenchPage page : window.getPages()) {
for (IViewReference ref : page.getViewReferences()) {
if (ExplorerView.ID.equals(ref.getId())) {
explorerView = (ExplorerView) ref.getPart(true);
break;
}
}
}
}
Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
NewWorkflowWizard newWiz = new NewWorkflowWizard();
newWiz.init(PlatformUI.getWorkbench(), null);
WizardDialog dialog = new WizardDialog(shell, newWiz);
dialog.create();
dialog.getShell().setText("Create new workflow");
dialog.getShell().setSize(Math.max(470, dialog.getShell().getSize().x), 350);
int ok = dialog.open();
if ((ok == Window.OK) && (explorerView != null)) {
// update the tree
IWizardPage currentPage = dialog.getCurrentPage();
if (currentPage instanceof NewWorkflowWizardPage) {
NewWorkflowWizardPage nwwp = (NewWorkflowWizardPage) currentPage;
AbstractExplorerFileStore file = nwwp.getNewFile();
Object p = ContentDelegator.getTreeObjectFor(file.getParent());
explorerView.setNextSelection(file);
explorerView.getViewer().refresh(p);
}
}
}
use of org.eclipse.ui.IViewReference in project knime-core by knime.
the class RevealMetaNodeTemplateAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
List<NodeID> candidateList = new ArrayList<NodeID>();
List<AbstractExplorerFileStore> templates = new ArrayList<AbstractExplorerFileStore>();
for (NodeContainerEditPart p : nodes) {
Object model = p.getModel();
if (model instanceof WorkflowManagerUI) {
NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
try {
WorkflowManager wm = Wrapper.unwrapWFM((UI) model);
MetaNodeTemplateInformation i = wm.getTemplateInformation();
if (Role.Link.equals(i.getRole())) {
candidateList.add(wm.getID());
AbstractExplorerFileStore template = ExplorerFileSystem.INSTANCE.getStore(i.getSourceURI());
if (template != null) {
templates.add(template);
}
}
} finally {
NodeContext.removeLastContext();
}
}
}
List<Object> treeObjects = ContentDelegator.getTreeObjectList(templates);
if (treeObjects != null && treeObjects.size() > 0) {
IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
for (IViewReference view : views) {
if (ExplorerView.ID.equals(view.getId())) {
ExplorerView explorerView = (ExplorerView) view.getView(true);
explorerView.getViewer().setSelection(new StructuredSelection(treeObjects), true);
}
}
}
}
use of org.eclipse.ui.IViewReference in project knime-core by knime.
the class ExampleWorkflowExtractor method run.
/**
* {@inheritDoc}
*/
@Override
public void run() {
Location loc = Platform.getInstallLocation();
if (loc == null) {
NodeLogger.getLogger(getClass()).error("Cannot detect KNIME installation directory");
return;
} else if (!loc.getURL().getProtocol().equals("file")) {
NodeLogger.getLogger(getClass()).error("KNIME installation directory is not local");
return;
}
String path = loc.getURL().getPath();
if (Platform.OS_WIN32.equals(Platform.getOS()) && path.matches("^/[a-zA-Z]:/.*")) {
// Windows path with drive letter => remove first slash
path = path.substring(1);
}
Path initialWorkspace = Paths.get(path, "knime-workspace.zip");
if (!Files.exists(initialWorkspace)) {
NodeLogger.getLogger(getClass()).warn(initialWorkspace.toAbsolutePath() + " not found in installation directory, not creating inital workspace");
return;
}
File workspace = KNIMEPath.getWorkspaceDirPath();
try (ZipInputStream is = new ZipInputStream(Files.newInputStream(initialWorkspace))) {
FileUtil.unzip(is, workspace, 0);
} catch (IOException ex) {
NodeLogger.getLogger(getClass()).error("Could not extract example workflows: " + ex.getMessage(), ex);
}
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
for (IWorkbenchPage page : window.getPages()) {
for (IViewReference ref : page.getViewReferences()) {
if (ExplorerView.ID.equals(ref.getId())) {
final ExplorerView explorer = (ExplorerView) ref.getView(true);
final TreeViewer viewer = explorer.getViewer();
if (viewer.getControl() != null && viewer.getControl().getDisplay() != null) {
viewer.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
viewer.refresh();
viewer.expandAll();
}
});
}
}
}
}
}
}
Aggregations