Java Code Examples for org.eclipse.jface.viewers.TreeViewer#addSelectionChangedListener()

The following examples show how to use org.eclipse.jface.viewers.TreeViewer#addSelectionChangedListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MSyncWizardOverviewPage.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
  public void createControl(Composite parent) {
  	
      container = new Composite(parent, SWT.NONE);
      GridLayout layout = new GridLayout();
      container.setLayout(layout);
      // required to avoid an error in the system
      setControl(container);
      
      treeViewer = new TreeViewer(container, SWT.BORDER);
      treeViewer.setContentProvider(new TreeContentProvider());
      treeViewer.setLabelProvider(new MendeleyTreeLabelProvider());
      
      Tree tree = treeViewer.getTree();
      tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
      
      container.setEnabled(true);
      treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
	
	@Override
	public void selectionChanged(SelectionChangedEvent event) {
		treeViewer.getTree().deselect(treeViewer.getTree().getSelection()[0]);
	}
});
      
  }
 
Example 2
Source File: ActorMappingConfigurationWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void createMappingTree(final Composite listComposite) {
    mappingTree = new TreeViewer(listComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL);
    mappingTree.getTree().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    mappingTree.setContentProvider(new AdapterFactoryContentProvider(adapterFactory) {

        @Override
        public Object[] getElements(final Object object) {
            if (object instanceof Collection) {
                return ((Collection) object).toArray();
            }
            return super.getElements(object);
        }
    });
    mappingTree.setLabelProvider(new ActorMappingStyledTreeLabelProvider(adapterFactory, deployedOrganization));
    mappingTree.addSelectionChangedListener(this);
    mappingTree.addDoubleClickListener(this);
    mappingTree.addFilter(new ViewerFilter() {

        @Override
        public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
            return (element instanceof String || element instanceof MembershipType)
                    || ((ITreeContentProvider) mappingTree.getContentProvider()).hasChildren(element);
        }
    });
}
 
Example 3
Source File: SelectRegisteredTemplatePage.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void createControl(Composite parent) {
    final Composite container = new Composite(parent, parent.getStyle());
    setControl(container);
    container.setLayout(new FillLayout(SWT.HORIZONTAL | SWT.VERTICAL));

    final TreeViewer templatesTreeViewer = new TreeViewer(container, SWT.BORDER);
    templatesTreeViewer.setContentProvider(new CollectionContentProvider());
    templatesTreeViewer.setLabelProvider(new ColumnLabelProvider());
    final List<String> registeredTemplates = new ArrayList<>(TemplateRegistry.INSTANCE.getTemplates().keySet());
    Collections.sort(registeredTemplates);
    templatesTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            setSelectedTemplateURI(TemplateRegistry.INSTANCE.getTemplates()
                    .get(((IStructuredSelection) event.getSelection()).getFirstElement()));
            setPageComplete(selectedTemplateURI != null);
        }
    });
    templatesTreeViewer.setInput(registeredTemplates);
    setPageComplete(selectedTemplateURI != null);
}
 
Example 4
Source File: ChangeTypeWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tree-viewer that shows the allowable types in a tree view.
 * @param parent the parent
 */
private void addTreeComponent(Composite parent) {
	fTreeViewer= new TreeViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	
	GridData gd= new GridData(GridData.FILL_BOTH);
	gd.grabExcessHorizontalSpace= true;
	gd.grabExcessVerticalSpace= true;
	Tree tree= fTreeViewer.getTree();
	Dialog.applyDialogFont(tree);
	gd.heightHint= tree.getItemHeight() * 12;
	tree.setLayoutData(gd);

	fTreeViewer.setContentProvider(new ChangeTypeContentProvider(((ChangeTypeRefactoring)getRefactoring())));
	fLabelProvider= new ChangeTypeLabelProvider();
	fTreeViewer.setLabelProvider(fLabelProvider);
	ISelectionChangedListener listener= new ISelectionChangedListener(){
		public void selectionChanged(SelectionChangedEvent event) {
			IStructuredSelection selection= (IStructuredSelection)event.getSelection();
			typeSelected((ITypeBinding)selection.getFirstElement());
		}
	};
	fTreeViewer.addSelectionChangedListener(listener);
	fTreeViewer.setInput(new ChangeTypeContentProvider.RootType(getGeneralizeTypeRefactoring().getOriginalType()));
	fTreeViewer.expandToLevel(10);
}
 
Example 5
Source File: AbstractSelectTreeViewer2.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param parent
 *            Parent composite
 * @param checkboxTree
 *            <code>TriStateFilteredTree</code> wrapping a
 *            <code>CheckboxTreeViewer</code>
 * @param legendColumnIndex
 *            index of the legend column (-1 if none)
 */
private AbstractSelectTreeViewer2(Composite parent, TriStateFilteredCheckboxTree checkboxTree,
        int legendIndex, String id) {
    super(parent, checkboxTree.getViewer());

    TreeViewer treeViewer = checkboxTree.getViewer();
    treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    treeViewer.setComparator(COMPARATOR);
    if (treeViewer instanceof CheckboxTreeViewer) {
        ((CheckboxTreeViewer) treeViewer).addCheckStateListener(new CheckStateChangedListener());
    }
    treeViewer.addSelectionChangedListener(new TreeViewerSelectionListener());
    checkboxTree.getFilterControl().addModifyListener(e -> saveViewContext());
    fCheckboxTree = checkboxTree;
    fLegendIndex = legendIndex;
    fId = id;
    fLogCategory = fId + LOG_CATEGORY_SUFFIX;
    fInstanceId = INSTANCE_ID_SEQUENCE.incrementAndGet();
    setLabelProvider(new DataProviderTreeLabelProvider());
}
 
Example 6
Source File: DiagramPartitioningBreadcrumbViewer.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected TreeViewer createProjectStatechartViewer(Composite composite, Diagram diagram) {
	TreeViewer viewer = new TreeViewer(composite);
	viewer.setLabelProvider(new StatechartLabelProvider());
	viewer.setContentProvider(new StatechartContentProvider());
	viewer.setInput(getProjectStatechartInput(diagram));
	viewer.addSelectionChangedListener(this);
	return viewer;
}
 
Example 7
Source File: JsonContentOutlinePage.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void createControl(Composite parent) {
    super.createControl(parent);

    TreeViewer viewer = getTreeViewer();
    viewer.setContentProvider(new OutlineContentProvider());
    viewer.setLabelProvider(new OutlineStyledLabelProvider());
    viewer.addSelectionChangedListener(this);
    viewer.setAutoExpandLevel(2);
    viewer.setUseHashlookup(true);

    if (currentInput != null) {
        setInput(currentInput);
    }
}
 
Example 8
Source File: TreeNavigationView.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public TreeNavigationView(Composite parent, int style) {
  super(parent, style);
  setLayout(new FillLayout(SWT.VERTICAL));

  sashForm = new SashForm(this, SWT.HORIZONTAL);
  contentTypes = new TreeViewer(sashForm);
  contentTypes.addSelectionChangedListener(new ISelectionChangedListener() {
    public void selectionChanged(SelectionChangedEvent event) {
      fireSelectionChangedEvent(event);
      
      Object contentPanelSelection = null;
      ISelection selection = contentTypes.getSelection();
      if (selection != null && !selection.isEmpty()) {
        contentPanelSelection = ((ITreeSelection) selection).getFirstElement();
      }
      
      contentPanel.setSelection(contentPanelSelection);
    }
  });
  
  contentPanel = new ContentPanel(sashForm, SWT.NONE);

  contentTypes.setComparator(new ModelNodeViewerComparator());
  sashForm.setWeights(new int[] {20, 80});
  contentTypes.setLabelProvider(new ModelLabelProvider());
  contentTypes.setContentProvider(new TreeContentProvider());
  contentTypes.getTree().addKeyListener(
      new EnterKeyTreeToggleKeyAdapter(contentTypes));
}
 
Example 9
Source File: CubeGroupContent.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void createDataField( )
{
	Composite dataField = new Composite( this, SWT.NONE );
	dataField.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	dataField.setLayout( new GridLayout( ) );

	Label dataLabel = new Label( dataField, SWT.NONE );
	dataLabel.setText( Messages.getString( "GroupsPage.Label.DataField" ) ); //$NON-NLS-1$
	dataFieldsViewer = new TreeViewer( dataField, SWT.SINGLE
			| SWT.H_SCROLL
			| SWT.V_SCROLL
			| SWT.BORDER );
	cubeLabelProvider = getCubeLabelProvider( );
	cubeLabelProvider.setProivderViewer( true );
	dataFieldsViewer.setLabelProvider( cubeLabelProvider );
	dataFieldsViewer.setContentProvider( dataContentProvider );
	dataFieldsViewer.setAutoExpandLevel( 3 );
	GridData gd = new GridData( GridData.FILL_BOTH );
	dataFieldsViewer.getTree( ).setLayoutData( gd );
	( (GridData) dataFieldsViewer.getTree( ).getLayoutData( ) ).heightHint = 250;
	( (GridData) dataFieldsViewer.getTree( ).getLayoutData( ) ).widthHint = 200;
	dataFieldsViewer.addSelectionChangedListener( new ISelectionChangedListener( ) {

		public void selectionChanged( SelectionChangedEvent event )
		{
			updateButtons( );
		}

	} );

	final DragSource fieldsSource = new DragSource( dataFieldsViewer.getTree( ),
			operations );
	fieldsSource.setTransfer( types );
	fieldsSource.addDragListener( new CustomDragListener( dataFieldsViewer ) );

}
 
Example 10
Source File: M2DocTypeSelectionDialog.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createCustomArea(Composite parent) {
    final Composite container = new Composite(parent, parent.getStyle());
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    final FilteredTree filteredTree = new FilteredTree(container, SWT.BORDER, new PatternFilter(), true);
    final TreeViewer treeViewer = filteredTree.getViewer();
    final Tree tree = treeViewer.getTree();
    final GridData gdTable = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gdTable.minimumWidth = TABLE_MINIMUM_WIDTH;
    gdTable.minimumHeight = TABLE_MINIMUM_HEIGHT;
    tree.setLayoutData(gdTable);
    treeViewer.setContentProvider(new CollectionContentProvider());
    treeViewer.setLabelProvider(new LabelProvider());
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            final Object selected = ((IStructuredSelection) event.getSelection()).getFirstElement();
            selectedType = (String) selected;
        }
    });
    treeViewer.setInput(getAvailableTypes(nsURIs));
    if (defaultType != null) {
        treeViewer.setSelection(new StructuredSelection(defaultType));
    }

    return container;
}
 
Example 11
Source File: M2DocFileSelectionDialog.java    From M2Doc with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Control createCustomArea(Composite parent) {
    final Composite container = new Composite(parent, parent.getStyle());
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    fileText = createFilePathComposite(container, defaultFileName);

    final TreeViewer containerTreeViewer = new TreeViewer(container, SWT.BORDER);
    Tree tree = containerTreeViewer.getTree();
    final GridData gdTable = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gdTable.minimumWidth = TABLE_MINIMUM_WIDTH;
    gdTable.minimumHeight = TABLE_MINIMUM_HEIGHT;
    tree.setLayoutData(gdTable);
    containerTreeViewer.setContentProvider(new WorkbenchContentProvider() {
        @Override
        public Object[] getChildren(Object element) {
            final List<Object> res = new ArrayList<>();
            for (Object obj : super.getChildren(element)) {
                if (obj instanceof IContainer
                    || (obj instanceof IFile && fileExtension.equals(((IFile) obj).getFileExtension()))) {
                    res.add(obj);
                }
            }
            return res.toArray();
        }
    });
    containerTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
    containerTreeViewer.addSelectionChangedListener(new ContainerSelectionChangedListener());
    containerTreeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    if (defaultFileName != null && !defaultFileName.isEmpty()) {
        final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(defaultFileName));
        containerTreeViewer.setSelection(new StructuredSelection(file));
    }

    return container;
}
 
Example 12
Source File: XPathOperatorEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Composite createOpeartorEditor(Composite parent,final Operator operator,final Expression sourceExpression) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true,true).create()) ;
    composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 5).create());

    final XMLData data = (XMLData) sourceExpression.getReferencedElements().get(0) ;
    String namespace = data.getNamespace() ;
    String element = data.getType();
    XSDRepositoryStore xsdStore = (XSDRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(XSDRepositoryStore.class) ;

    XSDElementDeclaration root = xsdStore.findElementDeclaration(namespace, element);
    final XSDContentProvider provider =   new XSDContentProvider(true) ;
    provider.setElement(root);

    xsdViewer = new TreeViewer(composite);
    xsdViewer.setContentProvider(provider);
    XSDLabelProvider labelProvider = new XSDLabelProvider();
    xsdViewer.setLabelProvider(new DecoratingLabelProvider(labelProvider, labelProvider));
    xsdViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 200).create());
    xsdViewer.setInput(new Object());

    String content = operator.getExpression() ;
    if(content == null){
        content = "" ;
    }
    xsdViewer.setSelection(new StructuredSelection(createTreePath(content, provider)));

    xpathText = new Text(composite, SWT.WRAP | SWT.BORDER);
    xpathText.setLayoutData(GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 40).grab(true, false).create());
    xpathText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            operator.setExpression(xpathText.getText()) ;
        }
    });


    xsdViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ITreeSelection selection = (ITreeSelection) xsdViewer.getSelection();
            String xpath = computeXPath(selection, false);
            if(xpath == null || xpath.isEmpty()){
                xpathText.setText(data.getName());
            }else{
                xpathText.setText(xpath);
            }

            xpathText.redraw();
            fireSelectionChange(event) ;
        }
    });
    return composite ;
}
 
Example 13
Source File: JavaExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createBrowseJavaObjectForReadExpression(final Composite composite) {
    final Composite res = new Composite(composite, SWT.NONE);
    res.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    res.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).spacing(LayoutConstants.getSpacing().x, 0).create());

    final Label label = new Label(res, SWT.NONE);
    label.setText(Messages.browseJava);
    javaTreeviewer = new TreeViewer(res, SWT.SINGLE | SWT.BORDER);
    javaTreeviewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    javaTreeviewer.setLabelProvider(new JavaUILabelProvider() {

        @Override
        public String getText(final Object item) {
            if (item instanceof IMethod) {
                try {
                    return super.getText(item) + " - " + toQualifiedName(item);
                } catch (final JavaModelException e) {
                    BonitaStudioLog.error(e);
                    return null;
                }
            } else {
                return super.getText(item);
            }
        }

    });

    javaTreeviewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ITreeSelection selection = (ITreeSelection) event.getSelection();
            if (!selection.isEmpty()) {
                JavaExpressionEditor.this.fireSelectionChanged();
                javaTreeviewer.getTree().setFocus();
            }
        }

    });

    javaTreeviewer.getTree().setEnabled(false);
}
 
Example 14
Source File: FilterViewer.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
public FilterViewer(Composite parent, int style, boolean isDialog) {
    super(parent, style);

    this.fIsDialog = isDialog;

    setLayout(new FillLayout());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    setLayoutData(gd);

    final SashForm sash = new SashForm(this, SWT.HORIZONTAL);

    // Create the tree viewer to display the filter tree
    fViewer = new TreeViewer(sash, SWT.NONE);
    fViewer.setContentProvider(new FilterTreeContentProvider());
    fViewer.setLabelProvider(new FilterTreeLabelProvider());

    // Create the empty filter node properties panel
    fComposite = new Composite(sash, SWT.NONE);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    fComposite.setLayout(gl);

    createContextMenu();

    fViewer.addSelectionChangedListener(event -> {
        if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) {
            // Update the filter node properties panel to the selection
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            ITmfFilterTreeNode node = (ITmfFilterTreeNode) selection.getFirstElement();
            updateFilterNodeComposite(node);
        } else {
            updateFilterNodeComposite(null);
        }
    });

    fViewer.getTree().addPaintListener(e -> {
        TmfFilterTreeNode root = (TmfFilterTreeNode) fViewer.getInput();
        if (root == null || root.getChildrenCount() == 0) {
            e.gc.setForeground(FOREGROUND_COLOR);
            e.gc.drawText(Messages.FilterViewer_EmptyTreeHintText, 5, 0);
        }
    });

    int operations = DND.DROP_MOVE | DND.DROP_COPY;
    DragSource dragSource = new org.eclipse.swt.dnd.DragSource(fViewer.getTree(), operations);
    dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    dragSource.addDragListener(new FilterDragSourceAdapter(this));
    DropTarget dropTarget = new DropTarget(fViewer.getTree(), operations);
    dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    dropTarget.addDropListener(new FilterDropTargetAdapter(this));
}
 
Example 15
Source File: XPathExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void createXPathChooser(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    final GridLayout gl = new GridLayout(1, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    final Label label = new Label(composite, SWT.WRAP);
    label.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 30).create());
    label.setText(Messages.selectElementLabel);

    xsdViewer = new TreeViewer(composite);
    provider = new XSDContentProvider(true);
    xsdViewer.setComparer(new IElementComparer() {

        @Override
        public int hashCode(final Object element) {
            return element.hashCode();
        }

        @Override
        public boolean equals(final Object a, final Object b) {
            if (a instanceof XSDFeature && b instanceof XSDFeature) {
                final String aName = ((XSDFeature) a).getName();
                final String bName = ((XSDFeature) b).getName();
                if (aName.equals(bName)) {
                    return EcoreUtil.equals(((XSDFeature) a).getType(), ((XSDFeature) b).getType());
                }
            }
            return a.equals(b);
        }
    });
    xsdViewer.setContentProvider(provider);
    final XSDLabelProvider labelProvider = new XSDLabelProvider();
    xsdViewer.setLabelProvider(new DecoratingLabelProvider(labelProvider, labelProvider));
    final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.minimumHeight = 100;
    xsdViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 150).create());
    xsdViewer.setInput(new Object());

    text = new Text(composite, SWT.WRAP | SWT.BORDER);
    text.setLayoutData(GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 40).create());

    xsdViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ITreeSelection selection = (ITreeSelection) xsdViewer.getSelection();
            //                final String xpath = computeXPath(selection, false);
            //                if (dataName != null) {
            //                    if (xpath == null || xpath.isEmpty()) {
            //                        text.setText(dataName);
            //                    } else {
            //                        text.setText(xpath);
            //                    }
            //                }
            text.redraw();
            //                typeCombo.setSelection(new StructuredSelection(XPathReturnType.getType(selection.getFirstElement())));
            XPathExpressionEditor.this.fireSelectionChanged();
        }
    });

}
 
Example 16
Source File: FlowRefDialog.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
protected void createFormContent(IManagedForm mform) {
	FormToolkit tk = mform.getToolkit();
	Composite body = UI.formBody(mform.getForm(), tk);
	UI.gridLayout(body, 1, 10, 10);

	Composite filterComp = tk.createComposite(body);
	UI.gridLayout(filterComp, 2, 10, 0);
	UI.gridData(filterComp, true, false);
	Label filterLabel = UI.formLabel(filterComp, tk, M.Filter);
	filterLabel.setFont(UI.boldFont());
	Text filterText = UI.formText(filterComp, SWT.SEARCH);
	UI.gridData(filterText, true, false);

	TreeViewer viewer = new TreeViewer(body,
			SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL);
	UI.gridData(viewer.getControl(), true, true);
	viewer.setContentProvider(tree);
	viewer.setLabelProvider(tree);
	viewer.setFilters(new Filter(filterText, viewer));
	viewer.setInput(tree);

	viewer.addSelectionChangedListener(e -> {
		Object obj = Viewers.getFirst(e.getSelection());
		if (obj instanceof FlowRef) {
			selected = (FlowRef) obj;
		} else {
			selected = null;
		}
		Button ok = getButton(IDialogConstants.OK_ID);
		ok.setEnabled(selected != null);
	});

	// handle double clicks
	viewer.addDoubleClickListener(e -> {
		IStructuredSelection s = viewer.getStructuredSelection();
		if (s == null || s.isEmpty())
			return;
		Object elem = s.getFirstElement();

		// double click on a flow
		if (elem instanceof FlowRef) {
			selected = (FlowRef) elem;
			okPressed();
			return;
		}

		// double click on a category
		if (!tree.hasChildren(elem))
			return;
		selected = null;
		getButton(IDialogConstants.OK_ID).setEnabled(false);
		if (viewer.getExpandedState(elem)) {
			viewer.collapseToLevel(elem,
					AbstractTreeViewer.ALL_LEVELS);
		} else {
			viewer.expandToLevel(elem, 1);
		}
	});
}
 
Example 17
Source File: CheckoutWizardSelectionPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void createControl(Composite parent) {
	Composite outerContainer = new Composite(parent,SWT.NONE);
	GridLayout layout = new GridLayout();
	layout.numColumns = 1;
	outerContainer.setLayout(layout);
	outerContainer.setLayoutData(
	new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));

	treeViewer = new TreeViewer(outerContainer, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER);
	RepositoryContentProvider contentProvider = new RepositoryContentProvider();
       treeViewer.setContentProvider(contentProvider);
       treeViewer.addFilter(RepositoryFilters.FOLDERS_ONLY);
       treeViewer.setLabelProvider(new WorkbenchLabelProvider());
       treeViewer.setInput(repositoryLocation);

	GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL);
	data.heightHint = LIST_HEIGHT_HINT;
	data.widthHint = LIST_WIDTH_HINT;
	treeViewer.getControl().setLayoutData(data);

	treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			CheckoutWizard wizard = (CheckoutWizard)getWizard();
			ArrayList folderArray = new ArrayList();
			IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection();
			Iterator iter = selection.iterator();
			while (iter.hasNext()) {
				Object object = iter.next();
				if (object instanceof ISVNRemoteFolder || object instanceof ISVNRepositoryLocation) {
					if (object instanceof ISVNRepositoryLocation) folderArray.add(((ISVNRepositoryLocation)object).getRootFolder());
					else folderArray.add(object);
				}
			}
			ISVNRemoteFolder[] remoteFolders = new ISVNRemoteFolder[folderArray.size()];
			folderArray.toArray(remoteFolders);
			wizard.setRemoteFolders(remoteFolders);
			setPageComplete(!treeViewer.getSelection().isEmpty());
		}
	});
	
       final Action refreshAction = new Action(Policy.bind("RepositoriesView.refreshPopup"), SVNUIPlugin.getPlugin().getImageDescriptor(ISVNUIConstants.IMG_REFRESH)) { //$NON-NLS-1$
           public void run() {
           	refreshViewerNode();
           }
       };
       MenuManager menuMgr = new MenuManager();
       Tree tree = treeViewer.getTree();
       Menu menu = menuMgr.createContextMenu(tree);
       menuMgr.addMenuListener(new IMenuListener() {
           public void menuAboutToShow(IMenuManager manager) {
               manager.add(refreshAction);
           }

       });
       menuMgr.setRemoveAllWhenShown(true);
       tree.setMenu(menu);

	setMessage(Policy.bind("CheckoutWizardSelectionPage.text")); //$NON-NLS-1$

	setControl(outerContainer);
}
 
Example 18
Source File: MoveRemoteResourceWizardMainPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the UI part of the page.
 *
 * @param parent  the parent of the created widgets
 */
public void createControl(Composite parent) {
	Composite composite = createComposite(parent, 1);
	// set F1 help
	PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.MOVE_RENAME_REMOTE_RESOURCE_PAGE);

	Listener listener = new Listener() {
		public void handleEvent(Event event) {
               resourceName = resourceNameText.getText();
			validateFields();
		}
	};

       // the text field for the parent folder
	createLabel(composite, Policy.bind("MoveRemoteResourceWizardMainPage.selectParentUrl")); //$NON-NLS-1$

       urlParentText = createTextField(composite);
       urlParentText.addListener(SWT.Selection, listener);
       urlParentText.addListener(SWT.Modify, listener);
       urlParentText.setEditable(false);


       // Create drill down.
       DrillDownComposite drillDown = new DrillDownComposite(composite, SWT.BORDER);
       GridData spec = new GridData(GridData.FILL_BOTH);
       spec.widthHint = LIST_WIDTH;
       spec.heightHint = LIST_HEIGHT;
       drillDown.setLayoutData(spec);

       // Create tree viewer inside drill down.
       viewer = new TreeViewer(drillDown, SWT.H_SCROLL | SWT.V_SCROLL);
       drillDown.setChildTree(viewer);
       viewer.setLabelProvider(new WorkbenchLabelProvider());
       viewer.setContentProvider(new RemoteContentProvider());
       viewer.setInput(new AllRootsElement());
       viewer.addFilter(RepositoryFilters.FOLDERS_ONLY);
       viewer.addSelectionChangedListener(treeSelectionChangedListener);

       // the text field for the resource name
       createLabel(composite, Policy.bind("MoveRemoteResourceWizardMainPage.resourceName")); //$NON-NLS-1$

       resourceNameText = createTextField(composite);
       resourceNameText.addListener(SWT.Selection, listener);
       resourceNameText.addListener(SWT.Modify, listener);
       resourceNameText.setText(resourceName);

	validateFields();
       resourceNameText.setFocus();

	setControl(composite);

       // set the initial selection in the tree
       if (parentFolder != null) {
           Object toSelect = null;
           if (parentFolder.getParent() == null) {
               // the root folder : select the repository
               toSelect = parentFolder.getRepository();
           }
           else
               toSelect = parentFolder;
           viewer.expandToLevel(toSelect,0);
           viewer.setSelection(new StructuredSelection(toSelect),true);
       }

}
 
Example 19
Source File: NewRemoteFolderWizardMainPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the UI part of the page.
 *
 * @param parent  the parent of the created widgets
 */
public void createControl(Composite parent) {
	Composite composite = createComposite(parent, 1);
	// set F1 help
	PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.CREATE_REMOTE_FOLDER_PAGE);

	Listener listener = new Listener() {
		public void handleEvent(Event event) {
			validateFields();
		}
	};

       // the text field for the parent folder
	createLabel(composite, Policy.bind("NewRemoteFolderWizardMainPage.selectParentUrl")); //$NON-NLS-1$

       urlParentText = createTextField(composite);
       urlParentText.addListener(SWT.Selection, listener);
       urlParentText.addListener(SWT.Modify, listener);
       urlParentText.setEditable(false);


       // Create drill down.
       DrillDownComposite drillDown = new DrillDownComposite(composite, SWT.BORDER);
       GridData spec = new GridData(GridData.FILL_BOTH);
       spec.widthHint = LIST_WIDTH;
       spec.heightHint = LIST_HEIGHT;
       drillDown.setLayoutData(spec);

       // Create tree viewer inside drill down.
       viewer = new TreeViewer(drillDown, SWT.H_SCROLL | SWT.V_SCROLL);
       drillDown.setChildTree(viewer);
       viewer.setLabelProvider(new WorkbenchLabelProvider());
       RemoteContentProvider remoteContentProvider = new RemoteContentProvider();
       remoteContentProvider.setUseDeferredContentManager(false);
       viewer.setContentProvider(remoteContentProvider);
       viewer.setInput(new AllRootsElement());
       viewer.addFilter(RepositoryFilters.FOLDERS_ONLY);
       viewer.addSelectionChangedListener(treeSelectionChangedListener);

       // the text field for the folder name
       createLabel(composite, Policy.bind("NewRemoteFolderWizardMainPage.folderName")); //$NON-NLS-1$

       folderNameText = createTextField(composite);
       folderNameText.addListener(SWT.Selection, listener);
       folderNameText.addListener(SWT.Modify, listener);

	validateFields();
       folderNameText.setFocus();

	setControl(composite);

       // set the initial selection in the tree
       if (parentFolder != null) {      	
       	List itemsToExpand = new ArrayList();
       	ISVNRemoteFolder remoteParent = parentFolder.getParent();
       	while (remoteParent != null) {
   			if (remoteParent.getParent() == null) itemsToExpand.add(0, remoteParent.getRepository());
   			else itemsToExpand.add(0, remoteParent);
   			remoteParent = remoteParent.getParent();        		
       	}

       	viewer.setExpandedElements(itemsToExpand.toArray());
       	if (parentFolder.getParent() == null) viewer.setSelection(new StructuredSelection(parentFolder.getRepository()), true);
       	else viewer.setSelection(new StructuredSelection(parentFolder), true);
       }

}
 
Example 20
Source File: MSyncWizardFolderPage.java    From slr-toolkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Create contents of the wizard.
 * @param parent
 */
public void createControl(Composite parent) {
	mc = MendeleyClient.getInstance();
	
	Composite container = new Composite(parent, SWT.NULL);

	setControl(container);
	container.setLayout(new GridLayout(1, false));
	TreeViewer treeViewer = new TreeViewer(container, SWT.BORDER);
	Tree tree = treeViewer.getTree();
	
	tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	treeViewer.setContentProvider(new TreeContentProvider());
	treeViewer.setLabelProvider(new MendeleyTreeLabelProvider());
	
       try {
       	// TreeViewer takes Array of MendeleyFolders
		treeViewer.setInput(mc.getMendeleyFolders());
	} catch (TokenMgrException e) {
		e.printStackTrace();
	}  
       
       // add a Listener that makes sure that only Folders can be selected
       // if a Folder is selected, the page will be set to complete
       treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
		
		@Override
		public void selectionChanged(SelectionChangedEvent event) {
			TreeSelection selection = ((TreeSelection)event.getSelection());
			if(selection.getFirstElement() instanceof MendeleyDocument){
				
				TreeItem[] item = treeViewer.getTree().getSelection();
				tree.select(item[0].getParentItem());
				folder_selected = (MendeleyFolder)item[0].getParentItem().getData();
				setPageComplete(true);
			}
			if(selection.getFirstElement() instanceof MendeleyFolder){
				folder_selected = (MendeleyFolder)selection.getFirstElement();
				setPageComplete(true);
			}
			isSelectionValidated = false;
		}
	});	
       
}