private boolean selectTreePath(Viewer viewer, TreePath parentPath, Object element) { // Cut off children of elements that are shown repeatedly. for (int i = 0; i < parentPath.getSegmentCount() - 1; i++) { if (element.equals(parentPath.getSegment(i))) { return false; } } if (!(viewer instanceof TreeViewer)) { return true; } if (matcher == null) { return true; } TreeViewer treeViewer = (TreeViewer) viewer; Boolean matchingResult = isMatchingOrNull(element); if (matchingResult != null) { return matchingResult; } return hasUnfilteredChild(treeViewer, parentPath, element); }
public static IJavaProject[] getJavaProjects(final ITreeSelection treeSelection) { if (treeSelection == null) { return new IJavaProject[0]; } final List<IJavaProject> projects = new ArrayList<>(); final TreePath[] paths = treeSelection.getPaths(); for (final TreePath treePath : paths) { if (treePath.equals(TreePath.EMPTY)) { continue; } for (int i = 0; i < treePath.getSegmentCount(); i++) { final Object segment = treePath.getSegment(i); if ((segment instanceof IJavaProject)) { projects.add((IJavaProject) segment); break; } } } return projects.toArray(new IJavaProject[projects.size()]); }
public static IJavaElement[] getJavaElements(final ITreeSelection selection) { if (selection == null) { return new IJavaProject[0]; } final List<IJavaElement> projects = new ArrayList<>(); for (final TreePath treePath : selection.getPaths()) { if (treePath.equals(TreePath.EMPTY)) { continue; } final Object lastSegment = treePath.getLastSegment(); if (!(lastSegment instanceof IJavaElement)) { continue; } projects.add((IJavaElement) lastSegment); } return projects.toArray(new IJavaElement[projects.size()]); }
@Override protected boolean computeEnablement(final IStructuredSelection selection) { if (selection.size() != 1) { return false; } // For VS 2010 the content provider is a TreeContentProvider. Only // enable this action for history items at the root level. For // versions prior to 2010 the condition for enablement conditions // are unchanged. boolean isRootItemSelected = true; if (selection instanceof ITreeSelection) { final ITreeSelection treeSelection = (ITreeSelection) selection; final TreePath[] treePaths = treeSelection.getPaths(); if (treePaths.length == 1) { isRootItemSelected = treePaths[0].getSegmentCount() == 1; } } final String item = historyInput.getHistoryItem(); return !ServerPath.isServerPath(item) && isRootItemSelected; }
public void setInput(PageRoot inputElement) { input = inputElement; if (viewer != null) { Object[] expandedElements = viewer.getExpandedElements(); TreePath[] expandedTreePaths = viewer.getExpandedTreePaths(); viewer.setInput(input); viewer.setExpandedElements(expandedElements); viewer.setExpandedTreePaths(expandedTreePaths); actions.get(ACTION_COPY).setEnabled(true); actions.get(ACTION_CUT).setEnabled(true); actions.get(ACTION_PASTE).setEnabled(true); actions.get(ACTION_DELETE).setEnabled(true); } }
/** * getExpandTreePaths * * @param tree * @param selectedItem * @return TreePath[] */ public static TreePath[] getExpandTreePaths(Tree tree, TreeItem selectedItem) { ArrayList<Object> items = new ArrayList<Object>(); internalCollectTreeItems(items, tree); ArrayList<Object> result = new ArrayList<Object>(); for (Iterator<Object> it = items.iterator(); it.hasNext();) { Item item = (Item) it.next(); // if (item == selectedItem) { TreePath treePath = getTreePathFromItem(item); if (treePath != null) { result.add(treePath); } // } } return (TreePath[]) result.toArray(new TreePath[items.size()]); }
/** * hierarchyCheck * * @return boolean */ protected boolean hierarchyCheck() { CommonViewer commonViewer = ViewerRegistry.getViewer(); TreeSelection sel = (TreeSelection) commonViewer.getSelection(); List<TreePath> pathList = Arrays.asList(sel.getPaths()); for (TreePath path : pathList) { if (isContains(pathList, path.getParentPath())) { MessageDialog.openError(ProjectExplorerPlugin.getShell(), UMLMessage.LABEL_FILE_FRAGMENTATION, UMLMessage.MESSAGE_FRAGMENT_DEFRAGMENT_ERROR_MESSAGE/*"패키지 간 상하 관계가 포함된 경우 일괄 단편화/병합을 실행할 수 없습니다."*/); return false; } } return true; }
protected void doRunSimulationExperiment() { TreePath[] paths = suiteViewer.getStructuredSelection().getPaths(); if ((paths != null)&&(paths.length>0)) { TreePath selected = paths[0]; if (selected.getSegmentCount()>=2) { SimulationSuiteElement simulationSuiteElement = (SimulationSuiteElement) selected.getSegment(1); RunSimulationExperimentJob experiment = new RunSimulationExperimentJob(this, simulationSuiteElement); //update the Lab View //updateView(); experiment.setUser(true); experiment.schedule(); } } }
private void refreshTreeViewer(final BTSCorpusObject btsCorpusObject) { sync.asyncExec(new Runnable() { public void run() { if (!mainTreeViewer.getTree().isDisposed()) { // mainTreeViewer // .removeSelectionChangedListener(selectionListener); for (TreePath path : mainTreeViewer.getExpandedTreePaths()) System.out.println(path.getLastSegment()); mainTreeViewer.refresh(); // mainTreeViewer.addSelectionChangedListener(selectionListener); } } }); }
@Override public void handleEvent(final Event event) { // FIXME hack, should be solved be resetting the selection in viewer // instead btnToEdit.setEnabled(false); btnUngroup.setEnabled(false); final TreePath[] paths = xViewer.getSelection().getPaths(); if (paths.length > 0) { final Copy copy = (Copy) paths[0].getLastSegment(); setInput(copy); copies.remove(copy); bindingContext.updateTargets(); checkGroups(); updateToListButton(); updateSaveButton(); xViewer.setInput(copies); } }
@Override public void doubleClick(final DoubleClickEvent event) { // safety check first if (event == null || event.getSelection() == null || !(event.getSelection() instanceof TreeSelection)) { return; } final TreeSelection selection = (TreeSelection) event.getSelection(); final TreePath[] paths = selection.getPaths(); final TreePath treePath = paths[paths.length - 1]; final Object segment = treePath.getLastSegment(); final TreeItem[] items = viewer.getTree().getItems(); final TreeItem item = getItem(items, segment); if (item != null) { item.setExpanded(!item.getExpanded()); viewer.refresh(); } }
private void copyTreeSelectionToClipboard() { ITreeSelection selection = (ITreeSelection) treeViewer.getSelection(); TreePath[] paths = selection.getPaths(); StringBuffer buf = new StringBuffer(); for (TreePath path : paths) { LogEntry<?> entry = (LogEntry<?>) path.getLastSegment(); buf.append(createTabString(path.getSegmentCount() - 1)); buf.append(entry.toString()); buf.append("\n"); } if (buf.length() > 0) { buf.deleteCharAt(buf.length() - 1); // take off last \n } copyToClipboard(buf.toString()); }
/** * We will accept the selection in the workbench to see if we can initialize * from it. * * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection) */ public void init(IWorkbench workbench, IStructuredSelection selection) { if (selection instanceof StructuredSelection) { if (selection.getFirstElement() instanceof IProject || selection.getFirstElement() instanceof IFile || selection.getFirstElement() instanceof IFolder) { this.selection = selection; return; } for (Object obj : selection.toList()) { if (obj instanceof EditPart) { IEditorInput ein = SelectionHelper.getActiveJRXMLEditor().getEditorInput(); if (ein instanceof FileEditorInput) { this.selection = new TreeSelection(new TreePath(new Object[] { ((FileEditorInput) ein).getFile() })); return; } } } } this.selection = selection; }
@Override public void init(IWorkbench workbench, IStructuredSelection selection) { if (selection instanceof StructuredSelection) { if (selection.getFirstElement() instanceof IProject || selection.getFirstElement() instanceof IFile || selection.getFirstElement() instanceof IFolder) { this.selection = selection; return; } for (Object obj : selection.toList()) { if (obj instanceof EditPart) { IEditorInput ein = SelectionHelper.getActiveJRXMLEditor().getEditorInput(); if (ein instanceof FileEditorInput) { this.selection = new TreeSelection(new TreePath(new Object[] { ((FileEditorInput) ein).getFile() })); return; } } } } this.selection = selection; }
@Override public void run() { TreeSelection s = (TreeSelection) treeViewer.getSelection(); TreePath[] p = s.getPaths(); for (int i = 0; i < p.length;) { final Object obj = p[i].getLastSegment(); if (obj instanceof ANode) { ANode parent = (ANode) obj; AddResourceWizard wizard = new AddResourceWizard(parent); WizardDialog dialog = new WizardDialog(UIUtils.getShell(), wizard); dialog.create(); dialog.open(); } break; } }
@Override public void run() { final TreeSelection s = (TreeSelection) treeViewer.getSelection(); TreePath[] p = s.getPaths(); for (int i = 0; i < p.length; i++) { final Object obj = p[i].getLastSegment(); if (obj instanceof MResource) { PermissionWizard wizard = new PermissionWizard((MResource) obj); PermissionDialog dialog = new PermissionDialog(UIUtils.getShell(), wizard); dialog.addApplyListener(wizard); dialog.open(); } else if (obj instanceof MServerProfile) { EditServerAction.fillServerProfile((MServerProfile) obj, treeViewer); } } }
@Override public void run() { final TreeSelection s = (TreeSelection) treeViewer.getSelection(); TreePath[] p = s.getPaths(); for (int i = 0; i < p.length; i++) { Object obj = p[i].getLastSegment(); if (obj instanceof MResource) { INode node = ((MResource) obj).getReportUnit(); if (node != null) { final String key = ServerManager.getKey((MReportUnit) node); if (key != null) Display.getDefault().asyncExec(new Runnable() { public void run() { SelectionHelper.openEditor(key, ReportUnitEditor.ID); } }); } break; } } }
@Override public void run() { TreeSelection s = (TreeSelection) treeViewer.getSelection(); TreePath[] p = s.getPaths(); List<MResource> rlist = new ArrayList<MResource>(); for (int i = 0; i < p.length; i++) { final Object obj = p[i].getLastSegment(); if (obj instanceof MResource) { System.out.println(((MResource) obj).getToolTip()); ((MResource) obj).setCut(true); rlist.add((MResource) obj); } } if (!rlist.isEmpty()) Clipboard.getDefault().setContents(rlist); }
public void editElement(Object element, int column) { if (element instanceof TreePath) { setSelection(new TreeSelection((TreePath) element)); GalleryItem[] items = gallery.getSelection(); if (items.length == 1) { ViewerRow row = getViewerRowFromItem(items[0]); if (row != null) { ViewerCell cell = row.getCell(column); if (cell != null) { getControl().setRedraw(false); triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell)); getControl().setRedraw(true); } } } } else { super.editElement(element, column); } }
@Override public void run() { TreeSelection s = (TreeSelection) treeViewer.getSelection(); TreePath[] p = s.getPaths(); for (int i = 0; i < p.length; i++) { Object obj = p[i].getLastSegment(); if (obj instanceof MDataAdapter) { SaveAsDialog saveAsDialog = new SaveAsDialog(Display.getDefault().getActiveShell()); saveAsDialog.setOriginalName(((MDataAdapter) obj).getValue().getName().replace(" ", "") + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ saveAsDialog.open(); IPath path = saveAsDialog.getResult(); if (path != null) saveFile(obj, path); } } }
@Override public void run() { TreeSelection s = (TreeSelection) treeViewer.getSelection(); TreePath[] p = s.getPaths(); if (!UIUtils.showDeleteConfirmation()) return; ADataAdapterStorage storage = null; for (int i = 0; i < p.length; i++) { Object obj = p[i].getLastSegment(); if (obj instanceof MDataAdapter) { MDataAdapter mDataAdapter = (MDataAdapter) obj; DataAdapterDescriptor m = mDataAdapter.getValue(); if (storage == null) storage = ((MDataAdapters) mDataAdapter.getParent()).getValue(); if (storage != null) storage.removeDataAdapter(m); treeViewer.refresh(true); } } }
public void setActivePart(IAction action, IWorkbenchPart targetPart) { ISelection s = targetPart.getSite().getSelectionProvider().getSelection(); if (s instanceof TreeSelection) { TreePath[] tp = ((TreeSelection) s).getPaths(); for (int i = 0; i < tp.length; i++) { Object obj = tp[i].getFirstSegment(); if (obj instanceof IProject) { try { if (((IProject) obj).hasNature(JasperReportsNature.NATURE_ID)) action.setChecked(true); else { action.setChecked(false); break; } } catch (CoreException e) { e.printStackTrace(); } } } } }
/** * @param allVisibleItems * @param allExpandedItems * @return Returns {@link TreePath}'s which are expanded and open (not hidden). */ public static TreePath[] getExpandedOpenedItems(final Object[] allVisibleItems, final TreePath[] allExpandedItems) { final ArrayList<TreePath> expandedOpened = new ArrayList<TreePath>(); for (final TreePath expandedPath : allExpandedItems) { /* * The last expanded segment must be in the visible list otherwise it is hidden. */ final Object lastExpandedItem = expandedPath.getLastSegment(); for (final Object visibleItem : allVisibleItems) { if (lastExpandedItem == visibleItem) { expandedOpened.add(expandedPath); break; } } } return expandedOpened.toArray(new TreePath[expandedOpened.size()]); }
private List<TreePath> getTreePaths(List<Object> modelParents, int index) { List<TreePath> result= new ArrayList<TreePath>(); Object input= getViewerInput(); Object element= modelParents.get(index); Object[] parents= fWorkingSetModel.getAllParents(element); for (int i= 0; i < parents.length; i++) { List<Object> chain= new ArrayList<Object>(); if (!parents[i].equals(input)) chain.add(parents[i]); for (int m= index; m < modelParents.size(); m++) { chain.add(modelParents.get(m)); } result.add(new TreePath(chain.toArray())); } return result; }
public void updateLabel(ViewerLabel label, TreePath elementPath) { Object firstSegment = elementPath.getFirstSegment(); if (firstSegment instanceof IProject && elementPath.getSegmentCount() == 2) { IProject project = (IProject) firstSegment; Object lastSegment = elementPath.getLastSegment(); if (lastSegment instanceof IFolder) { IFolder folder = (IFolder) lastSegment; if (!folder.getParent().equals(project)) { // This means that a folder that is not a direct child of the project // is a child in the tree. Therefore, the resource content provider // must be active and in compress folder mode so we will leave // it to the resource provider to provide the proper label. // We need to do this because of bug 153912 return; } } } label.setImage(getImage(elementPath.getLastSegment())); label.setText(getText(elementPath.getLastSegment())); Font f = getFont(elementPath.getLastSegment()); if (f != null) label.setFont(f); }
public SelectObject(ExecutionEvent event, String outputFolder) { ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof TreeSelection) { TreeSelection tselection = (TreeSelection) selection; TreePath[] paths = tselection.getPaths(); TreePath path = paths[0]; Object firstSegment = path.getFirstSegment(); if (firstSegment instanceof IProject) { project = (IProject) path.getFirstSegment(); javaProject = JavaCore.create(project); } else if (firstSegment instanceof IJavaProject) { javaProject = (IJavaProject) path.getFirstSegment(); project = javaProject.getProject(); } IFolder source = project.getFolder(outputFolder); IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(source); packageRoot = root; Object o = tselection.getFirstElement(); if (o instanceof IFile) { this.file = (IFile) o; } } }
/** * Adds the supplied contour to the tree viewer. This method is called by * {@link #contourAdded(IExecutionModel, AtomicInsert)}. * * @param model * the model in which the contour was added * @param contour * the contour that was added * @param parent * the parent of the added contour */ private void addContour(final AtomicInsert change) { final TreeViewer viewer = this.owner.getViewer(); if (!viewer.getControl().isDisposed()) { if (change.contour().parent() == null) { viewer.add(viewer.getInput(), change.contour()); } else { if (change.contour().model().contourView().contains(change.contour().parent())) { final TreePath path = createTreePath(change.contour().parent()); viewer.add(path, change.contour()); viewer.expandToLevel(path, 1); } else { viewer.add(change.contour().parent(), change.contour()); } } } }
/** * Creates a {@code TreePath} for the supplied contour, so that it may be used to efficiently add * (remove) a contour to (from) the tree viewer. * * @param model * the model containing the contour * @param contour * the contour for which to construct a path * @return a tree path from the root to the contour, inclusive */ private TreePath createTreePath(IContour contour) { final IExecutionModel model = contour.model(); model.readLock(); try { final LinkedList<IContour> segmentList = new LinkedList<IContour>(); do { segmentList.addFirst(contour); contour = contour.parent(); } while (contour != null); return new TreePath(segmentList.toArray()); } finally { model.readUnlock(); } }
/** * Removes the supplied contour from the tree viewer. This method is called by * {@link #removeContour(IExecutionModel, AtomicDelete)}. * * @param model * the model in which the contour was removed * @param contour * the contour that was removed * @param oldParent * the parent of the removed contour */ private void removeContour(final AtomicDelete removed) { final TreeViewer viewer = this.owner.getViewer(); if (!viewer.getControl().isDisposed()) { final Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (removed.contour().equals(selection)) { this.owner.fMemberTableViewer.setInput(null); } // old parent might not be in the model if the remove was a result of a rollback if (removed.contour().model().contourView().contains(removed.contour().parent())) { // read-locks final TreePath path = createTreePath(removed.contour().parent()); viewer.remove(path.createChildPath(removed.contour())); } else { viewer.remove(removed.contour()); } } }
public void updateStatus( TreeViewer treeViewer ) { TreePath[] treepaths = treeViewer.getExpandedTreePaths( ); List list = Arrays.asList( treepaths ); leafList.clear( ); leafList.addAll( list ); for ( int i = 0; i < leafList.size( ); i++ ) { TreePath path = ( (TreePath) leafList.get( i ) ).getParentPath( ); if ( path == null ) { leafList.remove( i ); i--; } if ( leafList.contains( path ) ) { leafList.remove( path ); i--; } } }
/** * Render a selected variable. * * @param selection * the selection object * @param element * the variable element * @throws DebugException */ private void displayVariable(IStructuredSelection selection, IDebugElement element) throws DebugException { IValue value = ((IVariable) element).getValue(); if (value instanceof IJavaPrimitiveValue) { setBrowserTextToPrimitive((IJavaPrimitiveValue) value); } else { TreePath firstElementTreePath = ((TreeSelection) selection).getPaths()[0]; String watchExpression = generateWatchExpression(firstElementTreePath); String messageExpression = generateMessageExpression(watchExpression); // Iterate all threads and run our rendering // expression in them in the hopes that we can find // the relevant selection in only one thread // FIXME find a better way to derive the correct thread! IWatchExpressionDelegate delegate = DebugPlugin.getDefault().getExpressionManager() .newWatchExpressionDelegate(element.getModelIdentifier()); for (IThread thread : element.getDebugTarget().getThreads()) { delegate.evaluateExpression(messageExpression, thread, this); } } }
/** * Moves the outline view to show the element where the cursor in the * text editor is placed. */ @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection instanceof ITextSelection) { ITextSelection textSelection = (ITextSelection) selection; int start = textSelection.getOffset(); int length = textSelection.getLength(); JsonTreeNode element = fContentProvider.findNearestElement(start, length); if (element != null) { element.setTextSelection(true); getTreeViewer().reveal(element); TreeSelection treeSelection = new TreeSelection(new TreePath(new Object[]{element})); getTreeViewer().setSelection(treeSelection); } } }
/** * Saves some selection in the memento object. */ private void save(TreePath treePath, String type) { if (treePath != null) { Object object = treePath.getLastSegment(); if (object instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) object; IResource resource = (IResource) adaptable.getAdapter(IResource.class); if (resource != null) { IPath path = resource.getLocation(); if (path != null) { memento.createChild(type, path.toPortableString()); } } } } }