List of usage examples for org.eclipse.jface.util OpenStrategy activateOnOpen
public static boolean activateOnOpen()
From source file:ca.uvic.cs.tagsea.actions.GoToTagAction.java
License:Open Source License
/** * Grabs the currently selected waypoint from the viewer and navigates to * that waypoint's marker position in the editor. */// w ww . ja v a 2 s .c o m public void run() { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { Object obj = selection.getFirstElement(); IMarker marker = null; if (obj instanceof Waypoint) { // Waypoints TableViewer marker = ((Waypoint) obj).getMarker(); } if ((marker != null) && marker.exists()) { IResource resource = marker.getResource(); if (marker.exists() && resource instanceof IFile) { try { IDE.openEditor(page, marker, OpenStrategy.activateOnOpen()); Monitoring.getDefault().fireEvent(new TagSEANavigationEvent((Waypoint) obj)); } catch (PartInitException e) { TagSEAPlugin.log("Couldn't open editor to show the tag", e); } } } } }
From source file:ca.uvic.cs.tagsea.ui.views.RoutesComposite.java
License:Open Source License
public void goToWaypoint(int direction) { Waypoint wp = null;/*w w w . java2s . c o m*/ TreeItem routeItem = null; int index = -1; int waypointsInRoute; //determine the index of previous/next waypoints in the route TreeItem[] selections = routesTreeViewer.getTree().getSelection(); if (selections.length > 0) { TreeItem selection = selections[0]; if (selection.getData() instanceof Route) { routeItem = selection; waypointsInRoute = routeItem.getItemCount(); if (waypointsInRoute > 0) { if (direction == -1) { index = waypointsInRoute - 1; } else { index = 0; } } } else if (selection.getData() instanceof Waypoint) { routeItem = selection.getParentItem(); index = routeItem.indexOf(selection); waypointsInRoute = routeItem.getItemCount(); if (direction == -1) { index = (index + waypointsInRoute - 1) % waypointsInRoute; } else { index = (index + 1) % waypointsInRoute; } } } if (index != -1) { //get the waypoint in the route TreeItem wpItem = routeItem.getItem(index); wp = (Waypoint) wpItem.getData(); //go to the tag in resource RoutesView routesView = TagSEAPlugin.getDefault().getRoutesView(); IMarker marker = wp.getMarker(); if ((marker != null) && marker.exists()) { IResource resource = marker.getResource(); if (marker.exists() && resource instanceof IFile) { try { IDE.openEditor(routesView.getSite().getPage(), marker, OpenStrategy.activateOnOpen()); } catch (PartInitException e) { TagSEAPlugin.log("Couldn't open editor to show the tag", e); } } } //highlight the waypoint in routeTreeViewer //routesTreeViewer.setSelection(new StructuredSelection(wpItem.getData()), true); routesTreeViewer.getTree().setSelection(wpItem); routesTreeViewer.getControl().setFocus(); } }
From source file:com.google.appraise.eclipse.ui.AppraiseUiPlugin.java
License:Open Source License
/** * Helper method to open the given file in the workspace editor. *//* w w w .j av a 2 s. c o m*/ public static void openFileInEditor(String filePath, TaskRepository taskRepository) { Repository repository = AppraisePluginUtils.getGitRepoForRepository(taskRepository); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); String fullPath = new Path(repository.getWorkTree().getAbsolutePath()).append(filePath).toOSString(); File file = new File(fullPath); if (!file.exists()) { AppraiseUiPlugin.logError("File to open not found: " + fullPath); return; } IWorkbenchPage page = window.getActivePage(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile fileResource = root.getFileForLocation(new Path(file.getAbsolutePath())); if (fileResource != null) { try { IDE.openEditor(page, fileResource, OpenStrategy.activateOnOpen()); } catch (PartInitException e) { AppraiseUiPlugin.logError("Failed to open editor for " + filePath, e); } } else { IFileStore store = EFS.getLocalFileSystem().getStore(new Path(file.getAbsolutePath())); try { IDE.openEditor(page, new FileStoreEditorInput(store), EditorsUI.DEFAULT_TEXT_EDITOR_ID); } catch (PartInitException e) { AppraiseUiPlugin.logError("Failed to open editor for " + filePath, e); } } }
From source file:com.google.dart.tools.search.ui.text.AbstractTextSearchViewPage.java
License:Open Source License
/** * <p>//from w ww .ja v a2s.c o m * This method is called when the search page gets an 'open' event from its underlying viewer (for * example on double click). The default implementation will open the first match on any element * that has matches. If the element to be opened is an inner node in the tree layout, the node * will be expanded if it's collapsed and vice versa. Subclasses are allowed to override this * method. * </p> * * @param event the event sent for the currently shown viewer * @see IOpenListener */ protected void handleOpen(OpenEvent event) { Viewer viewer = event.getViewer(); boolean hasCurrentMatch = showCurrentMatch(OpenStrategy.activateOnOpen()); ISelection sel = event.getSelection(); if (viewer instanceof TreeViewer && sel instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) sel; TreeViewer tv = (TreeViewer) getViewer(); Object element = selection.getFirstElement(); if (element != null) { if (!hasCurrentMatch && getDisplayedMatchCount(element) > 0) { gotoNextMatch(OpenStrategy.activateOnOpen()); } else { tv.setExpandedState(element, !tv.getExpandedState(element)); } } return; } else if (!hasCurrentMatch) { gotoNextMatch(OpenStrategy.activateOnOpen()); } }
From source file:com.google.dart.tools.ui.actions.OpenAction.java
License:Open Source License
/** * Note: this method is for internal use only. Clients should not call this method. * /*from w ww . ja va 2 s .co m*/ * @param element the element to process * @param candidateRegion * @noreference This method is not intended to be referenced by clients. */ public void run(DartElement element, IRegion candidateRegion) { if (element == null) { return; } IStatus status = Status.OK_STATUS; try { Object elementToOpen = getElementToOpen(element); boolean activateOnOpen = fEditor != null ? true : OpenStrategy.activateOnOpen(); IEditorPart part = EditorUtility.openInEditor(elementToOpen, activateOnOpen); if (part != null && elementToOpen instanceof DartElement) { selectInEditor(part, (DartElement) elementToOpen, candidateRegion); } } catch (PartInitException exception) { String message = Messages.format(ActionMessages.OpenAction_error_problem_opening_editor, new String[] { DartElementLabels.getTextLabel(element, DartElementLabels.ALL_DEFAULT), exception.getStatus().getMessage() }); status = new Status(IStatus.ERROR, DartToolsPlugin.PLUGIN_ID, IStatus.ERROR, message, null); } catch (CoreException exception) { String message = Messages.format(ActionMessages.OpenAction_error_problem_opening_editor, new String[] { DartElementLabels.getTextLabel(element, DartElementLabels.ALL_DEFAULT), exception.getStatus().getMessage() }); status = new Status(IStatus.ERROR, DartToolsPlugin.PLUGIN_ID, IStatus.ERROR, message, null); DartToolsPlugin.log(exception); } if (!status.isOK()) { ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.OpenAction_error_message, status); } }
From source file:com.google.dart.tools.ui.actions.OpenAction.java
License:Open Source License
/** * Note: this method is for internal use only. Clients should not call this method. * // w w w .ja va 2 s .c o m * @param elements the elements to process * @noreference This method is not intended to be referenced by clients. */ public void run(Object[] elements) { EmitInstrumentationCommand(); if (elements == null) { return; } MultiStatus status = new MultiStatus(DartToolsPlugin.PLUGIN_ID, IStatus.OK, ActionMessages.OpenAction_multistatus_message, null); for (int i = 0; i < elements.length; i++) { Object element = elements[i]; try { element = getElementToOpen(element); boolean activateOnOpen = fEditor != null ? true : OpenStrategy.activateOnOpen(); IEditorPart part = EditorUtility.openInEditor(element, activateOnOpen); if (part != null && element instanceof DartElement) { selectInEditor(part, (DartElement) element); } } catch (PartInitException e) { String message = Messages.format(ActionMessages.OpenAction_error_problem_opening_editor, new String[] { DartElementLabels.getTextLabel(element, DartElementLabels.ALL_DEFAULT), e.getStatus().getMessage() }); status.add(new Status(IStatus.ERROR, DartToolsPlugin.PLUGIN_ID, IStatus.ERROR, message, null)); } catch (CoreException e) { String message = Messages.format(ActionMessages.OpenAction_error_problem_opening_editor, new String[] { DartElementLabels.getTextLabel(element, DartElementLabels.ALL_DEFAULT), e.getStatus().getMessage() }); status.add(new Status(IStatus.ERROR, DartToolsPlugin.PLUGIN_ID, IStatus.ERROR, message, null)); DartToolsPlugin.log(e); } } if (!status.isOK()) { IStatus[] children = status.getChildren(); ErrorDialog.openError(getShell(), getDialogTitle(), ActionMessages.OpenAction_error_message, children.length == 1 ? children[0] : status); } }
From source file:com.google.dart.tools.ui.callhierarchy.OpenLocationAction.java
License:Open Source License
@Override public void run(IStructuredSelection selection) { if (!checkEnabled(selection)) { return;/*from w ww . j a va2s .co m*/ } for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { boolean noError = CallHierarchyUI.openInEditor(iter.next(), getShell(), OpenStrategy.activateOnOpen()); if (!noError) { return; } } }
From source file:com.ibm.research.tagging.java.JavaWaypoint.java
License:Open Source License
public void navigate() { if (getMarker().exists()) { try {/*from www . j a v a2 s . c o m*/ IDE.openEditor( JavaWaypointPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(), getMarker(), OpenStrategy.activateOnOpen()); } catch (PartInitException e) { e.printStackTrace(); } } }
From source file:com.liferay.ide.project.ui.migration.MigrationUtil.java
License:Open Source License
public static void openEditor(Problem problem) { try {/*w w w. j av a 2 s. c o m*/ final IResource resource = getIResourceFromProblem(problem); if (resource instanceof IFile) { final IMarker marker = getMarker(problem); if (marker != null) { IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), marker, OpenStrategy.activateOnOpen()); } else { final IEditorPart editor = IDE.openEditor( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), (IFile) resource); if (editor instanceof ITextEditor) { final ITextEditor textEditor = (ITextEditor) editor; textEditor.selectAndReveal(problem.startOffset, problem.endOffset - problem.startOffset); } } } } catch (PartInitException e) { } }
From source file:com.nokia.carbide.search.system.ui.text.AbstractTextSearchViewPage.java
License:Open Source License
/** * <p>This method is called when the search page gets an open even from it's * underlying viewer (for example on double click). The default * implementation will open the first match on any element that has matches. * If the element to be opened is an inner node in the tree layout, the node * will be expanded if it's collapsed and vice versa. Subclasses are allowed * to override this method.// w w w .ja v a 2 s .c o m * </p> * @param event * the event sent for the currently shown viewer * * @see IOpenListener */ protected void handleOpen(OpenEvent event) { Viewer viewer = event.getViewer(); boolean hasCurrentMatch = showCurrentMatch(OpenStrategy.activateOnOpen()); ISelection sel = event.getSelection(); if (viewer instanceof TreeViewer && sel instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) sel; TreeViewer tv = (TreeViewer) getViewer(); Object element = selection.getFirstElement(); if (element != null) { if (!hasCurrentMatch && getDisplayedMatchCount(element) > 0) gotoNextMatch(OpenStrategy.activateOnOpen()); else tv.setExpandedState(element, !tv.getExpandedState(element)); } return; } else if (!hasCurrentMatch) { gotoNextMatch(OpenStrategy.activateOnOpen()); } }