Java Code Examples for org.eclipse.ui.IWorkbenchPage#getSelection()
The following examples show how to use
org.eclipse.ui.IWorkbenchPage#getSelection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefreshSpecHandler.java From tlaplus with MIT License | 6 votes |
public Object execute(final ExecutionEvent event) throws ExecutionException { final IWorkbenchPage activePage = UIHelper.getActivePage(); if (activePage != null) { final ISelection selection = activePage.getSelection(ToolboxExplorer.VIEW_ID); if (selection != null && selection instanceof IStructuredSelection && !((IStructuredSelection) selection).isEmpty()) { final Job job = new ToolboxJob("Refreshing spec...") { /* (non-Javadoc) * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) */ protected IStatus run(IProgressMonitor monitor) { final Iterator<Spec> selectionIterator = ((IStructuredSelection) selection).iterator(); while (selectionIterator.hasNext()) { ResourceHelper.refreshSpec(selectionIterator.next(), monitor); } return Status.OK_STATUS; } }; job.schedule(); } } return null; }
Example 2
Source File: AttributeViewPage.java From birt with Eclipse Public License 1.0 | 6 votes |
public void createControl( Composite parent ) { addActions( ); container = new Composite( parent, SWT.NONE ); GridLayout layout = new GridLayout( ); layout.marginWidth = layout.marginHeight = 0; container.setLayout( layout ); builder = new AttributesBuilder( ); IWorkbenchPage page = getSite( ).getPage( ); selection = page.getSelection( ); page.addSelectionListener( this ); if ( selection == null && UIUtil.getActiveReportEditor( ) != null ) { selection = (ISelection) UIUtil.getActiveReportEditor( ) .getAdapter( ISelection.class ); } SessionHandleAdapter.getInstance( ) .getMediator( model ) .addColleague( this ); handleSelectionChanged( selection ); }
Example 3
Source File: WorkbenchUtils.java From goclipse with Eclipse Public License 1.0 | 6 votes |
/** * Attempts to guess the most relevant resource for the current workbench state */ public static IResource getContextResource() { IWorkbenchPage page = getActivePage(); if (page == null) { return null; } final ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { final IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { final Object obj = ss.getFirstElement(); if (obj instanceof IResource) { return (IResource) obj; } } } IEditorPart editor = page.getActiveEditor(); if (editor == null) { return null; } IEditorInput editorInput = editor.getEditorInput(); return ResourceUtil.getResource(editorInput); }
Example 4
Source File: OpenSpecHandlerDelegate.java From tlaplus with MIT License | 5 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { /* * Try to get the spec from active navigator if any */ IWorkbenchPage activePage = UIHelper.getActivePage(); if (activePage != null) { ISelection selection = activePage.getSelection(ToolboxExplorer.VIEW_ID); if (selection != null && selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) { Object selected = ((IStructuredSelection) selection).getFirstElement(); if (selected instanceof Spec) { final Map<String, String> parameters = new HashMap<String, String>(); // fill the spec name for the handler parameters.put(OpenSpecHandler.PARAM_SPEC, ((Spec) selected).getName()); // delegate the call to the open spec handler UIHelper.runCommand(OpenSpecHandler.COMMAND_ID, parameters); } } } return null; }
Example 5
Source File: SelectElementTypeContributionItem.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override protected IContributionItem[] getContributionItems() { /* * Fill the selected trace types and verify if selection applies only to * either traces or experiments */ Set<String> selectedTraceTypes = new HashSet<>(); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); ISelection selection = page.getSelection(); boolean forTraces = false, forExperiments = false; if (selection instanceof StructuredSelection) { for (Object element : ((StructuredSelection) selection).toList()) { if (element instanceof TmfTraceElement) { TmfTraceElement trace = (TmfTraceElement) element; selectedTraceTypes.add(trace.getTraceType()); forTraces = true; } else if (element instanceof TmfExperimentElement) { TmfExperimentElement exp = (TmfExperimentElement) element; selectedTraceTypes.add(exp.getTraceType()); forExperiments = true; } } } if (forTraces && forExperiments) { /* This should never happen anyways */ throw new RuntimeException("You must select only experiments or only traces to set the element type"); //$NON-NLS-1$ } return getContributionItems(selectedTraceTypes, forExperiments); }
Example 6
Source File: JavaBrowsingPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void partVisible(IWorkbenchPartReference ref) { if (ref != null && ref.getId() == getSite().getId()){ fProcessSelectionEvents= true; IWorkbenchPage page= getSite().getWorkbenchWindow().getActivePage(); if (page != null) { ISelection selection= page.getSelection(); if (selection != null) selectionChanged(page.getActivePart(), selection); } } }
Example 7
Source File: RenameSpecHandler.java From tlaplus with MIT License | 4 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { /* * No parameter try to get it from active navigator if any */ final IWorkbenchPage activePage = UIHelper.getActivePage(); if (activePage != null) { final ISelection selection = activePage.getSelection(ToolboxExplorer.VIEW_ID); if (selection != null && selection instanceof IStructuredSelection) { // handler is set up to only allow single selection in // plugin.xml -> no need to handle multi selection final Spec spec = (Spec) ((IStructuredSelection) selection).getFirstElement(); // name proposal String specName = spec.getName() + "_Copy"; // dialog that prompts the user for the new spec name (no need // to join UI thread, this is the UI thread) final InputDialog dialog = new InputDialog(UIHelper.getShell(), "New specification name", "Please input the new name of the specification", specName, new SpecNameValidator()); dialog.setBlockOnOpen(true); if (dialog.open() == Window.OK) { final WorkspaceSpecManager specManager = Activator.getSpecManager(); // close open spec before it gets renamed reopenEditorAfterRename = false; if (specManager.isSpecLoaded(spec)) { UIHelper.runCommand(CloseSpecHandler.COMMAND_ID, new HashMap<String, String>()); reopenEditorAfterRename = true; } // use confirmed rename -> rename final Job j = new ToolboxJob("Renaming spec...") { protected IStatus run(final IProgressMonitor monitor) { // do the actual rename specManager.renameSpec(spec, dialog.getValue(), monitor); // reopen editor again (has to happen in UI thread) UIHelper.runUIAsync(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ public void run() { if (reopenEditorAfterRename) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(OpenSpecHandler.PARAM_SPEC, dialog.getValue()); UIHelper.runCommand(OpenSpecHandler.COMMAND_ID, parameters); } } }); return Status.OK_STATUS; } }; j.schedule(); } } } return null; }
Example 8
Source File: DeleteSpecHandler.java From tlaplus with MIT License | 4 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { /* * No parameter try to get it from active navigator if any */ final IWorkbenchPage activePage = UIHelper.getActivePage(); if (activePage != null) { final ISelection selection = activePage.getSelection(ToolboxExplorer.VIEW_ID); if ((selection != null) && (selection instanceof IStructuredSelection) && !((IStructuredSelection) selection).isEmpty()) { final Iterator<?> selectionIterator = ((IStructuredSelection) selection).iterator(); while (selectionIterator.hasNext()) { final Object next = selectionIterator.next(); if (!(next instanceof Spec)) { // The selection can contain models and groups too. continue; } final Spec spec = (Spec) next; // 3 Aug 2011: LL changed the dialog's message to make it clearer what the Delete command does. final boolean answer = MessageDialog.openQuestion(UIHelper.getShellProvider().getShell(), "Delete specification?", "Do you really want the Toolbox to forget the specification " + spec.getName() + " and delete all its models?"); if (answer) { // close the spec handler (in the ui thread) final WorkspaceSpecManager specManager = Activator.getSpecManager(); if (specManager.isSpecLoaded(spec)) { final CloseSpecHandler handler = new CloseSpecHandler(); final Boolean result = (Boolean)handler.execute(event); if ((result != null) && !result.booleanValue()) { // there was a dirty editor and the user cancelled out of the closing return null; } } final Job j = new ToolboxJob("Deleting spec...") { protected IStatus run(final IProgressMonitor monitor) { Activator.getSpecManager().removeSpec(spec, monitor, false); return Status.OK_STATUS; } }; j.schedule(); } } } } return null; }
Example 9
Source File: ForgetSpecHandler.java From tlaplus with MIT License | 4 votes |
public Object execute(ExecutionEvent event) throws ExecutionException { /* * No parameter try to get it from active navigator if any */ IWorkbenchPage activePage = UIHelper.getActivePage(); if (activePage != null) { ISelection selection = activePage.getSelection(ToolboxExplorer.VIEW_ID); if (selection != null && selection instanceof IStructuredSelection && !((IStructuredSelection) selection).isEmpty()) { Iterator<Object> selectionIterator = ((IStructuredSelection) selection).iterator(); while (selectionIterator.hasNext()) { Object next = selectionIterator.next(); if (!(next instanceof Spec)) { // The selection can contain models and groups too. continue; } final Spec spec = (Spec) next; boolean answer = MessageDialog.openQuestion(UIHelper.getShellProvider().getShell(), "Forget specification?", "Do you really want to remove specification " + spec.getName() + " from the Toolbox's list of specs?"); if (answer) { // close the spec handler (in the ui thread) final WorkspaceSpecManager specManager = Activator.getSpecManager(); if (specManager.isSpecLoaded(spec)) { new CloseSpecHandler().execute(event); } // use confirmed rename -> rename final Job j = new ToolboxJob("Deleting spec...") { protected IStatus run(final IProgressMonitor monitor) { Activator.getSpecManager().removeSpec(spec, monitor, true); return Status.OK_STATUS; } }; j.schedule(); } } } } return null; }
Example 10
Source File: DeleteHandler.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@SuppressWarnings("unchecked") @Override public Object execute(ExecutionEvent event) throws ExecutionException{ IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); ISelection selection = activePage.getSelection(); // remove selection first - otherwise selection will try to select removed item... IWorkbenchPart activePart = activePage.getActivePart(); if (activePart != null && activePart instanceof MedicationView) { MedicationView mediView = (MedicationView) activePart; mediView.resetSelection(); } if (selection != null && !selection.isEmpty()) { if (MessageDialog.openQuestion(HandlerUtil.getActiveShell(event), Messages.FixMediDisplay_DeleteUnrecoverable, Messages.FixMediDisplay_DeleteUnrecoverable)) { IStructuredSelection strucSelection = (IStructuredSelection) selection; Iterator<MedicationTableViewerItem> selectionList = strucSelection.iterator(); while (selectionList.hasNext()) { MedicationTableViewerItem item = selectionList.next(); IPrescription prescription = item.getPrescription(); AcquireLockUi.aquireAndRun(prescription, new ILockHandler() { @Override public void lockFailed(){ // do nothing } @Override public void lockAcquired(){ CoreModelServiceHolder.get().remove(prescription); ContextServiceHolder.get().postEvent(ElexisEventTopics.EVENT_UPDATE, prescription); } }); } } } return null; }