List of usage examples for org.eclipse.jface.viewers TreeViewer expandToLevel
public void expandToLevel(int level)
From source file:com.safi.workshop.sqlexplorer.preview.XmlPreviewer.java
License:Open Source License
public void createControls(Composite parent, final Object data) throws ExplorerException { Element rootElem = getXml(data); if (rootElem == null) return;//from w w w. j ava2 s . c o m final Object[] root = new Object[] { rootElem }; TreeViewer tree = new TreeViewer(parent, SWT.SINGLE); tree.setContentProvider(new ITreeContentProvider() { public void dispose() { } /** * Called to get the top level items */ public Object[] getChildren(Object parentElement) { return root; } /** * Called to get the item's children */ public Object[] getElements(Object inputElement) { Element elem = (Element) inputElement; return elem.elements().toArray(); } public boolean hasChildren(Object element) { Element elem = (Element) element; List<Element> list = elem.elements(); return list != null && list.size() > 0; } public Object getParent(Object element) { Element elem = (Element) element; return elem.getParent(); } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // Nothing } }); tree.setLabelProvider(new LabelProvider() { @Override public String getText(Object obj) { Element elem = (Element) obj; StringBuffer result = new StringBuffer(); result.append('<'); result.append(elem.getName()); for (Object o : elem.attributes()) { Attribute attr = (Attribute) o; result.append(' ').append(attr.getName()).append('=').append('\"').append(attr.getValue()) .append('\"'); } if (!elem.hasContent()) result.append('/'); result.append('>'); return result.toString(); } }); tree.expandToLevel(1); }
From source file:com.twinsoft.convertigo.eclipse.property_editors.XmlQNameEditorComposite.java
License:Open Source License
public XmlQNameEditorComposite(final Composite parent, int style, AbstractDialogCellEditor cellEditor) { super(parent, style, cellEditor); try {//from w w w . ja va 2s .co m String propertyName = "" + cellEditor.propertyDescriptor.getId(); DatabaseObject dbo = cellEditor.databaseObjectTreeObject.getObject(); Project project = dbo.getProject(); collection = Engine.theApp.schemaManager.getSchemasForProject(project.getName()); currentNamespace = project.getTargetNamespace(); if ("xmlTypeAffectation".equals(propertyName)) { // useComplexType = true; // TODO: add complex type support for input variables useSimpleType = true; } else { useComplexType = "xmlComplexTypeAffectation".equals(propertyName); useSimpleType = "xmlSimpleTypeAffectation".equals(propertyName); } useType = useComplexType || useSimpleType; useRef = "xmlElementRefAffectation".equals(propertyName); } catch (Exception e) { e.printStackTrace(); } this.setLayoutData(new GridData(GridData.FILL_BOTH)); this.setLayout(new GridLayout(1, false)); new Label(this, style).setText("Existing objects"); final TreeViewer treeViewer = new TreeViewer(this); treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); treeViewer.setContentProvider(new SchemaViewContentProvider() { @Override protected void filter(XmlSchemaObject xso, List<XmlSchemaObject> children, XmlSchemaObject subObject) { if (xso instanceof XmlSchema) { if ((useSimpleType && subObject instanceof XmlSchemaSimpleType) || useComplexType && subObject instanceof XmlSchemaComplexType || useRef && subObject instanceof XmlSchemaElement) { super.filter(xso, children, subObject); } } else { super.filter(xso, children, subObject); } } @Override public Object[] getChildren(Object object) { Object[] children = super.getChildren(object); for (Object child : children) { if (child instanceof NamedList) { if (useType && "Types".equals(((NamedList) child).getName())) { return new Object[] { child }; } else if (useRef && "Elements".equals(((NamedList) child).getName())) { return new Object[] { child }; } } else { return children; } } return children; } }); treeViewer.setComparer(new IElementComparer() { public int hashCode(Object element) { return element.hashCode(); } public boolean equals(Object a, Object b) { return a == b; } }); DecoratingLabelProvider dlp = new DecoratingLabelProvider(new SchemaViewLabelProvider(), new SchemaViewLabelDecorator()); treeViewer.setLabelProvider(dlp); treeViewer.setInput(collection); treeViewer.expandToLevel(3); new Label(this, SWT.NONE).setText("Namespace"); tNamespace = new Text(this, SWT.NONE); tNamespace.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tNamespace.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); tNamespace.setEditable(false); new Label(this, SWT.NONE).setText("Local name"); tLocalName = new Text(this, SWT.NONE); tLocalName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Button bNone = new Button(this, SWT.NONE); bNone.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); bNone.setText("No " + (useComplexType ? "type" : (useRef ? "element" : "object"))); new Label(this, SWT.NONE).setText("Summary"); lSummary = new Label(this, SWT.WRAP); lSummary.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); lSummary.setText("No change."); lSummary.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { TreePath[] path = ((ITreeSelection) event.getSelection()).getPaths(); XmlSchemaObject object = null; QName qName = null; if (path.length > 0 && path[0].getSegmentCount() > 2 && path[0].getSegment(2) instanceof XmlSchemaType) { object = (XmlSchemaType) path[0].getSegment(2); qName = ((XmlSchemaType) object).getQName(); } if (path.length > 0 && path[0].getSegmentCount() > 2 && path[0].getSegment(2) instanceof XmlSchemaElement) { object = (XmlSchemaElement) path[0].getSegment(2); qName = ((XmlSchemaElement) object).getQName(); } if (object != null) { String obText = (useType ? "type" : (useRef ? "element" : "object")); tLocalName.setText(qName.getLocalPart()); tNamespace.setText(qName.getNamespaceURI()); updateLabel(obText, qName, object); XmlQNameEditorComposite.this.layout(true); } } }); bNone.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { tNamespace.setText(""); tLocalName.setText(""); lSummary.setText("No " + (useType ? "type" : (useRef ? "element" : "object")) + " set."); lSummary.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); } }); tLocalName.addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent e) { if (e.text.contains(" ")) { e.doit = false; } } }); tLocalName.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { String txt = tLocalName.getText(); if (txt.length() == 0) { //bNone.notifyListeners(SWT.Selection, null); // commented to prevent stack over flow } else { tNamespace.setText(currentNamespace); QName qName = new QName(currentNamespace, txt); XmlSchemaType type = collection.getTypeByQName(qName); XmlSchemaElement element = collection.getElementByQName(qName); XmlSchemaObject object = type == null ? element : type; String obText = (useType ? "type" : (useRef ? "element" : "object")); if (object == null) { lSummary.setText("Create the dynamic " + obText + " : \n" + qName.toString()); lSummary.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_MAGENTA)); XmlQNameEditorComposite.this.layout(true); } else { updateLabel(obText, qName, object); } } } }); if (useSimpleType) { tLocalName.setEnabled(false); bNone.setEnabled(false); } XmlQName schemaDefinition = (XmlQName) cellEditor.getValue(); if (schemaDefinition != null) { QName qName = schemaDefinition.getQName(); if (useType) { XmlSchemaType type = collection.getTypeByQName(qName); if (type != null) { treeViewer.setSelection(new StructuredSelection(type), true); } } if (useRef) { XmlSchemaElement element = collection.getElementByQName(qName); if (element != null) { treeViewer.setSelection(new StructuredSelection(element), true); } } } }
From source file:com.twinsoft.convertigo.eclipse.views.schema.SchemaView.java
License:Open Source License
private TreeViewer makeTreeViewer(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(SwtUtils.newGridLayout(1, false, 0, 0, 0, 0)); ToolBar toolbar = new ToolBar(composite, SWT.NONE); toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final TreeViewer treeViewer = new TreeViewer(composite); ToolItem toolItem = new ToolItem(toolbar, SWT.PUSH); setToolItemIcon(toolItem, "icons/studio/collapse_all_nodes.gif", "C", "Collapse all"); toolItem.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { treeViewer.collapseAll();/*w ww .j a va2 s .c o m*/ } public void widgetDefaultSelected(SelectionEvent e) { } }); toolItem = new ToolItem(toolbar, SWT.PUSH); setToolItemIcon(toolItem, "icons/studio/expand_all_nodes.gif", "E", "Expand all"); toolItem.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { treeViewer.expandToLevel(50); } public void widgetDefaultSelected(SelectionEvent e) { } }); treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); treeViewer.setLabelProvider(SchemaViewContentProvider.decoratingLabelProvider); treeViewer.setComparer(new IElementComparer() { public int hashCode(Object element) { String txt = SchemaViewContentProvider.decoratingLabelProvider.getText(element); int hash = txt.hashCode(); if (element instanceof XmlSchemaObject) { Iterator<DatabaseObject> ref = SchemaMeta .getReferencedDatabaseObjects((XmlSchemaObject) element).iterator(); if (ref.hasNext()) { hash += ref.next().hashCode(); } } return hash; } public boolean equals(Object a, Object b) { boolean ret = false; if (a != null && b != null && a.getClass().equals(b.getClass())) { String aTxt = SchemaViewContentProvider.decoratingLabelProvider.getText(a); String bTxt = SchemaViewContentProvider.decoratingLabelProvider.getText(b); if (aTxt.equals(bTxt)) { if (a instanceof XmlSchemaObject) { Iterator<DatabaseObject> aRef = SchemaMeta .getReferencedDatabaseObjects((XmlSchemaObject) a).iterator(); Iterator<DatabaseObject> bRef = SchemaMeta .getReferencedDatabaseObjects((XmlSchemaObject) b).iterator(); if (aRef.hasNext() && bRef.hasNext()) { ret = aRef.next() == bRef.next(); } } else { ret = true; } } } return ret; } }); return treeViewer; }
From source file:de.loskutov.dh.views.DataHierarchyView.java
License:Open Source License
static void expandViewer(final TreeViewer treeViewer) { final Runnable expand = new Runnable() { @Override/* ww w . j a v a2 s .c o m*/ public void run() { treeViewer.expandToLevel(2); } }; Display.getDefault().asyncExec(expand); }
From source file:de.stefanteitge.mtmx.workbench.ui.internal.view.GameExplorerView.java
License:Open Source License
private void createTree(Composite parent) { parent.setLayout(new FillLayout()); disposeChildren(parent);/*from w w w. jav a 2s . com*/ TreeViewer treeViewer = new TreeViewer(parent); treeViewer.setContentProvider(new TreeContentProvider()); treeViewer.setLabelProvider(new TreeLabelProvider()); treeViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { ISelection selection = event.getSelection(); openRequested(selection); } }); treeViewer.setInput(GameProvider.getInstance().getGameDirs()); treeViewer.expandToLevel(2); getSite().setSelectionProvider(treeViewer); parent.layout(); }
From source file:de.walware.statet.r.internal.ui.dataeditor.RDataEditorOutlinePage.java
License:Open Source License
@Override protected void init() { super.init(); fEditor.getRDataTable().addTableListener(new IRDataTableListener() { @Override/*from ww w . j a v a 2s . co m*/ public void inputChanged(final IRDataTableInput input, final RDataTableContentDescription description) { final boolean isNew = (description != null && (fDescription == null || fDescription.getVariables().length != description.getVariables().length)); fDescription = description; final TreeViewer viewer = getViewer(); if (UIAccess.isOkToUse(viewer)) { viewer.refresh(); if (isNew && fDescription != null) { // viewer.setExpandedTreePaths(new TreePath[] { new TreePath(new Object[] { fDescription }) }); viewer.expandToLevel(3); } } } }); }
From source file:es.cv.gvcase.emf.ui.common.dialogs.FeatureEditorDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite contents = (Composite) super.createDialogArea(parent); GridLayout contentsGridLayout = (GridLayout) contents.getLayout(); contentsGridLayout.numColumns = 3;/*from www. j a va 2s . com*/ GridData contentsGridData = (GridData) contents.getLayoutData(); contentsGridData.horizontalAlignment = SWT.FILL; contentsGridData.verticalAlignment = SWT.FILL; Text patternText = null; if (choiceOfValues != null) { Group filterGroupComposite = new Group(contents, SWT.NONE); filterGroupComposite.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_group")); filterGroupComposite.setLayout(new GridLayout(2, false)); filterGroupComposite.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 3, 1)); Label label = new Label(filterGroupComposite, SWT.NONE); label.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_pattern_label")); patternText = new Text(filterGroupComposite, SWT.BORDER); patternText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } Composite choiceComposite = new Composite(contents, SWT.NONE); { GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.horizontalAlignment = SWT.END; choiceComposite.setLayoutData(data); GridLayout layout = new GridLayout(); data.horizontalAlignment = SWT.FILL; layout.marginHeight = 0; layout.marginWidth = 0; layout.numColumns = 1; choiceComposite.setLayout(layout); } Label choiceLabel = new Label(choiceComposite, SWT.NONE); choiceLabel.setText(choiceOfValues == null ? EMFEditUIPlugin.INSTANCE.getString("_UI_Value_label") : EMFEditUIPlugin.INSTANCE.getString("_UI_Choices_label")); GridData choiceLabelGridData = new GridData(); choiceLabelGridData.verticalAlignment = SWT.FILL; choiceLabelGridData.horizontalAlignment = SWT.FILL; choiceLabel.setLayoutData(choiceLabelGridData); final Tree choiceTree = choiceOfValues == null ? null : new Tree(choiceComposite, SWT.MULTI | SWT.BORDER); if (choiceTree != null) { GridData choiceTtreeGridData = new GridData(); choiceTtreeGridData.widthHint = Display.getCurrent().getBounds().width / 5; choiceTtreeGridData.heightHint = Display.getCurrent().getBounds().height / 3; choiceTtreeGridData.verticalAlignment = SWT.FILL; choiceTtreeGridData.horizontalAlignment = SWT.FILL; choiceTtreeGridData.grabExcessHorizontalSpace = true; choiceTtreeGridData.grabExcessVerticalSpace = true; choiceTree.setLayoutData(choiceTtreeGridData); } final TreeViewer choiceTreeViewer = choiceOfValues == null ? null : new TreeViewer(choiceTree); if (choiceTreeViewer != null) { choiceTreeViewer.setContentProvider(contentProvider); choiceTreeViewer.setLabelProvider(labelProvider); final PatternFilter filter = new PatternFilter() { @Override protected boolean isParentMatch(Viewer viewer, Object element) { return viewer instanceof AbstractTreeViewer && super.isParentMatch(viewer, element); } }; choiceTreeViewer.addFilter(filter); assert patternText != null; patternText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { filter.setPattern(((Text) e.widget).getText()); choiceTreeViewer.refresh(); } }); choiceTreeViewer.setInput(choiceOfValues); choiceTreeViewer.expandToLevel(2); } // We use multi even for a single line because we want to respond to the // enter key. // int style = multiLine ? SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER : SWT.MULTI | SWT.BORDER; final Text choiceText = choiceOfValues == null ? new Text(choiceComposite, style) : null; if (choiceText != null) { GridData choiceTextGridData = new GridData(); choiceTextGridData.widthHint = Display.getCurrent().getBounds().width / 5; choiceTextGridData.verticalAlignment = SWT.BEGINNING; choiceTextGridData.horizontalAlignment = SWT.FILL; choiceTextGridData.grabExcessHorizontalSpace = true; if (multiLine) { choiceTextGridData.verticalAlignment = SWT.FILL; choiceTextGridData.grabExcessVerticalSpace = true; } choiceText.setLayoutData(choiceTextGridData); } Composite controlButtons = new Composite(contents, SWT.NONE); GridData controlButtonsGridData = new GridData(); controlButtonsGridData.verticalAlignment = SWT.FILL; controlButtonsGridData.horizontalAlignment = SWT.FILL; controlButtons.setLayoutData(controlButtonsGridData); GridLayout controlsButtonGridLayout = new GridLayout(); controlButtons.setLayout(controlsButtonGridLayout); new Label(controlButtons, SWT.NONE); final Button addButton = new Button(controlButtons, SWT.PUSH); addButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Add_label")); GridData addButtonGridData = new GridData(); addButtonGridData.verticalAlignment = SWT.FILL; addButtonGridData.horizontalAlignment = SWT.FILL; addButton.setLayoutData(addButtonGridData); final Button removeButton = new Button(controlButtons, SWT.PUSH); removeButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Remove_label")); GridData removeButtonGridData = new GridData(); removeButtonGridData.verticalAlignment = SWT.FILL; removeButtonGridData.horizontalAlignment = SWT.FILL; removeButton.setLayoutData(removeButtonGridData); Label spaceLabel = new Label(controlButtons, SWT.NONE); GridData spaceLabelGridData = new GridData(); spaceLabelGridData.verticalSpan = 2; spaceLabel.setLayoutData(spaceLabelGridData); final Button upButton = new Button(controlButtons, SWT.PUSH); upButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Up_label")); GridData upButtonGridData = new GridData(); upButtonGridData.verticalAlignment = SWT.FILL; upButtonGridData.horizontalAlignment = SWT.FILL; upButton.setLayoutData(upButtonGridData); final Button downButton = new Button(controlButtons, SWT.PUSH); downButton.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Down_label")); GridData downButtonGridData = new GridData(); downButtonGridData.verticalAlignment = SWT.FILL; downButtonGridData.horizontalAlignment = SWT.FILL; downButton.setLayoutData(downButtonGridData); Composite featureComposite = new Composite(contents, SWT.NONE); { GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.horizontalAlignment = SWT.END; featureComposite.setLayoutData(data); GridLayout layout = new GridLayout(); data.horizontalAlignment = SWT.FILL; layout.marginHeight = 0; layout.marginWidth = 0; layout.numColumns = 1; featureComposite.setLayout(layout); } Label featureLabel = new Label(featureComposite, SWT.NONE); featureLabel.setText(EMFEditUIPlugin.INSTANCE.getString("_UI_Feature_label")); GridData featureLabelGridData = new GridData(); featureLabelGridData.horizontalSpan = 2; featureLabelGridData.horizontalAlignment = SWT.FILL; featureLabelGridData.verticalAlignment = SWT.FILL; featureLabel.setLayoutData(featureLabelGridData); final Tree featureTree = new Tree(featureComposite, SWT.MULTI | SWT.BORDER); GridData featureTreeGridData = new GridData(); featureTreeGridData.widthHint = Display.getCurrent().getBounds().width / 5; featureTreeGridData.heightHint = Display.getCurrent().getBounds().height / 3; featureTreeGridData.verticalAlignment = SWT.FILL; featureTreeGridData.horizontalAlignment = SWT.FILL; featureTreeGridData.grabExcessHorizontalSpace = true; featureTreeGridData.grabExcessVerticalSpace = true; featureTree.setLayoutData(featureTreeGridData); final TreeViewer featureTreeViewer = new TreeViewer(featureTree); featureTreeViewer.setContentProvider(contentProvider); featureTreeViewer.setLabelProvider(labelProvider); if (values != null) { featureTreeViewer.setInput(values); if (!values.getChildren().isEmpty()) { featureTreeViewer.setSelection(new StructuredSelection(values.getChildren().get(0))); } } else { featureTreeViewer.setInput(currentValues); if (!currentValues.isEmpty()) { featureTreeViewer.setSelection(new StructuredSelection(currentValues.get(0))); } } featureTreeViewer.expandToLevel(2); if (choiceTreeViewer != null) { choiceTreeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (addButton.isEnabled()) { addButton.notifyListeners(SWT.Selection, null); } } }); featureTreeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (removeButton.isEnabled()) { removeButton.notifyListeners(SWT.Selection, null); } } }); } if (choiceText != null) { choiceText.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (!multiLine && (event.character == '\r' || event.character == '\n')) { try { Object value = EcoreUtil.createFromString((EDataType) eClassifier, choiceText.getText()); if (values != null) { values.getChildren().add(value); } else { currentValues.add(value); } choiceText.setText(""); featureTreeViewer.setSelection(new StructuredSelection(value)); event.doit = false; } catch (RuntimeException exception) { // Ignore } } else if (event.character == '\33') { choiceText.setText(""); event.doit = false; } } }); } upButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { IStructuredSelection selection = (IStructuredSelection) featureTreeViewer.getSelection(); int minIndex = 0; for (Iterator<?> i = selection.iterator(); i.hasNext();) { Object value = i.next(); if (values != null) { int index = values.getChildren().indexOf(value); values.getChildren().move(Math.max(index - 1, minIndex++), value); } else { int index = currentValues.indexOf(value); currentValues.remove(value); currentValues.add(Math.max(index - 1, minIndex++), value); } } featureTreeViewer.refresh(); featureTreeViewer.expandToLevel(2); featureTreeViewer.setSelection(selection); } }); downButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { IStructuredSelection selection = (IStructuredSelection) featureTreeViewer.getSelection(); int maxIndex = 0; if (values != null) { maxIndex = values.getChildren().size(); } else { maxIndex = currentValues.size(); } maxIndex = maxIndex - selection.size(); for (Iterator<?> i = selection.iterator(); i.hasNext();) { Object value = i.next(); if (values != null) { int index = values.getChildren().indexOf(value); values.getChildren().move(Math.min(index + 1, maxIndex++), value); } else { int index = currentValues.indexOf(value); currentValues.remove(value); currentValues.add(Math.min(index + 1, maxIndex++), value); } } featureTreeViewer.refresh(); featureTreeViewer.expandToLevel(2); featureTreeViewer.setSelection(selection); } }); addButton.addSelectionListener(new SelectionAdapter() { // event is null when choiceTableViewer is double clicked @Override public void widgetSelected(SelectionEvent event) { if (choiceTreeViewer != null) { IStructuredSelection selection = (IStructuredSelection) choiceTreeViewer.getSelection(); for (Iterator<?> i = selection.iterator(); i.hasNext();) { Object value = i.next(); if (!eClassifier.isInstance(value)) { continue; } if (values != null) { if (!values.getChildren().contains(value)) { values.getChildren().add(value); } } else { if (!currentValues.contains(value)) { currentValues.add(value); } } } featureTreeViewer.refresh(); featureTreeViewer.expandToLevel(2); featureTreeViewer.setSelection(selection); } else if (choiceText != null) { try { Object value = EcoreUtil.createFromString((EDataType) eClassifier, choiceText.getText()); if (values != null) { values.getChildren().add(value); } else { currentValues.add(value); } choiceText.setText(""); featureTreeViewer.refresh(value); featureTreeViewer.setSelection(new StructuredSelection(value)); } catch (RuntimeException exception) { // Ignore } } } }); removeButton.addSelectionListener(new SelectionAdapter() { // event is null when featureTableViewer is double clicked @Override public void widgetSelected(SelectionEvent event) { IStructuredSelection selection = (IStructuredSelection) featureTreeViewer.getSelection(); Object firstValue = null; for (Iterator<?> i = selection.iterator(); i.hasNext();) { Object value = i.next(); if (!eClassifier.isInstance(value)) { continue; } if (firstValue == null) { firstValue = value; } if (values != null) { values.getChildren().remove(value); } else { currentValues.remove(value); } } if (values != null) { if (!values.getChildren().isEmpty()) { featureTreeViewer.setSelection(new StructuredSelection(values.getChildren().get(0))); } } else { if (!currentValues.isEmpty()) { featureTreeViewer.setSelection(new StructuredSelection(currentValues.get(0))); } } if (choiceTreeViewer != null) { choiceTreeViewer.refresh(); choiceTreeViewer.expandToLevel(2); featureTreeViewer.refresh(); featureTreeViewer.expandToLevel(2); choiceTreeViewer.setSelection(selection); } else if (choiceText != null) { if (firstValue != null) { String value = EcoreUtil.convertToString((EDataType) eClassifier, firstValue); choiceText.setText(value); } } } }); return contents; }
From source file:gov.nasa.ensemble.core.activityDictionary.view.ActivityDictionaryView.java
License:Open Source License
@Override protected TreeViewer buildTreeViewer(Composite parent) { TreeViewer treeViewer = new ActivityDictionaryViewer(parent); treeViewer.setContentProvider(new ActivityDictionaryContentProvider()); treeViewer.setLabelProvider(new ViewLabelProvider()); treeViewer.setSorter(new NameSorter()); treeViewer.setInput(getViewSite());//from w ww . j a v a2 s . c o m treeViewer.expandToLevel(2); treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); treeViewer.getTree().setData("name", "ActivityDictionaryView.activityTree"); return treeViewer; }
From source file:gov.nasa.ensemble.core.plan.resources.ui.view.PlanProfileTreePage.java
License:Open Source License
@Override protected void configureTreeViewer(TreeViewer treeViewer) { super.configureTreeViewer(treeViewer); this.treeViewer = treeViewer; treeViewer.setContentProvider(new PlanProfileTreeContentProvider()); treeViewer.setInput(plan);/*from w w w . j ava2 s.com*/ treeViewer.expandToLevel(2); }
From source file:gov.nasa.ensemble.core.plan.resources.ui.view.ResourceTreeView.java
License:Open Source License
@Override protected TreeViewer buildTreeViewer(Composite parent) { TreeViewer treeViewer = new TreeViewer(parent, SWT.MULTI); treeViewer.addDragSupport(DND_OPERATIONS, TRANSFERS, new ResourceTreeDragSourceListener(treeViewer, null)); treeViewer.setContentProvider(new ResourceTreeContentProvider()); treeViewer.setLabelProvider(new DefLabelProvider()); treeViewer.setInput(getViewSite());/*from ww w . j a va 2 s . com*/ treeViewer.expandToLevel(2); treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); treeViewer.getTree().setData("name", "ResourceTreeView.resourceTree"); return treeViewer; }