/** * An editor has been activated. Set the selection in this Packages Viewer * to be the editor's input, if linking is enabled. * @param editor the activated editor */ void editorActivated(IEditorPart editor) { IEditorInput editorInput= editor.getEditorInput(); if (editorInput == null) return; Object input= getInputFromEditor(editorInput); if (input == null) return; if (!inputIsSelected(editorInput)) showInput(input); else getTreeViewer().getTree().showSelection(); }
@Override public void run() { IWorkbenchPart activePart= getActivePart(); if (activePart instanceof IPackagesViewPart) { PackageExplorerPart view= PackageExplorerPart.openInActivePerspective(); view.tryToReveal(newElement); } } });
@Override public void init(IViewSite site, IMemento memento) throws PartInitException { super.init(site, memento); if (memento == null) { String persistedMemento= fDialogSettings.get(TAG_MEMENTO); if (persistedMemento != null) { try { memento= XMLMemento.createReadRoot(new StringReader(persistedMemento)); } catch (WorkbenchException e) { // don't do anything. Simply don't restore the settings } } } fMemento= memento; if (memento != null) { restoreLayoutState(memento); restoreLinkingEnabled(memento); restoreRootMode(memento); } if (getRootMode() == WORKING_SETS_AS_ROOTS) { createWorkingSetModel(); } }
public IStatus runInUIThread(IProgressMonitor monitor) { long start = System.currentTimeMillis(); PackageExplorerPart pep = PackageExplorerPart .getFromActivePerspective(); if (pep != null) { pep.getTreeViewer().refresh(); } previousExecutionTime = (int)(System.currentTimeMillis() - start); //System.out.println("refresh explorer: elapsed="+previousExecutionTime); return Status.OK_STATUS; } }
private void doWorkingSetChanged(PropertyChangeEvent event) { if (ViewActionGroup.MODE_CHANGED.equals(event.getProperty())) { fPart.rootModeChanged(((Integer)event.getNewValue()).intValue()); Object oldInput= null; Object newInput= null; if (fPart.getRootMode() == PackageExplorerPart.PROJECTS_AS_ROOTS) { oldInput= fPart.getWorkingSetModel(); newInput= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); } else { oldInput= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); newInput= fPart.getWorkingSetModel(); if (workingSet != null) workingSetLabel= BasicElementLabels.getWorkingSetLabel(workingSet); fPart.setWorkingSetLabel(workingSetLabel); fPart.updateTitle(); TreeViewer viewer= fPart.getTreeViewer(); viewer.getControl().setRedraw(false); viewer.refresh();
return null; if (explorerPart.getRootMode() == ViewActionGroup.SHOW_PROJECTS) { IWorkingSet filterWorkingSet= explorerPart.getFilterWorkingSet(); if (filterWorkingSet == null) return null; } else if (explorerPart.getRootMode() == ViewActionGroup.SHOW_WORKING_SETS) { Object input= explorerPart.getViewPartInput(); if (!(input instanceof IWorkingSet)) return null;
private void doWorkingSetChanged(PropertyChangeEvent event) { if (ViewActionGroup.MODE_CHANGED.equals(event.getProperty())) { fPart.rootModeChanged(((Integer)event.getNewValue()).intValue()); Object oldInput= null; Object newInput= null; if (fPart.showProjects()) { oldInput= fPart.getWorkingSetModel(); newInput= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); } else if (fPart.showWorkingSets()) { oldInput= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); newInput= fPart.getWorkingSetModel(); if (workingSet != null) workingSetLabel= workingSet.getLabel(); fPart.setWorkingSetLabel(workingSetLabel); fPart.updateTitle(); TreeViewer viewer= fPart.getTreeViewer(); viewer.getControl().setRedraw(false); viewer.refresh();
private void gotoType(IType type) { ICompilationUnit cu= (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT); IJavaElement element= null; if (cu != null) { element= cu.getPrimary(); } else { element= type.getAncestor(IJavaElement.CLASS_FILE); } if (element != null) { PackageExplorerPart view= PackageExplorerPart.openInActivePerspective(); if (view != null) { view.selectReveal(new StructuredSelection(element)); if (!element.equals(getSelectedElement(view))) { MessageDialog.openInformation(fPackageExplorer.getSite().getShell(), getDialogTitle(), Messages.format(PackagesMessages.PackageExplorer_element_not_present, JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT))); } } } }
private boolean revealAndVerify(Object element) { if (element == null) return false; selectReveal(new StructuredSelection(element)); return ! getSite().getSelectionProvider().getSelection().isEmpty(); }
@Override public boolean show(ShowInContext context) { ISelection selection= context.getSelection(); if (selection instanceof IStructuredSelection) { // fix for 64634 Navigate/Show in/Package Explorer doesn't work IStructuredSelection structuredSelection= ((IStructuredSelection) selection); if (structuredSelection.size() == 1) { int res= tryToReveal(structuredSelection.getFirstElement()); if (res == IStatus.OK) return true; if (res == IStatus.CANCEL) return false; } else if (structuredSelection.size() > 1) { selectReveal(structuredSelection); return true; } } Object input= context.getInput(); if (input instanceof IEditorInput) { Object elementOfInput= getInputFromEditor((IEditorInput) input); return elementOfInput != null && (tryToReveal(elementOfInput) == IStatus.OK); } return false; }
PackagesFrameSource(PackageExplorerPart explorer) { super(explorer.getTreeViewer()); fPackagesExplorer= explorer; }
public void run() { IStructuredSelection selection= (IStructuredSelection)fPackageExplorer.getSite().getSelectionProvider().getSelection(); Object element= selection.getFirstElement(); if (element instanceof ClassPathContainer.RequiredProjectWrapper) { ClassPathContainer.RequiredProjectWrapper wrapper= (ClassPathContainer.RequiredProjectWrapper) element; fPackageExplorer.tryToReveal(wrapper.getProject()); } } }
private IElementComparer createElementComparer() { if (getRootMode() == PROJECTS_AS_ROOTS) return null; else return WorkingSetModel.COMPARER; }
@Override public void selectReveal(final ISelection selection) { Control ctrl= getTreeViewer().getControl(); if (ctrl == null || ctrl.isDisposed()) return; fContentProvider.runPendingUpdates(); fViewer.setSelection(convertSelection(selection), true); }
public void setLinkingEnabled(boolean enabled) { fLinkingEnabled= enabled; saveDialogSettings(); IWorkbenchPage page= getSite().getPage(); if (enabled) { page.addPartListener(fLinkWithEditorListener); IEditorPart editor = page.getActiveEditor(); if (editor != null) { editorActivated(editor); } } else { page.removePartListener(fLinkWithEditorListener); } }
private boolean isActivePart() { return this == getSite().getPage().getActivePart(); }
@Override public boolean performFinish() { fPage.finish(); IWorkingSet ws= fPage.getSelection(); if (ws != null) { PlatformUI.getWorkbench().getWorkingSetManager().addWorkingSet(ws); PackageExplorerPart explorer= getActivePackageExplorer(); if (explorer != null) { if (explorer.getRootMode() == PackageExplorerPart.WORKING_SETS_AS_ROOTS) { explorer.selectReveal(new StructuredSelection(ws)); } } } return true; }
private Object findInputElement() { if (getRootMode() == WORKING_SETS_AS_ROOTS) { return fWorkingSetModel; } else { Object input= getSite().getPage().getInput(); if (input instanceof IWorkspace) { return JavaCore.create(((IWorkspace)input).getRoot()); } else if (input instanceof IContainer) { IJavaElement element= JavaCore.create((IContainer)input); if (element != null && element.exists()) return element; return input; } //1GERPRT: ITPJUI:ALL - Packages View is empty when shown in Type Hierarchy Perspective // we can't handle the input // fall back to show the workspace return JavaCore.create(JavaPlugin.getWorkspace().getRoot()); } }
private boolean reveal(PackageExplorerPart view, Object element) { if (view == null) { return false; } view.selectReveal(new StructuredSelection(element)); IElementComparer comparer= view.getTreeViewer().getComparer(); Object selected= getSelectedElement(view); if (comparer != null ? comparer.equals(element, selected) : element.equals(selected)) { return true; } return false; }
@Override public void run() { TreeViewer viewer= fPackageExplorer.getTreeViewer(); GotoResourceDialog dialog= new GotoResourceDialog(fPackageExplorer.getSite().getShell(), ResourcesPlugin.getWorkspace().getRoot(), viewer); dialog.open(); Object[] result = dialog.getResult(); if (result == null || result.length == 0 || !(result[0] instanceof IResource)) return; StructuredSelection selection= null; IJavaElement element = JavaCore.create((IResource)result[0]); if (element != null && element.exists()) selection= new StructuredSelection(element); else selection= new StructuredSelection(result[0]); viewer.setSelection(selection, true); } }