Java Code Examples for org.eclipse.jface.viewers.TreeViewer

The following are top voted examples for showing how to use org.eclipse.jface.viewers.TreeViewer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: neoscada   File: ChartConfiguratorView.java   Source Code and License 8 votes vote down vote up
@Override
public void createPartControl ( final Composite parent )
{
    this.container = parent;
    createEditingDomain ();

    parent.setLayout ( new FillLayout () );
    this.viewer = new TreeViewer ( parent );
    this.viewer.setAutoExpandLevel ( 2 );

    this.viewer.setContentProvider ( new AdapterFactoryContentProvider ( this.factory ) );
    this.viewer.setLabelProvider ( new AdapterFactoryLabelProvider ( this.factory ) );

    createContextMenuFor ( this.viewer );

    new AdapterFactoryTreeEditor ( this.viewer.getTree (), this.factory );
    getViewSite ().setSelectionProvider ( this.viewer );

    attachSelectionService ();

    getViewSite ().getActionBars ().getMenuManager ().add ( new Separator ( "additions" ) );

    this.actionBarContributor.init ( getViewSite ().getActionBars () );
    this.actionBarContributor.setViewPart ( this );
}
 
Example 2
Project: bdf2   File: SelectClassPage.java   Source Code and License 7 votes vote down vote up
private void removeSelectedPackage(SelectionEvent e, TreeViewer treeViewer) {
	Tree tree = getTree(e);
	if (tree == null) {
		return;
	}
	TreeItem[] selection = tree.getSelection();
	if (selection != null && selection.length > 0) {
		for (TreeItem item : selection) {
			TreeItem parent = item.getParentItem();
			if (parent == null) {
				removePackage(item);
				updatePageComplete(tree);
			} else {
				alert("请选择要删除的包!");
			}
		}
	} else {
		alert("请选择要删除的包!");
	}
}
 
Example 3
Project: n4js   File: CustomElementSelectionForm.java   Source Code and License 6 votes vote down vote up
/**
 * Create the composite.
 */
public CustomElementSelectionForm(Composite parent, int style) {
	super(parent, style);
	setLayout(new GridLayout(2, false));

	treeViewer = new TreeViewer(this, SWT.BORDER);
	Tree tree = getTreeViewer().getTree();

	// Set a minimum height to prevent weird dialog dimensions
	tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).minSize(0, 200).create());

	elementLabel = new Label(this, SWT.NONE);
	elementLabel.setLayoutData(GridDataFactory.swtDefaults().create());
	elementLabel.setText("New Label");

	elementInput = new SuffixText(this, SWT.BORDER);// new Text(this, SWT.BORDER);
	elementInput.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
}
 
Example 4
Project: n4js   File: TreeViewerBuilder.java   Source Code and License 6 votes vote down vote up
@Override
protected TreeViewer createViewer(final Composite parent, final AbstractColumnLayout columnLayout,
		final int style) {
	final TreeViewer viewer = new TreeViewer(parent, virual ? (style | VIRTUAL) : style);
	final Tree tree = viewer.getTree();
	tree.setLinesVisible(linesVisible);
	tree.setHeaderVisible(headerVisible);

	int columnIndex = 0;
	for (final String columnLabel : columnLabels) {

		final TreeViewerColumn viewerColumn = new TreeViewerColumn(viewer, NONE);
		final TreeColumn column = viewerColumn.getColumn();
		columnLayout.setColumnData(column, createColumnLayoutData(columnIndex));
		column.setText(columnLabel);
		column.setMoveable(moveable);

		columnIndex++;
	}

	return viewer;
}
 
Example 5
Project: AgentWorkbench   File: ProjectEditor.java   Source Code and License 6 votes vote down vote up
/**
 * Create contents of the editor part.
 * @param parent
 */
@Override
@PostConstruct
public void createPartControl(Composite parent) {
	
	this.sashForm = new SashForm(parent, SWT.NONE);
	
	this.treeViewer = new TreeViewer(this.sashForm, SWT.BORDER);
	this.tree = this.treeViewer.getTree();
	
	this.tabFolder = new CTabFolder(this.sashForm, SWT.BORDER);
	this.tabFolder.setTabPosition(SWT.BOTTOM);
	this.tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
	
	this.tabItem = new CTabItem(this.tabFolder, SWT.NONE);
	this.tabItem.setText("New Item");
	
	this.tabItem_1 = new CTabItem(this.tabFolder, SWT.NONE);
	this.tabItem_1.setText("New Item");
													
	this.sashForm.setWeights(new int[] { 3, 10 });
	
}
 
Example 6
Project: eclipse-batch-editor   File: AbstractTreeViewerFilter.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 7
Project: neoscada   File: ItemListContentProvider.java   Source Code and License 6 votes vote down vote up
protected void performAdded ( final ListEntry[] entries )
{
    if ( this.viewer.getControl ().isDisposed () )
    {
        return;
    }

    if ( this.viewer instanceof TreeViewer )
    {
        ( (TreeViewer)this.viewer ).add ( this.data, entries );
    }
    else if ( this.viewer != null )
    {
        this.viewer.refresh ();
    }
}
 
Example 8
Project: neoscada   File: ItemListContentProvider.java   Source Code and License 6 votes vote down vote up
public void performRemoved ( final ListEntry[] entries )
{
    if ( this.viewer.getControl ().isDisposed () )
    {
        return;
    }

    if ( this.viewer instanceof TreeViewer )
    {
        ( (TreeViewer)this.viewer ).remove ( entries );
    }
    else if ( this.viewer != null )
    {
        this.viewer.refresh ();
    }
}
 
Example 9
Project: neoscada   File: ItemListContentProvider.java   Source Code and License 6 votes vote down vote up
public void performUpdated ( final ListEntry[] entries )
{
    if ( this.viewer.getControl ().isDisposed () )
    {
        return;
    }

    if ( this.viewer instanceof TreeViewer )
    {
        for ( final ListEntry entry : entries )
        {
            ( (TreeViewer)this.viewer ).refresh ( entry );
        }
        ( (TreeViewer)this.viewer ).update ( entries, null );
    }
    else if ( this.viewer != null )
    {
        this.viewer.refresh ();
    }
}
 
Example 10
Project: neoscada   File: ServersViewer.java   Source Code and License 6 votes vote down vote up
public ServersViewer ( final Composite parent )
{
    parent.setLayout ( new FillLayout () );
    this.viewer = new TreeViewer ( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL );

    this.contentProvider = new ObservableSetTreeContentProvider ( new ObservableFactoryImpl (), null );
    this.viewer.setContentProvider ( this.contentProvider );
    this.labelProvider = new ServerLabelProvider ( this.contentProvider.getKnownElements () );
    this.viewer.setLabelProvider ( this.labelProvider );

    this.viewer.setInput ( HivesPlugin.getDefault ().getServerManager () );
    this.viewer.getControl ().addDisposeListener ( new DisposeListener () {

        @Override
        public void widgetDisposed ( final DisposeEvent e )
        {
            handleDispose ();
        }
    } );

    ColumnViewerToolTipSupport.enableFor ( this.viewer );
}
 
Example 11
Project: convertigo-eclipse   File: PropertyTableTreeObject.java   Source Code and License 6 votes vote down vote up
protected synchronized void hasBeenModified() {
	if (isInherited()) return;
	
	XMLVector<XMLVector<Object>> xmlv = new XMLVector<XMLVector<Object>>();
	for(PropertyTableRowTreeObject rowTreeObject : getChildren()){
		XMLVector<Object> row = new XMLVector<Object>(rowTreeObject.getObject());
		xmlv.add(row);
	}
	data = xmlv;
	
	try {
		DatabaseObject databaseObject = databaseObjectTreeObject.getObject();
		java.beans.PropertyDescriptor databaseObjectPropertyDescriptor = databaseObjectTreeObject.getPropertyDescriptor(getObject());
        Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
        Object args[] = { data };
        setter.invoke(databaseObject, args);
        databaseObject.hasChanged = true;
        databaseObjectTreeObject.hasBeenModified(true);
	}
	catch (Exception e) {}
	
       TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
   	viewer.update(databaseObjectTreeObject, null);
	
}
 
Example 12
Project: convertigo-eclipse   File: DesignDocumentUpdateTreeObject.java   Source Code and License 6 votes vote down vote up
@Override
public boolean rename(String newName, Boolean bDialog) {
	if (getName().equals(newName))
		return true;
	
	IDesignTreeObject dto = getParentDesignTreeObject();
	if (((DesignDocumentTreeObject)dto).hasUpdate(newName)) {
		ConvertigoPlugin.logException(new ConvertigoException("The function named \"" + newName + "\" already exists."), "Unable to change the object name.", bDialog);
		return false;
	}
	
	getObject().setName(newName);
	hasBeenModified();
	
       TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
   	viewer.update(this, null);
	
	return true;
}
 
Example 13
Project: convertigo-eclipse   File: DesignDocumentViewTreeObject.java   Source Code and License 6 votes vote down vote up
public boolean rename(String newName, Boolean bDialog) {
	if (getName().equals(newName))
		return true;
	if (getParentDesignTreeObject().hasView(newName)) {
		ConvertigoPlugin.logException(new ConvertigoException("The view named \"" + newName + "\" already exists."), "Unable to change the object name.", bDialog);
		return false;
	}
	
	getObject().setName(newName);
	hasBeenModified();
	
       TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
   	viewer.update(this, null);
	
	return true;
}
 
Example 14
Project: convertigo-eclipse   File: DesignDocumentFilterTreeObject.java   Source Code and License 6 votes vote down vote up
@Override
public boolean rename(String newName, Boolean bDialog) {
	if (getName().equals(newName))
		return true;
	
	IDesignTreeObject dto = getParentDesignTreeObject();
	if (((DesignDocumentTreeObject)dto).hasFilter(newName)) {
		ConvertigoPlugin.logException(new ConvertigoException("The function named \"" + newName + "\" already exists."), "Unable to change the object name.", bDialog);
		return false;
	}
	
	getObject().setName(newName);
	hasBeenModified();
	
       TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
   	viewer.update(this, null);
	
	return true;
}
 
Example 15
Project: convertigo-eclipse   File: SequenceTreeObject.java   Source Code and License 6 votes vote down vote up
private void updateLoadedProjects() {
	TreeParent invisibleRoot = ((ViewContentProvider)((TreeViewer)viewer).getContentProvider()).getTreeRoot();
	Sequence sequence = getObject();
	
	Set<String> loadedProject = sequence.getLoadedProjectNames();
	
	for (TreeObject treeObject : invisibleRoot.getChildren()) {
		if (treeObject instanceof ProjectTreeObject) {
			Project project = ((ProjectTreeObject)treeObject).getObject();
			sequence.setLoadedProject(project);
		}
		else if (treeObject instanceof UnloadedProjectTreeObject) {
			sequence.removeLoaded(((UnloadedProjectTreeObject)treeObject).getName());
		}
		
		if (loadedProject.contains(treeObject.getName())) {
			loadedProject.remove(treeObject.getName());
		}
	}
	
	for (String projectName: loadedProject) {
		sequence.removeLoaded(projectName);
	}
}
 
Example 16
Project: scanning   File: ControlTreeViewer.java   Source Code and License 6 votes vote down vote up
private void createColumns(TreeViewer viewer) {

		viewer.setColumnProperties(new String[] { "Name", "Value"});
		ColumnViewerToolTipSupport.enableFor(viewer);

		TreeViewerColumn nameColumn = new TreeViewerColumn(viewer, SWT.LEFT, 0);
		nameColumn.getColumn().setText("Name");
		nameColumn.getColumn().setWidth(200);
		nameColumn.setLabelProvider(new ColumnLabelProvider() {
			@Override
			public String getText(Object element) {
				INamedNode node = (INamedNode)element;
				return node.getDisplayName();
			}
		});
		nameColumn.setEditingSupport(new NameEditingSupport(this));

		TreeViewerColumn valueColumn = new TreeViewerColumn(viewer, SWT.LEFT, 1);
		valueColumn.getColumn().setText("Value");
		valueColumn.getColumn().setWidth(300);
		valueColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(new ControlValueLabelProvider(cservice, this)));
		valueColumn.setEditingSupport(new ControlEditingSupport(viewer, cservice, controlViewerMode));
	}
 
Example 17
Project: eclipse-bash-editor   File: AbstractTreeViewerFilter.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 18
Project: gw4e.project   File: ModelSearchResultPage.java   Source Code and License 6 votes vote down vote up
/**
 * @wbp.parser.entryPoint
 */
@Override
public void createControl(Composite parent) {
	fRootControl = new Composite(parent, SWT.NULL);
	fRootControl.setLayout(new FillLayout(SWT.HORIZONTAL));

	 
	viewer = new TreeViewer(fRootControl, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
	viewer.setContentProvider(new ViewContentProvider());
	viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new ViewLabelProvider(createImageDescriptor())));
	viewer.addDoubleClickListener(new IDoubleClickListener () {

		@Override
		public void doubleClick(DoubleClickEvent evt) {
			TreeSelection sel = (TreeSelection) evt.getSelection();
			IFile file = (IFile) sel.getFirstElement();
			if (isModelFile(file)) {
				JDTManager.openEditor(file, "org.gw4e.eclipse.studio.editor.GW4EEditor", null);	
				return;
			}
			JDTManager.openEditor(file, null); 
		}
		
	});
	files = new ArrayList<IFile>();
}
 
Example 19
Project: Tarski   File: Startup.java   Source Code and License 6 votes vote down vote up
private void initContextualView(IEditorPart editor) {
  if (editor == null) {
    return;
  }
  IFile file = editor.getEditorInput().getAdapter(IFile.class);
  TreeViewer treeViewer = ContextualView.getTreeViewer();
  if (treeViewer != null) {
    // Finding all markers in given file.
    ArrayList<IMarker> allMarkers;
    allMarkers = MarkerFactory.findMarkersAsArrayList(file);
    if (allMarkers == null) {
      return;
    }
    Iterator<IMarker> iter = allMarkers.iterator();
    while (iter.hasNext()) {
      IMarker marker = iter.next();
      if (MarkUtilities.getLeaderId(marker) == null && MarkUtilities.getGroupId(marker) != null) {
        iter.remove();
      }
    }
    if (!treeViewer.getTree().isDisposed()) {
      treeViewer.setInput(allMarkers.toArray());
    }
    treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
  }
}
 
Example 20
Project: Tarski   File: ContainerSelectionPage.java   Source Code and License 6 votes vote down vote up
@Override
public void createControl(Composite parent) {
  Composite container = new Composite(parent, SWT.NONE);
  setControl(container);
  container.setLayout(new FillLayout(SWT.HORIZONTAL));

  treeViewer = new TreeViewer(container, SWT.BORDER);
  treeViewer.setUseHashlookup(true);
  treeViewer.setLabelProvider(new SigTypeLabelProvider());
  treeViewer.setContentProvider(new SigTypeContentProvider());
  treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot().getProjects());

  treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

    @Override
    public void selectionChanged(SelectionChangedEvent event) {
      if (((TreeSelection) event.getSelection()).getFirstElement() instanceof IMarker) {
        selection = event.getSelection();
        ContainerSelectionPage.this.setPageComplete(true);
      } else {
        ContainerSelectionPage.this.setPageComplete(false);
      }
    }
  });
}
 
Example 21
Project: Tarski   File: UntypedMarkerPage.java   Source Code and License 6 votes vote down vote up
@Override
public void createControl(Composite parent) {
  Composite container = new Composite(parent, SWT.NONE);
  this.setControl(container);
  container.setLayout(new FillLayout(SWT.HORIZONTAL));

  TreeViewer treeViewer = new TreeViewer(container, SWT.BORDER);
  treeViewer.setUseHashlookup(true);
  treeViewer.setLabelProvider(new CreatingAtomWizardLabelProvider());
  treeViewer.setContentProvider(new CreatingAtomWizardContentProvider());
  treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot().getProjects());
  treeViewer.setFilters(new ViewerFilter[] {new CreatingAtomWizardFilter()});

  treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

    @Override
    public void selectionChanged(SelectionChangedEvent event) {
      if (((TreeSelection) event.getSelection()).getFirstElement() instanceof IMarker) {
        UntypedMarkerPage.this.selection = event.getSelection();
        UntypedMarkerPage.this.setPageComplete(true);
      } else {
        UntypedMarkerPage.this.setPageComplete(false);
      }
    }
  });
}
 
Example 22
Project: bdf2   File: SelectClassPage.java   Source Code and License 6 votes vote down vote up
private void addPackage(TreeViewer treeViewer) {
	IJavaProject jProject = ProjectHelper.getCurrentJavaProject();
	if (jProject == null) {
		alertAndClose();
		return;
	}
	PackageSelectionDialog dialog = createPackageSelectionDialog(jProject);
	if (dialog.open() == IDialogConstants.OK_ID) {
		String packageName = getPackageName(dialog);
		if (nodeListManager.addNodesFromPackage(jProject, packageName,
				getFile(jProject, packageName).list())) {
			setTreeViewer(treeViewer);
			setPageComplete(false);
		}
	}
}
 
Example 23
Project: avro-schema-editor   File: UIUtils.java   Source Code and License 6 votes vote down vote up
public static void expandAll(final TreeViewer treeViewer, final String context) {
  	AvroSchemaLogger.logMsg(context + " BEGIN", false);
  	BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {				
	@Override
	public void run() {
		long time1 = System.currentTimeMillis();				
		try {		
			treeViewer.getTree().setRedraw(false);
			treeViewer.expandAll();
		} finally {
			treeViewer.getTree().setRedraw(true);
			long time2 = System.currentTimeMillis();
			long delay = time2 - time1;
			AvroSchemaLogger.logMsg(context + " END : " + delay + " ms", false);
		}
	}
});
  }
 
Example 24
Project: avro-schema-editor   File: UIUtils.java   Source Code and License 6 votes vote down vote up
public static void run(final TreeViewer treeViewer, final Runnable runnable, final String context) {
  	AvroSchemaLogger.logMsg(context + " BEGIN", false);
  	BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {				
	@Override
	public void run() {
		long time1 = System.currentTimeMillis();				
		try {					
			treeViewer.getTree().setRedraw(false);
			runnable.run();
		} finally {
			treeViewer.getTree().setRedraw(true);
			long time2 = System.currentTimeMillis();
			long delay = time2 - time1;
			AvroSchemaLogger.logMsg(context + " END : " + delay + " ms", false);
		}
	}
});
  }
 
Example 25
Project: avro-schema-editor   File: CountTreeItemsHandler.java   Source Code and License 6 votes vote down vote up
protected void computeAndDisplayStats(AvroSchemaEditor editor) {
	
	SchemaViewer masterViewer = editor.getContentPart().getSchemaViewer(AvroContext.Kind.MASTER);
	TreeViewer treeViewer = masterViewer.getTreeViewer();
	AvroNode inputNode = (AvroNode) treeViewer.getInput();
	NodeType inputType = inputNode.getType();
	String name = AttributeUtil.getNameFromAttribute(inputNode);
	
	NodeStats stats = new NodeStats("Compute stats of " + inputType.toString().toLowerCase() 
			+ " " + name + " from editor " + editor.getName());
	stats.start();
	
	Tree tree = treeViewer.getTree();
	
	TreeItem[] items = tree.getItems();
	for (TreeItem item : items) {
		visitTreeItem(item, stats);
	}
	
	stats.finish();
	AvroSchemaLogger.logStats(stats, false);
	
}
 
Example 26
Project: avro-schema-editor   File: SchemaViewer.java   Source Code and License 6 votes vote down vote up
protected void configureDragAndDrop(DragAndDropConfiguration dragAndDropConfiguration, TreeViewer treeViewer) {

      // drop
      Transfer[] transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };
      int operations = dragAndDropConfiguration.getSupportedDropOperations(this);
      
      DropTarget target = new DropTarget(treeViewer.getControl(), operations);
      target.setTransfer(transferTypes);

      // Drop listeners pour le drop des elements sur l'arbre
      SchemaViewerDropPolicy dropPolicy = dragAndDropConfiguration.getDropPolicy(this);
      DnDTargetListener targetListener = new DnDTargetListener(this, nodeConverter, dropPolicy);
      target.addDropListener(targetListener);

      // Drag listener pour le drag des elements de l'arbre
      DragSourceListener sourceListener = new DnDSourceListener(this);
      operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT;
      transferTypes = new Transfer[] { LocalSelectionTransfer.getTransfer() };
      treeViewer.addDragSupport(operations, transferTypes, sourceListener);
      
  }
 
Example 27
Project: n4js   File: AbstractOutlineWorkbenchTest.java   Source Code and License 5 votes vote down vote up
protected void assertExpanded(TreeViewer aTreeViewer, IOutlineNode... expectedExpansion) {
	Object[] expandedElements = aTreeViewer.getExpandedElements();
	assertEquals(expectedExpansion.length, expandedElements.length);
	OUTER: for (Object expandedObject : expandedElements) {
		assertTrue(expandedObject instanceof IOutlineNode);
		for (IOutlineNode expectedExpanded : expectedExpansion) {
			if (nodeComparer.equals((IOutlineNode) expandedObject, expectedExpanded))
				continue OUTER;
		}
		fail("Unexpected expansion" + expandedObject.toString());
	}
}
 
Example 28
Project: n4js   File: AbstractOutlineWorkbenchTest.java   Source Code and License 5 votes vote down vote up
protected void assertSelected(TreeViewer aTreeViewer, IOutlineNode... expectedSelection) {
	ISelection selection = aTreeViewer.getSelection();
	assertTrue(selection instanceof IStructuredSelection);
	assertEquals(expectedSelection.length, ((IStructuredSelection) selection).size());
	OUTER: for (Iterator<?> i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
		Object selectedObject = i.next();
		assertTrue(selectedObject instanceof IOutlineNode);
		for (IOutlineNode expectedSelected : expectedSelection) {
			if (nodeComparer.equals((IOutlineNode) selectedObject, expectedSelected))
				continue OUTER;
		}
		fail("Unexpected selection " + selectedObject.toString());
	}
}
 
Example 29
Project: n4js   File: CustomElementSelectionDialog.java   Source Code and License 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	CustomElementSelectionForm form = new CustomElementSelectionForm(parent, SWT.FILL);
	form.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	TreeViewer v = form.getTreeViewer();
	for (ViewerFilter filter : filters) {
		v.addFilter(filter);
	}
	this.treeViewer = v;

	WorkbenchContentProvider contentProvider = new WorkbenchContentProvider();
	ILabelProvider labelProvider = new WorkbenchLabelProvider();

	this.treeViewer.setContentProvider(contentProvider);
	this.treeViewer.setLabelProvider(labelProvider);

	this.treeViewer.setComparator(new ViewerComparator());

	this.treeViewer.setAutoExpandLevel(this.getAutoExpandLevel());

	form.setElementLabel(this.elementLabel);

	this.elementNameInput = form.getElementInput();

	form.getElementInput().addPropertyChangeListener(new PropertyChangeListener() {

		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			if (evt.getPropertyName().equals(SuffixText.TEXT_PROPERTY) ||
					evt.getPropertyName().equals(SuffixText.SUFFIX_PROPERTY)) {
				validateElementInput();
				elementInputChanged();
			}

		}
	});
	return form;
}
 
Example 30
Project: n4js   File: ExternalLibraryPreferencePage.java   Source Code and License 5 votes vote down vote up
private static void updateInput(final TreeViewer viewer, final Object input) {
	UIUtils.getDisplay().asyncExec(() -> {
		final Object[] expandedElements = viewer.getExpandedElements();
		final TreePath[] expandedTreePaths = viewer.getExpandedTreePaths();
		viewer.setInput(input);
		viewer.getControl().notifyListeners(Selection, null);
		if (!Arrays2.isEmpty(expandedElements)) {
			viewer.setExpandedElements(expandedElements);
		}
		if (!Arrays2.isEmpty(expandedTreePaths)) {
			viewer.setExpandedTreePaths(expandedTreePaths);
		}
	});
}
 
Example 31
Project: n4js   File: ExternalLibraryTreeContentProvider.java   Source Code and License 5 votes vote down vote up
@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
	if (viewer instanceof TreeViewer) {
		this.treeViewerRef = Optional.of((TreeViewer) viewer);
	} else {
		this.treeViewerRef = Optional.absent();
	}
}
 
Example 32
Project: n4js   File: ExternalLibraryTreeContentProvider.java   Source Code and License 5 votes vote down vote up
@Override
public void updateChildCount(final Object element, final int currentChildCount) {
	if (treeViewerRef.isPresent()) {
		final TreeViewer treeViewer = treeViewerRef.get();
		if (element instanceof Iterable) {
			treeViewer.setChildCount(element, Iterables.size((Iterable<?>) element));
		} else if (element instanceof URI) {
			treeViewer.setChildCount(element, Iterables.size(getProjects((URI) element)));
		} else {
			treeViewer.setChildCount(element, 0);
		}
	}
}
 
Example 33
Project: gemoc-studio-modeldebugging   File: EnginesStatusView.java   Source Code and License 5 votes vote down vote up
/**
	 * This is a callback that will allow us
	 * to create the viewer and initialize it.
	 */
	public void createPartControl(Composite parent) {
		_viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
		_contentProvider = new ViewContentProvider();
		_viewer.setContentProvider(_contentProvider);
		ColumnViewerToolTipSupport.enableFor(_viewer);
		_viewer.addSelectionChangedListener(
				new ISelectionChangedListener() {
					public void selectionChanged(SelectionChangedEvent event) {
						fireEngineSelectionChanged();
					}
				});
		
		createColumns();
//		_viewer.setColumnProperties( new String[] {"Status", "Identifier", "Step", "Status"} );
//		_viewer.getTree().setHeaderVisible(true);
		Font mono = JFaceResources.getFont(JFaceResources.TEXT_FONT);
		_viewer.getTree().setFont(mono);
		
		// Create the help context id for the viewer's control
		PlatformUI.getWorkbench().getHelpSystem().setHelp(_viewer.getControl(), "org.eclipse.gemoc.executionframework.ui.views.engine.EngineStatusView");
			
		// register for changes in the RunningEngineRegistry
		//org.eclipse.gemoc.executionframework.engine.Activator.getDefault().gemocRunningEngineRegistry.addObserver(this);
		
		buildMenu();		

		org.eclipse.gemoc.executionframework.engine.Activator.getDefault().gemocRunningEngineRegistry.addEngineRegistrationListener(this);
	}
 
Example 34
Project: eclipse-batch-editor   File: BatchEditorContentOutlinePage.java   Source Code and License 5 votes vote down vote up
public void createControl(Composite parent) {
	super.createControl(parent);

	labelProvider = new BatchEditorOutlineLabelProvider();

	TreeViewer viewer = getTreeViewer();
	viewer.setContentProvider(contentProvider);
	viewer.addDoubleClickListener(this);
	viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(labelProvider));
	viewer.addSelectionChangedListener(this);

	/* it can happen that input is already updated before control created */
	if (input != null) {
		viewer.setInput(input);
	}
	toggleLinkingAction = new ToggleLinkingAction();
	toggleLinkingAction.setActionDefinitionId(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR);
	
	IActionBars actionBars = getSite().getActionBars();
	
	IToolBarManager toolBarManager = actionBars.getToolBarManager();
	toolBarManager.add(toggleLinkingAction);
	
	IMenuManager viewMenuManager = actionBars.getMenuManager();
	viewMenuManager.add(new Separator("EndFilterGroup")); //$NON-NLS-1$

	viewMenuManager.add(new Separator("treeGroup")); //$NON-NLS-1$
	viewMenuManager.add(toggleLinkingAction);
	
	
	/*
	 * when no input is set on init state - let the editor rebuild outline
	 * (async)
	 */
	if (input == null && editor != null) {
		editor.rebuildOutline();
	}

}
 
Example 35
Project: eclipse-batch-editor   File: BatchEditorContentOutlinePage.java   Source Code and License 5 votes vote down vote up
public void rebuild(BatchScriptModel model) {
	if (model == null) {
		return;
	}
	contentProvider.rebuildTree(model);

	TreeViewer treeViewer = getTreeViewer();
	if (treeViewer != null) {
		Control control = treeViewer.getControl();
		if (control == null || control.isDisposed()){
			return;
		}
		treeViewer.setInput(model);
	}
}
 
Example 36
Project: eclipse-batch-editor   File: AbstractTreeViewerFilter.java   Source Code and License 5 votes vote down vote up
private boolean hasUnfilteredChild(TreeViewer viewer, TreePath parentPath, Object element) {
	TreePath elementPath = parentPath.createChildPath(element);
	IContentProvider contentProvider = viewer.getContentProvider();
	Object[] children = contentProvider instanceof ITreePathContentProvider
			? ((ITreePathContentProvider) contentProvider).getChildren(elementPath)
			: ((ITreeContentProvider) contentProvider).getChildren(element);

	/* avoid NPE + guard close */
	if (children == null || children.length == 0) {
		return false;
	}
	for (int i = 0; i < children.length; i++) {
		if (selectTreePath(viewer, elementPath, children[i])) {
			return true;
		}
	}
	return false;
}
 
Example 37
Project: neoscada   File: TreeNodeLabelProvider.java   Source Code and License 5 votes vote down vote up
public TreeNodeLabelProvider ( final TreeViewer viewer, final IObservableMap... attributeMaps )
{
    super ( attributeMaps );
    this.viewer = viewer;

    this.defaultFont = viewer.getControl ().getFont ();

    final FontData[] fds = this.viewer.getControl ().getFont ().getFontData ();
    for ( final FontData fd : fds )
    {
        fd.setStyle ( SWT.ITALIC );
    }
    this.font = new Font ( this.viewer.getControl ().getDisplay (), fds );
}
 
Example 38
Project: neoscada   File: MainEntryPoint.java   Source Code and License 5 votes vote down vote up
private Composite createMenu ( final Composite parent )
{
    final Composite menu = new Composite ( parent, SWT.NONE );

    menu.setLayout ( new FillLayout () );

    this.viewer = new TreeViewer ( menu, SWT.FULL_SELECTION );

    this.treeContentProvider = new ObservableListTreeContentProvider ( new FactoryImpl (), null );
    this.viewer.setContentProvider ( this.treeContentProvider );

    this.viewer.setLabelProvider ( new TreeNodeLabelProvider ( this.viewer,
            BeansObservables.observeMap ( this.treeContentProvider.getRealizedElements (), TreeNode.PROP_NAME ),
            BeansObservables.observeMap ( this.treeContentProvider.getRealizedElements (), TreeNode.PROP_PROVIDER_SET )
            ) );

    this.viewer.setInput ( this.manager.getRootNode () );

    this.viewer.addSelectionChangedListener ( new ISelectionChangedListener () {

        @Override
        public void selectionChanged ( final SelectionChangedEvent event )
        {
            handleSelectionChanged ( event );
        }
    } );

    this.viewer.setAutoExpandLevel ( 2 );

    return menu;
}
 
Example 39
Project: neoscada   File: KeyTreeViewer.java   Source Code and License 5 votes vote down vote up
public KeyTreeViewer ( final Composite parent )
{
    this.resourceManager = new LocalResourceManager ( JFaceResources.getResources ( parent.getDisplay () ), parent );

    this.viewer = new TreeViewer ( parent );
    this.viewer.getControl ().setLayoutData ( new GridData ( SWT.FILL, SWT.FILL, true, true ) );

    this.viewer.setAutoExpandLevel ( AbstractTreeViewer.ALL_LEVELS );

    this.contentProvider = new ObservableListTreeContentProvider ( new FactoryImpl (), null );
    this.viewer.setContentProvider ( this.contentProvider );
    this.viewer.setLabelProvider ( this.labelProvider = new LabelProviderImpl ( this.resourceManager, this.contentProvider.getRealizedElements () ) );
}
 
Example 40
Project: neoscada   File: LazyDiffEntryTreeProvider.java   Source Code and License 5 votes vote down vote up
@Override
public void inputChanged ( final Viewer viewer, final Object oldInput, final Object newInput )
{
    this.input = newInput;
    if ( viewer instanceof TreeViewer )
    {
        this.viewer = (TreeViewer)viewer;
    }
    else
    {
        this.viewer = null;
    }
}