List of usage examples for org.eclipse.jface.viewers TreeViewer TreeViewer
public TreeViewer(Tree tree)
From source file:com.ebmwebsourcing.petals.services.sa.editor.SaEditionComposite.java
License:Open Source License
/** * Initializes the widgets on the left side. *///from ww w. j av a2 s . c o m protected void createLeftWidgets() { FormToolkit toolkit = this.ise.getFormToolkit(); Composite container = toolkit.createComposite(this); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginTop = 11; layout.marginRight = 7; container.setLayout(layout); container.setLayoutData(new GridData(GridData.FILL_BOTH)); Section section = toolkit.createSection(container, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED); section.setLayoutData(new GridData(GridData.FILL_BOTH)); section.clientVerticalSpacing = 10; section.setText("Service Assembly's Content"); section.setDescription("Select the elements to edit."); container = toolkit.createComposite(section); layout = new GridLayout(2, false); layout.marginWidth = 0; container.setLayout(layout); container.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); section.setClient(container); // Add the tree Tree tree = toolkit.createTree(container, SWT.BORDER | SWT.MULTI); this.viewer = new TreeViewer(tree); this.viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); // Add the content provider this.labelProvider = new ServicesLabelProvider(); this.viewer.setLabelProvider(this.labelProvider); this.viewer.setContentProvider(new DefaultTreeContentProvider() { @Override public Object[] getElements(Object inputElement) { Object o = SaEditionComposite.this.ise.getJbiModel().getServiceAssembly(); return new Object[] { o }; } @Override public boolean hasChildren(Object element) { return getChildren(element).length > 0; } @Override public Object getParent(Object element) { return null; } @Override public Object[] getChildren(Object parentElement) { Object[] result = new Object[0]; if (parentElement instanceof ServiceAssembly) result = ((ServiceAssembly) parentElement).getServiceUnit().toArray(); return result; } }); this.viewer.setInput(new Object()); this.viewer.expandAll(); // Add the buttons Composite buttonsComposite = toolkit.createComposite(container); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttonsComposite.setLayout(layout); buttonsComposite.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, false)); Button newSuButton = this.ise.getFormToolkit().createButton(buttonsComposite, "New...", SWT.PUSH); newSuButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); newSuButton.setImage(PetalsImages.INSTANCE.getAdd()); newSuButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // Select a SU project List<IProject> suProjects = ServiceProjectRelationUtils.getAllSuProjects(); Collections.sort(suProjects, new IProjectComparator()); // Filter projects List<IProject> alreadyPresent = new ArrayList<IProject>(); IWorkspaceRoot iwr = ResourcesPlugin.getWorkspace().getRoot(); for (ServiceUnit su : SaEditionComposite.this.ise.getJbiModel().getServiceAssembly() .getServiceUnit()) { if (su.getIdentification() == null) continue; if (StringUtils.isEmpty(su.getIdentification().getName())) continue; IProject p = iwr.getProject(su.getIdentification().getName()); if (p.exists()) alreadyPresent.add(p); } suProjects.removeAll(alreadyPresent); // Open the selection dialog ListSelectionDialog dlg = new ListSelectionDialog(getShell(), suProjects, new ArrayContentProvider(), new WorkbenchLabelProvider(), "Select a Service Unit project."); dlg.setTitle("Service Unit Selection"); if (dlg.open() != Window.OK) return; // Create the SU element CompoundCommand cc = new CompoundCommand(); for (Object o : dlg.getResult()) { IProject suProject = (IProject) o; ServiceUnit su = JbiFactory.eINSTANCE.createServiceUnit(); Identification id = JbiFactory.eINSTANCE.createIdentification(); id.setName(suProject.getName()); id.setDescription(""); su.setIdentification(id); Target target = JbiFactory.eINSTANCE.createTarget(); target.setArtifactsZip(suProject.getName() + ".zip"); Properties properties = PetalsSPPropertiesManager.getProperties(suProject); String componentName = properties.getProperty(PetalsSPPropertiesManager.COMPONENT_DEPLOYMENT_ID, ""); target.setComponentName(componentName); su.setTarget(target); EList<?> list = SaEditionComposite.this.ise.getJbiModel().getServiceAssembly().getServiceUnit(); AddCommand addCommand = new AddCommand(SaEditionComposite.this.ise.getEditingDomain(), list, su); cc.append(addCommand); } // Execute the command SaEditionComposite.this.ise.getEditingDomain().getCommandStack().execute(cc); // Update the viewers SaEditionComposite.this.viewer.refresh(); SaEditionComposite.this.viewer.expandAll(); SaEditionComposite.this.viewer.setSelection( new StructuredSelection(SaEditionComposite.this.ise.getJbiModel().getServiceAssembly())); SaEditionComposite.this.viewer.getTree().notifyListeners(SWT.Selection, new Event()); SaEditionComposite.this.viewer.getTree().setFocus(); } }); final Button removeProvidesButton = this.ise.getFormToolkit().createButton(buttonsComposite, "Remove", SWT.PUSH); removeProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); removeProvidesButton.setImage(PetalsImages.INSTANCE.getDelete()); removeProvidesButton.addSelectionListener(new DefaultSelectionListener() { /* * (non-Javadoc) * @see org.eclipse.swt.events.SelectionListener * #widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { if (MessageDialog.openConfirm(getShell(), Messages.confimeRemoveEndpointTitle, Messages.confimeRemoveEndpointMessage)) { ServiceAssembly sa = SaEditionComposite.this.ise.getJbiModel().getServiceAssembly(); Object o = ((IStructuredSelection) SaEditionComposite.this.viewer.getSelection()) .getFirstElement(); RemoveCommand deleteCommand = new RemoveCommand(SaEditionComposite.this.ise.getEditingDomain(), sa.getServiceUnit(), o); SaEditionComposite.this.ise.getEditingDomain().getCommandStack().execute(deleteCommand); SaEditionComposite.this.pageBook.removePage(o); SaEditionComposite.this.viewer.refresh(); SaEditionComposite.this.viewer.expandAll(); SaEditionComposite.this.viewer.setSelection(new StructuredSelection(sa)); SaEditionComposite.this.viewer.getTree().notifyListeners(SWT.Selection, new Event()); } } }); final Button upProvidesButton = this.ise.getFormToolkit().createButton(buttonsComposite, "", SWT.PUSH); upProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); upProvidesButton.setText("&Up"); upProvidesButton.addSelectionListener(new DefaultSelectionListener() { /* * (non-Javadoc) * @see org.eclipse.swt.events.SelectionListener * #widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { EList<?> list = SaEditionComposite.this.ise.getJbiModel().getServiceAssembly().getServiceUnit(); Object o = ((IStructuredSelection) SaEditionComposite.this.viewer.getSelection()).getFirstElement(); MoveCommand moveCommand = new MoveCommand(SaEditionComposite.this.ise.getEditingDomain(), list, o, list.indexOf(o) - 1); SaEditionComposite.this.ise.getEditingDomain().getCommandStack().execute(moveCommand); } }); final Button downProvidesButton = this.ise.getFormToolkit().createButton(buttonsComposite, "", SWT.PUSH); downProvidesButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); downProvidesButton.setText("&Down"); downProvidesButton.addSelectionListener(new DefaultSelectionListener() { /* * (non-Javadoc) * @see org.eclipse.swt.events.SelectionListener * #widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { EList<?> list = SaEditionComposite.this.ise.getJbiModel().getServiceAssembly().getServiceUnit(); Object o = ((IStructuredSelection) SaEditionComposite.this.viewer.getSelection()).getFirstElement(); MoveCommand moveCommand = new MoveCommand(SaEditionComposite.this.ise.getEditingDomain(), list, o, list.indexOf(o) + 1); SaEditionComposite.this.ise.getEditingDomain().getCommandStack().execute(moveCommand); } }); this.viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { Object o = ((IStructuredSelection) SaEditionComposite.this.viewer.getSelection()).getFirstElement(); EList<?> sus = SaEditionComposite.this.ise.getJbiModel().getServiceAssembly().getServiceUnit(); boolean isSa = o instanceof ServiceAssembly; boolean isFirst = sus.indexOf(o) == 0; boolean isLast = sus.indexOf(o) == sus.size() - 1; downProvidesButton.setEnabled(!isSa && !isLast); upProvidesButton.setEnabled(!isSa && !isFirst); removeProvidesButton.setEnabled(!isSa); } }); }
From source file:com.ebmwebsourcing.petals.services.su.ui.EnhancedConsumeDialog.java
License:Open Source License
@Override protected Control createDialogArea(final Composite parent) { // General properties getShell().setText("Consume a Petals Service"); setTitle("Consume a Petals Service"); setMessage(DEFAULT_MSG);//from ww w.ja v a 2s .c o m Composite outterComposite = new Composite(parent, SWT.BORDER); GridLayout layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; outterComposite.setLayout(layout); outterComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); ScrolledForm form = this.toolkit.createScrolledForm(outterComposite); form.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite container = form.getBody(); TableWrapLayout tableWrapLayout = new TableWrapLayout(); tableWrapLayout.topMargin = 12; layout = new GridLayout(); layout.verticalSpacing = 9; layout.marginTop = 7; container.setLayout(layout); container.setLayoutData(new GridData(GridData.FILL_BOTH)); // Create the search filter Section filterSection = this.toolkit.createSection(container, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | Section.DESCRIPTION); filterSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); filterSection.clientVerticalSpacing = 10; filterSection.setText("Search Filters"); filterSection.setDescription("Filter the displayed services."); Composite subContainer = this.toolkit.createComposite(filterSection); layout = new GridLayout(4, false); layout.marginWidth = 0; layout.marginBottom = 10; layout.horizontalSpacing = 10; subContainer.setLayout(layout); subContainer.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); filterSection.setClient(subContainer); this.toolkit.createLabel(subContainer, "Interface Name:"); final Text itfNameText = this.toolkit.createText(subContainer, "", SWT.BORDER | SWT.SINGLE); itfNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); itfNameText.setText(this.filterItfName == null ? WILDCARD : this.filterItfName); this.toolkit.createLabel(subContainer, "Interface Namespace:"); final Text itfNsText = this.toolkit.createText(subContainer, "", SWT.BORDER | SWT.SINGLE); itfNsText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); itfNsText.setText(this.filterItfNs == null ? WILDCARD : this.filterItfNs); this.toolkit.createLabel(subContainer, "Service Name:"); final Text srvNameText = this.toolkit.createText(subContainer, "", SWT.BORDER | SWT.SINGLE); srvNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); srvNameText.setText(this.filterSrvName == null ? WILDCARD : this.filterSrvName); this.toolkit.createLabel(subContainer, "Service Namespace:"); final Text srvNsText = this.toolkit.createText(subContainer, "", SWT.BORDER | SWT.SINGLE); srvNsText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); srvNsText.setText(this.filterSrvNs == null ? WILDCARD : this.filterSrvNs); this.toolkit.createLabel(subContainer, "End-point Name:"); final Text edptNameText = this.toolkit.createText(subContainer, "", SWT.BORDER | SWT.SINGLE); edptNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); edptNameText.setText(this.filterEdpt == null ? WILDCARD : this.filterEdpt); this.toolkit.createLabel(subContainer, "Target Component:"); final Text compText = this.toolkit.createText(subContainer, "", SWT.BORDER | SWT.SINGLE); compText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); compText.setText(this.filterComp == null ? WILDCARD : this.filterComp); // The tree to list all the services Composite bottomComposite = this.toolkit.createComposite(container); layout = new GridLayout(2, true); layout.marginWidth = 0; bottomComposite.setLayout(layout); bottomComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); Section section = this.toolkit.createSection(bottomComposite, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | Section.DESCRIPTION); section.setLayoutData(new GridData(GridData.FILL_BOTH)); section.clientVerticalSpacing = 10; section.setText("Available Services"); section.setDescription("A list of all the known Petals services."); subContainer = this.toolkit.createComposite(section); layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; subContainer.setLayout(layout); subContainer.setLayoutData(new TableWrapData(TableWrapData.FILL)); section.setClient(subContainer); Tree tree = this.toolkit.createTree(subContainer, SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.widthHint = 400; layoutData.heightHint = 400; tree.setLayoutData(layoutData); final TreeViewer treeViewer = new TreeViewer(tree); treeViewer.setContentProvider(new ServiceContentProvider()); treeViewer.setLabelProvider(new ServiceLabelProvider()); treeViewer.addFilter(new ServiceViewerFilter()); ColumnViewerToolTipSupport.enableFor(treeViewer, ToolTip.NO_RECREATE); // Prepare the input... Map<QName, ItfBean> itfNameToInterface = new HashMap<QName, ItfBean>(); for (EndpointSource src : SourceManager.getInstance().getSources()) { for (ServiceUnitBean su : src.getServiceUnits()) { for (EndpointBean bean : su.getEndpoints()) { // Handle the interface name ItfBean itfBean = itfNameToInterface.get(bean.getInterfaceName()); if (itfBean == null) { itfBean = new ItfBean(); itfBean.itfName = bean.getInterfaceName(); itfNameToInterface.put(itfBean.itfName, itfBean); } // Handle the service name SrvBean srvBean = itfBean.srvNameToService.get(bean.getServiceName()); if (srvBean == null) { srvBean = new SrvBean(); srvBean.itf = itfBean; srvBean.srvName = bean.getServiceName(); itfBean.srvNameToService.put(srvBean.srvName, srvBean); } // Handle the end-point name EdptBean edptBean = new EdptBean(); edptBean.edptBean = bean; srvBean.endpoints.add(edptBean); } } } // ... and set it! treeViewer.setInput(itfNameToInterface); // The properties of the selection final Composite leftComposite = this.toolkit.createComposite(bottomComposite); leftComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; leftComposite.setLayout(layout); // Show a default widget on the left (waiting for a new selection) // It will be deleted as soon as a selection is made in the tree section = this.toolkit.createSection(leftComposite, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED); section.setLayoutData(new GridData(GridData.FILL_BOTH)); section.clientVerticalSpacing = 10; section.setText("Properties"); final Composite propertiesComposite = this.toolkit.createComposite(section); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.horizontalSpacing = 10; layout.verticalSpacing = 2; propertiesComposite.setLayout(layout); propertiesComposite.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); section.setClient(propertiesComposite); this.toolkit.createLabel(propertiesComposite, "Select a service identifier in the tree on the left."); this.toolkit.createLabel(propertiesComposite, "Its properties will be displayed here."); // Listeners ModifyListener modifyListener = new ModifyListener() { @Override public void modifyText(ModifyEvent e) { String value = ((Text) e.widget).getText().trim(); if (e.widget == itfNameText) EnhancedConsumeDialog.this.filterItfName = value; else if (e.widget == itfNsText) EnhancedConsumeDialog.this.filterItfNs = value; else if (e.widget == srvNameText) EnhancedConsumeDialog.this.filterSrvName = value; else if (e.widget == srvNsText) EnhancedConsumeDialog.this.filterSrvNs = value; else if (e.widget == edptNameText) EnhancedConsumeDialog.this.filterEdpt = value; else if (e.widget == compText) EnhancedConsumeDialog.this.filterComp = value; treeViewer.refresh(); } }; itfNameText.addModifyListener(modifyListener); itfNsText.addModifyListener(modifyListener); srvNameText.addModifyListener(modifyListener); srvNsText.addModifyListener(modifyListener); edptNameText.addModifyListener(modifyListener); compText.addModifyListener(modifyListener); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { EnhancedConsumeDialog.this.operationToInvoke = null; EnhancedConsumeDialog.this.invocationMep = null; EnhancedConsumeDialog.this.itfToInvoke = null; EnhancedConsumeDialog.this.srvToInvoke = null; EnhancedConsumeDialog.this.edptToInvoke = null; handleSelection(event, leftComposite); validate(); parent.layout(); } }); if (!StringUtils.isEmpty(this.filterItfName) || !StringUtils.isEmpty(this.filterItfNs) || !StringUtils.isEmpty(this.filterSrvName) || !StringUtils.isEmpty(this.filterSrvNs) || !StringUtils.isEmpty(this.filterEdpt) || !StringUtils.isEmpty(this.filterComp)) filterSection.setExpanded(true); return container; }
From source file:com.ebmwebsourcing.petals.services.wizards.AbstractPetalsServiceCreationWizardPage.java
License:Open Source License
@Override @SuppressWarnings("restriction") public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout()); container.setLayoutData(new GridData(GridData.FILL_BOTH)); // Before the workspace location createWidgetsBeforeProjectLocation(container); // Workspace location final Button useDefaultLocButton = new Button(container, SWT.CHECK); useDefaultLocButton.setText("Create the project(s) in the default location"); GridData layoutData = new GridData(); layoutData.verticalIndent = 17;//from ww w. j a va 2s . co m useDefaultLocButton.setLayoutData(layoutData); Composite locContainer = new Composite(container, SWT.NONE); GridLayout layout = new GridLayout(3, false); layout.marginHeight = layout.marginWidth = 0; locContainer.setLayout(layout); locContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Label locLabel = new Label(locContainer, SWT.NONE); locLabel.setText("Project(s) location:"); final Text projectLocationText = new Text(locContainer, SWT.SINGLE | SWT.BORDER); projectLocationText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); projectLocationText.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); projectLocationText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { AbstractPetalsServiceCreationWizardPage.this.projectLocation = projectLocationText.getText(); validate(); } }); final Button browseButton = new Button(locContainer, SWT.PUSH); browseButton.setText("Browse..."); browseButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String location = new DirectoryDialog(getShell()).open(); if (location != null) projectLocationText.setText(location); } }); useDefaultLocButton.setSelection(this.isAtDefaultLocation); useDefaultLocButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { AbstractPetalsServiceCreationWizardPage.this.isAtDefaultLocation = useDefaultLocButton .getSelection(); boolean use = !AbstractPetalsServiceCreationWizardPage.this.isAtDefaultLocation; locLabel.setEnabled(use); projectLocationText.setEnabled(use); browseButton.setEnabled(use); projectLocationText.setFocus(); } }); // List of projects to create Label l = new Label(container, SWT.NONE); l.setText("Specify the properties of the target project(s)."); layoutData = new GridData(); layoutData.verticalIndent = 17; l.setLayoutData(layoutData); Tree tree = new Tree(container, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE); layoutData = new GridData(GridData.FILL_BOTH); layoutData.heightHint = 90; tree.setLayoutData(layoutData); tree.setHeaderVisible(true); tree.setLinesVisible(true); TableLayout tlayout = new TableLayout(); tlayout.addColumnData(new ColumnWeightData(40, 150, false)); tlayout.addColumnData(new ColumnWeightData(10, 10, false)); tlayout.addColumnData(new ColumnWeightData(10, 15, false)); tlayout.addColumnData(new ColumnWeightData(20, 80, true)); tlayout.addColumnData(new ColumnWeightData(20, 60, true)); tree.setLayout(tlayout); TreeColumn column = new TreeColumn(tree, SWT.LEFT); column.setText(PROJECT_NAME); column = new TreeColumn(tree, SWT.CENTER); column.setText(CREATE); column = new TreeColumn(tree, SWT.CENTER); column.setText(OVERWRITE); column = new TreeColumn(tree, SWT.LEFT); column.setText(COMPONENT_NAME); column = new TreeColumn(tree, SWT.CENTER); column.setText(COMPONENT_VERSION); // Create the viewer this.viewer = new TreeViewer(tree); // Define its content provider this.viewer.setContentProvider(new ITreeContentProvider() { @Override public Object[] getChildren(Object parentElement) { Object[] children = new Object[0]; if (parentElement instanceof SaImportBean) { children = new Object[((SaImportBean) parentElement).countSuBeans()]; children = ((SaImportBean) parentElement).getSuBeans().toArray(children); } return children; } @Override public Object getParent(Object element) { return null; } @Override public boolean hasChildren(Object element) { boolean hasChildren = false; if (element instanceof SaImportBean) { hasChildren = ((SaImportBean) element).countSuBeans() > 0; } return hasChildren; } @Override public Object[] getElements(Object inputElement) { Object[] result = new Object[((Collection<?>) inputElement).size()]; return ((Collection<?>) inputElement).toArray(result); } @Override public void dispose() { // nothing } @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { // nothing } }); // Define its label provider this.viewer.setLabelProvider(new ITableLabelProvider() { @Override public Image getColumnImage(Object element, int columnIndex) { Image result = null; switch (columnIndex) { case 0: if (element instanceof SaImportBean) result = AbstractPetalsServiceCreationWizardPage.this.saImg; else if (element instanceof SuImportBean) result = AbstractPetalsServiceCreationWizardPage.this.suImg; break; case 1: if (element instanceof ServiceImportBean) { result = ((ServiceImportBean) element).isToCreate() ? AbstractPetalsServiceCreationWizardPage.this.checked : AbstractPetalsServiceCreationWizardPage.this.unchecked; } break; case 2: if (element instanceof ServiceImportBean) { result = ((ServiceImportBean) element).isToOverwrite() ? AbstractPetalsServiceCreationWizardPage.this.checked : AbstractPetalsServiceCreationWizardPage.this.unchecked; } break; } return result; } @Override public String getColumnText(Object element, int columnIndex) { String result = ""; switch (columnIndex) { case 0: if (element instanceof ServiceImportBean) result = ((ServiceImportBean) element).getProjectName(); break; case 1: case 2: break; case 3: if (element instanceof SuImportBean) result = ((SuImportBean) element).getComponentName(); break; case 4: if (element instanceof SuImportBean) result = ((SuImportBean) element).getComponentVersion(); break; } return result; } @Override public void addListener(ILabelProviderListener listener) { // nothing } @Override public void dispose() { // nothing } @Override public boolean isLabelProperty(Object element, String property) { return false; } @Override public void removeListener(ILabelProviderListener listener) { // nothing } }); // Define its sorter this.viewer.setSorter(new ViewerSorter() { @Override public int compare(Viewer viewer, Object e1, Object e2) { if (e1 instanceof ServiceImportBean && e2 instanceof ServiceImportBean) { String n1 = ((ServiceImportBean) e1).getProjectName(); if (n1 == null) n1 = ""; String n2 = ((ServiceImportBean) e2).getProjectName(); if (n2 == null) n2 = ""; return n1.compareTo(n2); } return super.compare(viewer, e1, e2); } }); // Create the editor for the versions (it must be done before creating the cell modifiers). // This is done this way to allow the editor to store and retrieve custom values (i.e. versions // that are not registered but manually entered by the user). final StringComboBoxCellEditor comboEditor = new StringComboBoxCellEditor(tree, DEFAULT_VERSIONS, SWT.DROP_DOWN); this.viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { if (!event.getSelection().isEmpty()) { Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (o instanceof SuImportBean) { // If there is a custom value, add it in the list SuImportBean suBean = (SuImportBean) o; List<String> versions = Arrays.asList(suBean.getSupportedVersions()); versions = new ArrayList<String>(versions); if (!versions.contains(suBean.getComponentVersion())) versions.add(suBean.getComponentVersion()); String[] items = new String[versions.size()]; comboEditor.setItems(versions.toArray(items)); } else if (o instanceof SaImportBean) comboEditor.setItems(DEFAULT_VERSIONS); } } }); // Define its cell modifier this.viewer.setCellModifier(new ICellModifier() { @Override public void modify(Object element, String property, Object value) { TreeItem tableItem = (TreeItem) element; if (PROJECT_NAME.equals(property)) { ServiceImportBean bean = (ServiceImportBean) tableItem.getData(); bean.setProjectName((String) value); AbstractPetalsServiceCreationWizardPage.this.viewer.refresh(bean); validate(); } else if (CREATE.equals(property)) { ServiceImportBean bean = (ServiceImportBean) tableItem.getData(); bean.setToCreate((Boolean) value); AbstractPetalsServiceCreationWizardPage.this.viewer.refresh(bean); validate(); } else if (OVERWRITE.equals(property)) { ServiceImportBean bean = (ServiceImportBean) tableItem.getData(); bean.setOverwrite((Boolean) value); AbstractPetalsServiceCreationWizardPage.this.viewer.refresh(bean); validate(); } else if (tableItem.getData() instanceof SuImportBean) { if (COMPONENT_NAME.equals(property)) { SuImportBean bean = (SuImportBean) tableItem.getData(); bean.setComponentName((String) value); AbstractPetalsServiceCreationWizardPage.this.viewer.refresh(bean); validate(); } else if (COMPONENT_VERSION.equals(property)) { SuImportBean bean = (SuImportBean) tableItem.getData(); bean.setComponentVersion((String) value); AbstractPetalsServiceCreationWizardPage.this.viewer.refresh(bean); validate(); } } } @Override public Object getValue(Object element, String property) { Object value = null; if (PROJECT_NAME.equals(property)) value = ((ServiceImportBean) element).getProjectName(); else if (CREATE.equals(property)) value = Boolean.valueOf(((ServiceImportBean) element).isToCreate()); else if (OVERWRITE.equals(property)) value = ((ServiceImportBean) element).isToOverwrite(); else if (element instanceof SuImportBean) { SuImportBean bean = (SuImportBean) element; if (COMPONENT_NAME.equals(property)) value = bean.getComponentName(); else if (COMPONENT_VERSION.equals(property)) value = bean.getComponentVersion(); } return value; } @Override public boolean canModify(Object element, String property) { boolean canModify = true; if (element instanceof SaImportBean) { canModify = PROJECT_NAME.equals(property) || CREATE.equals(property) || OVERWRITE.equals(property); } return canModify; } }); // End up with the viewer properties this.viewer.setColumnProperties( new String[] { PROJECT_NAME, CREATE, OVERWRITE, COMPONENT_NAME, COMPONENT_VERSION }); this.viewer.setCellEditors(new CellEditor[] { new TextCellEditor(tree), new CheckboxCellEditor(tree), new CheckboxCellEditor(tree), new TextCellEditor(tree, SWT.READ_ONLY), comboEditor }); // Last steps if (!this.importsBeans.isEmpty()) { this.viewer.setInput(this.importsBeans); this.viewer.expandAll(); } useDefaultLocButton.notifyListeners(SWT.Selection, new Event()); tree.notifyListeners(SWT.Selection, new Event()); validate(); setErrorMessage(null); setControl(container); // Force the shell size Point size = getShell().computeSize(700, 600); getShell().setSize(size); Rectangle rect = Display.getCurrent().getBounds(); getShell().setLocation((rect.width - size.x) / 2, (rect.height - size.y) / 2); }
From source file:com.ecfeed.ui.editor.TreeViewerSection.java
License:Open Source License
protected TreeViewer createTreeViewer(Composite parent, int style) { Tree tree = new Tree(parent, style); tree.setLayoutData(viewerLayoutData()); TreeViewer treeViewer = new TreeViewer(tree); return treeViewer; }
From source file:com.embedthis.ejs.ide.views.EJScriptPackageViewer.java
License:Open Source License
@Override public void createPartControl(Composite parent) { EJScriptTrace.trace(EJScriptTrace.TRACE_VERBOSE, EJScriptTrace.VIEWS_TRACE, "+createPartControl"); viewer = new TreeViewer(parent); viewer.setContentProvider(new EJScriptProjectContentProvider()); viewer.setLabelProvider(new EJScriptLabelProvider()); viewer.setInput(getViewSite());/* w w w . j a v a 2 s . c om*/ EJScriptTrace.trace(EJScriptTrace.TRACE_VERBOSE, EJScriptTrace.VIEWS_TRACE, "-createPartControl"); }
From source file:com.generalrobotix.ui.view.GrxItemView.java
License:Open Source License
/** * @brief constructor//from w w w . j a v a2s. c o m * @param name name of this view * @param manager PluginManager * @param vp * @param parent */ @SuppressWarnings("unchecked") public GrxItemView(String name, GrxPluginManager manager, GrxBaseViewPart vp, Composite parent) { super(name, manager, vp, parent); tv = new TreeViewer(composite_); tv.setContentProvider(new TreeContentProvider()); tv.setLabelProvider(new TreeLabelProvider()); Tree t = tv.getTree(); // When an item is left-clicked, the item becomes "current item". tv.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); for (Object o : ((IStructuredSelection) selection).toArray()) { if (GrxBaseItem.class.isAssignableFrom(o.getClass())) { manager_.focusedItem((GrxBaseItem) o); } else if (o instanceof String) { manager_.focusedItem(manager_.getProject()); } } } }); // ??? t.addListener(SWT.DefaultSelection, new Listener() { public void handleEvent(Event event) { ISelection selection = tv.getSelection(); for (Object o : ((IStructuredSelection) selection).toArray()) { if (GrxBaseItem.class.isAssignableFrom(o.getClass())) { manager_.setSelectedItem((GrxBaseItem) o, !((GrxBaseItem) o).isSelected()); } } } }); // ? t.setMenu(menuMgr.createContextMenu(t)); t.addListener(SWT.MenuDetect, new Listener() { public void handleEvent(Event event) { ISelection selection = tv.getSelection(); Object o = ((IStructuredSelection) selection).getFirstElement(); menuMgr.removeAll(); // ???? // project name if (o instanceof String) { Vector<Action> menus = manager_.getProject().getMenu(); for (Action a : menus) { menuMgr.add(a); } } // ? if (Class.class.isAssignableFrom(o.getClass())) { if (GrxBaseItem.class.isAssignableFrom((Class<?>) o)) { Vector<Action> menus = manager_.getItemMenu((Class<? extends GrxBaseItem>) o); for (Action a : menus) { menuMgr.add(a); } } } // ? if (GrxBasePlugin.class.isAssignableFrom(o.getClass())) { Vector<Action> menus = ((GrxBasePlugin) o).getMenu(); for (Action a : menus) { menuMgr.add(a); } Vector<MenuManager> subMenus = ((GrxBasePlugin) o).getSubMenu(); for (MenuManager m : subMenus) { menuMgr.add(m); } } } }); // ? tv.setInput(manager_); manager_.registerItemChangeListener(this, GrxBaseItem.class); setUp(); }
From source file:com.genuitec.eclipse.gerrit.tools.internal.gps.dialogs.ImportProjectsDialog.java
License:Open Source License
private void createRepositoriesGroup(Composite parent) { Group group = new Group(parent, SWT.NONE); group.setText("Git repositories"); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); group.setLayout(new GridLayout()); Composite treeParent = new Composite(group, SWT.NONE); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.heightHint = 200;//from w w w . j a v a 2s .c o m treeParent.setLayoutData(data); TreeColumnLayout treeLayout = new TreeColumnLayout(); treeParent.setLayout(treeLayout); TreeViewer viewer = new TreeViewer(treeParent); viewer.getTree().setHeaderVisible(true); TreeColumn column = new TreeColumn(viewer.getTree(), SWT.NONE); column.setText("Name"); treeLayout.setColumnData(column, new ColumnWeightData(30)); column = new TreeColumn(viewer.getTree(), SWT.NONE); column.setText("State"); treeLayout.setColumnData(column, new ColumnWeightData(20)); TreeViewerColumn vc = new TreeViewerColumn(viewer, SWT.NONE); column = vc.getColumn(); column.setText("User name"); treeLayout.setColumnData(column, new ColumnWeightData(20)); vc.setEditingSupport(new MyCellEditingSupport(viewer)); viewer.setContentProvider(new ContentProvider()); viewer.setLabelProvider(new MyLabelProvider()); viewer.setInput(null); for (IGpsRepositoriesConfig repo : gpsFile.getRepositoryConfigs()) { if (repo.getType().equals("git")) { //$NON-NLS-1$ viewer.setInput(repo.getRepositoriesSetups()); } } }
From source file:com.google.dart.tools.ui.internal.appsview.AppsView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { treeViewer = new TreeViewer(parent); treeViewer.setContentProvider(new AppsViewContentProvider()); appLabelProvider = new AppLabelProvider(treeViewer.getTree().getFont()); treeViewer.setLabelProvider(new LabelProviderWrapper(appLabelProvider, new AppProblemsDecorator(), null)); treeViewer.setComparator(new AppsViewComparator()); treeViewer.addDoubleClickListener(new IDoubleClickListener() { @Override// w w w . j ava 2 s.co m public void doubleClick(DoubleClickEvent event) { handleDoubleClick(event); } }); treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); initDragAndDrop(); getSite().setSelectionProvider(treeViewer); makeActions(); fillInToolbar(getViewSite().getActionBars().getToolBarManager()); fillInActionBars(); // Create the TreeViewer's context menu. createContextMenu(); parent.getDisplay().asyncExec(new Runnable() { @Override public void run() { linkWithEditorAction.syncSelectionToEditor(); } }); JFaceResources.getFontRegistry().addListener(fontPropertyChangeListener); updateTreeFont(); restoreState(); }
From source file:com.google.dart.tools.ui.internal.filesview.FilesView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { treeViewer = new TreeViewer(parent); treeViewer.setContentProvider(new ResourceContentProvider()); resourceLabelProvider = new ResourceLabelProvider(); treeViewer.setLabelProvider(/*from ww w . j ava 2s. c o m*/ new DecoratingStyledCellLabelProvider(resourceLabelProvider, new ProblemsLabelDecorator(), null)); treeViewer.setComparator(new FilesViewerComparator()); treeViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { handleDoubleClick(event); } }); treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); initDragAndDrop(); getSite().setSelectionProvider(treeViewer); makeActions(); fillInToolbar(getViewSite().getActionBars().getToolBarManager()); fillInActionBars(); // Create the TreeViewer's context menu. createContextMenu(); parent.getDisplay().asyncExec(new Runnable() { @Override public void run() { linkWithEditorAction.syncSelectionToEditor(); } }); JFaceResources.getFontRegistry().addListener(fontPropertyChangeListener); updateTreeFont(); restoreState(); }
From source file:com.google.dart.tools.ui.internal.typehierarchy.HierarchyInformationControl.java
License:Open Source License
@Override protected TreeViewer createTreeViewer(Composite parent, int style) { Tree tree = new Tree(parent, SWT.SINGLE | (style & ~SWT.MULTI)); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = tree.getItemHeight() * 12; tree.setLayoutData(gd);/*from w w w .j av a2s.c o m*/ TreeViewer treeViewer = new TreeViewer(tree); treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); treeViewer.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return element instanceof Type; } }); contentProvider = new TypeHierarchyContentProvider(); treeViewer.setContentProvider(contentProvider); labelProvider = new HierarchyLabelProvider(contentProvider.getLightPredicate()); ColoringLabelProvider coloringLabelProvider = new ColoringLabelProvider(labelProvider); treeViewer.setLabelProvider(coloringLabelProvider); coloringLabelProvider.setOwnerDrawEnabled(true); return treeViewer; }