List of usage examples for org.eclipse.jface.viewers TreeViewer setContentProvider
@Override public void setContentProvider(IContentProvider provider)
TreeViewer
. From source file:com.diffplug.common.swt.jface.ViewerMisc.java
License:Apache License
/** Sets an {@link ILazyTreeContentProvider} implemented by the given {@link TreeDef.Parented}. */ @SuppressWarnings("unchecked") public static <T> void setLazyTreeContentProvider(TreeViewer viewer, TreeDef.Parented<T> treeDef) { Preconditions.checkArgument(SwtMisc.flagIsSet(SWT.VIRTUAL, viewer.getControl()), "The tree must have SWT.VIRTUAL set."); viewer.setUseHashlookup(true);/*w ww. j a va2s . c o m*/ viewer.setContentProvider(new ILazyTreeContentProvider() { @Override public void dispose() { } @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @Override public void updateElement(Object parent, int index) { T child = treeDef.childrenOf((T) parent).get(index); viewer.replace(parent, index, child); updateChildCount(child, 0); } @Override public void updateChildCount(Object element, int currentChildCount) { viewer.setChildCount(element, treeDef.childrenOf((T) element).size()); } @Override public Object getParent(Object element) { return treeDef.parentOf((T) element); } }); }
From source file:com.dtsworkshop.flextools.search.ui.SearchResultPage.java
License:Open Source License
@Override protected void configureTreeViewer(TreeViewer viewer) { viewer.setUseHashlookup(true);/*from ww w .ja v a2s .c om*/ viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { handleDoubleClick(event); } }); viewer.setLabelProvider(new ILabelProvider() { public Image getImage(Object element) { // TODO: Implement image handling! return null; } public String getText(Object element) { if (element instanceof IFile) { return ((IFile) element).getProjectRelativePath().toPortableString().replace("/", "."); } else if (element instanceof SearchReference) { SearchReference ref = (SearchReference) element; String description = String.format("%s [%d - %d]", ref.getDescription(), ref.getFrom(), ref.getTo()); return description; } return element.toString(); } public void addListener(ILabelProviderListener listener) { } public void dispose() { } public boolean isLabelProperty(Object element, String property) { return false; } public void removeListener(ILabelProviderListener listener) { } }); viewer.setContentProvider(new FlexTreeContentProvider()); }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.JavaToWSDLWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); container.setLayout(layout);//from w ww . j a va 2s .c o m container.setLayoutData(new GridData(GridData.FILL_BOTH)); // Container selection Label l = new Label(container, SWT.NONE); l.setText("Select the Java project that contains the classes."); GridData layoutData = new GridData(); layoutData.horizontalSpan = 2; l.setLayoutData(layoutData); TreeViewer viewer = new TreeViewer(container, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 2; viewer.getTree().setLayoutData(layoutData); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new WorkbenchContentProvider() { @Override public Object[] getChildren(Object o) { if (o instanceof IWorkspaceRoot) { IProject[] projects = ((IWorkspaceRoot) o).getProjects(); ArrayList<IJavaProject> result = new ArrayList<IJavaProject>(); for (IProject project : projects) { try { if (!project.isOpen() || !project.hasNature(JavaCore.NATURE_ID)) continue; } catch (CoreException e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.WARNING); continue; } IJavaProject p = JavaCore.create(project); result.add(p); } return result.toArray(); } return new Object[0]; } }); // Set page input IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); viewer.setInput(root); if (this.javaProject != null) { viewer.setSelection(new StructuredSelection(this.javaProject), true); viewer.expandToLevel(this.javaProject, 1); } viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); if (!s.isEmpty()) JavaToWSDLWizardPage.this.javaProject = (IJavaProject) s.getFirstElement(); else JavaToWSDLWizardPage.this.javaProject = null; validate(); } }); viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { openClassSelectionDialog(); } }); // Class field l = new Label(container, SWT.NONE); l.setText("Select the Java interface."); layoutData = new GridData(); layoutData.horizontalSpan = 2; layoutData.verticalIndent = 15; l.setLayoutData(layoutData); this.classText = new Text(container, SWT.BORDER | SWT.SINGLE); this.classText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.classText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { JavaToWSDLWizardPage.this.className = JavaToWSDLWizardPage.this.classText.getText(); validate(); } }); Button b = new Button(container, SWT.PUSH); b.setText("Browse..."); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { openClassSelectionDialog(); } @Override public void widgetSelected(SelectionEvent e) { openClassSelectionDialog(); } }); this.classText.setFocus(); setControl(container); }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.WSDLtoJavaWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); container.setLayout(layout);/*www . ja va 2 s .com*/ container.setLayoutData(new GridData(GridData.FILL_BOTH)); // WSDL field Label l = new Label(container, SWT.NONE); l.setText("WSDL URI:"); l.setLayoutData(new GridData()); final Text text = new Text(container, SWT.BORDER | SWT.SINGLE); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { String uri = text.getText(); if (uri.trim().length() == 0) return; try { WSDLtoJavaWizardPage.this.wsdlUri = UriAndUrlHelper.urlToUri(uri); } catch (Exception e1) { WSDLtoJavaWizardPage.this.wsdlUri = null; } validate(); } }); Composite buttons = new Composite(container, SWT.NONE); layout = new GridLayout(2, false); layout.marginHeight = layout.marginWidth = 0; buttons.setLayout(layout); Button b = new Button(buttons, SWT.PUSH); b.setText("Browse File System"); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @Override public void widgetSelected(SelectionEvent e) { FileDialog dlg = new FileDialog(text.getShell(), SWT.SINGLE); dlg.setFilterNames(new String[] { "WSDL (*.wsdl)" }); //$NON-NLS-1$ dlg.setFilterExtensions(new String[] { "*.wsdl" }); //$NON-NLS-1$ String path = dlg.open(); if (path != null) { text.setText(new File(path).toURI().toString()); text.setSelection(path.length()); text.setFocus(); } } }); b = new Button(buttons, SWT.PUSH); b.setText("Browse Workspace..."); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } @Override public void widgetSelected(SelectionEvent e) { WorkspaceExplorer dlg = new WorkspaceExplorer(getShell(), new String[] { "wsdl" }); if (dlg.open() == Window.OK) { IResource res = dlg.getSelectedResource(); text.setText(new File(res.getLocation().toOSString()).toURI().toString()); text.setSelection(text.getText().length()); text.setFocus(); } } }); // Container selection l = new Label(container, SWT.NONE); l.setText("Select the output location."); GridData layoutData = new GridData(); layoutData.verticalIndent = 15; l.setLayoutData(layoutData); TreeViewer viewer = new TreeViewer(container, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); layoutData = new GridData(GridData.FILL_BOTH); layoutData.heightHint = 200; viewer.getTree().setLayoutData(layoutData); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new WorkbenchContentProvider() { @Override public Object[] getChildren(Object o) { if (o instanceof IContainer) { IResource[] members; try { members = ((IContainer) o).members(); } catch (Exception e) { return new Object[0]; } ArrayList<IResource> results = new ArrayList<IResource>(); for (IResource member : members) { if (member instanceof IContainer) results.add(member); } return results.toArray(); } return new Object[0]; } }); // Set page input IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); viewer.setInput(root); if (this.outputContainer != null) { viewer.setSelection(new StructuredSelection(this.outputContainer), true); viewer.expandToLevel(this.outputContainer, 1); } viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); if (!s.isEmpty()) WSDLtoJavaWizardPage.this.outputContainer = (IContainer) s.getFirstElement(); else WSDLtoJavaWizardPage.this.outputContainer = null; validate(); } }); text.setFocus(); setControl(container); }
From source file:com.ebmwebsourcing.petals.common.internal.wizards.JbiXmlNewWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { // Create the composite container and define its layout final Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginLeft = layout.marginRight = 15; layout.marginTop = 15;/* ww w .ja v a2 s . co m*/ container.setLayout(layout); container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Container viewer new Label(container, SWT.NONE).setText(Messages.NewJbiXmlWizardPage_2); final Text folderPathText = new Text(container, SWT.SINGLE | SWT.BORDER); folderPathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); TreeViewer viewer = new TreeViewer(container, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.HIDE_SELECTION); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.heightHint = 100; viewer.getTree().setLayoutData(layoutData); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new WorkbenchContentProvider() { /* * (non-Javadoc) * @see org.eclipse.ui.model.BaseWorkbenchContentProvider * #getChildren(java.lang.Object) */ @Override public Object[] getChildren(Object o) { if (o instanceof IProject && !((IProject) o).isOpen()) return new Object[0]; List<IResource> children = new ArrayList<IResource>(); if (o instanceof IContainer) { try { IResource[] members = ((IContainer) o).members(); for (IResource member : members) { if (member instanceof IContainer || (member instanceof IFile && member.getName().equals("jbi.xml"))) //$NON-NLS-1$ children.add(member); } } catch (CoreException e) { PetalsCommonPlugin.log(e, IStatus.ERROR); } } return children.toArray(new IResource[0]); } /* * (non-Javadoc) * @see org.eclipse.ui.model.BaseWorkbenchContentProvider * #hasChildren(java.lang.Object) */ @Override public boolean hasChildren(Object element) { return getChildren(element).length > 0; } }); // Set page input IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); viewer.setInput(root); if (this.selectedContainer != null) { viewer.setSelection(new StructuredSelection(this.selectedContainer), true); viewer.expandToLevel(this.selectedContainer, 1); } viewer.addPostSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (o instanceof IContainer) JbiXmlNewWizardPage.this.selectedContainer = (IContainer) o; else JbiXmlNewWizardPage.this.selectedContainer = ((IFile) o).getParent(); String path = JbiXmlNewWizardPage.this.selectedContainer.getFullPath().toOSString(); String fileSeparator = System.getProperty("file.separator"); //$NON-NLS-1$ if (path.startsWith(fileSeparator)) path = path.substring(fileSeparator.length()); folderPathText.setText(path); validate(); } }); // Overwrite existing file ? final Button overwriteButton = new Button(container, SWT.CHECK); overwriteButton.setText(Messages.NewJbiXmlWizardPage_5); overwriteButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { JbiXmlNewWizardPage.this.overwriteExistingFile = overwriteButton.getSelection(); validate(); } }); // Set control setControl(container); }
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 w w w .j a v a 2 s . c om 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.su.wizards.pages.ChoicePage.java
License:Open Source License
@Override public void createControl(Composite parent) { // Create the composite container and define its layout final Composite container = SwtFactory.createComposite(parent); setControl(container);/*from w ww .j a va 2 s . c o m*/ SwtFactory.applyNewGridLayout(container, 2, false, 15, 0, 0, 15); SwtFactory.applyHorizontalGridData(container); // Add a tool tip to display in case of problem this.helpTooltip = new FixedShellTooltip(getShell(), true, 90) { @Override public void populateTooltip(Composite parent) { GridLayout layout = new GridLayout(); layout.verticalSpacing = 2; parent.setLayout(layout); parent.setLayoutData(new GridData(GridData.FILL_BOTH)); parent.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); try { ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin( PetalsConstants.PETALS_COMMON_PLUGIN_ID, "icons/petals/thinking_hard.png"); if (desc != null) ChoicePage.this.helpImg = desc.createImage(); parent.setBackgroundMode(SWT.INHERIT_DEFAULT); Label imgLabel = new Label(parent, SWT.NONE); imgLabel.setImage(ChoicePage.this.helpImg); imgLabel.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true)); } catch (Exception e) { PetalsServicesPlugin.log(e, IStatus.WARNING); } FontData[] fd = PlatformUtils.getModifiedFontData(getFont().getFontData(), SWT.BOLD); ChoicePage.this.boldFont = new Font(getShell().getDisplay(), fd); Label titleLabel = new Label(parent, SWT.NONE); titleLabel.setFont(ChoicePage.this.boldFont); GridData layoutData = new GridData(SWT.CENTER, SWT.DEFAULT, true, true); layoutData.verticalIndent = 5; titleLabel.setLayoutData(layoutData); titleLabel.setText("What does this error mean?"); Label l = new Label(parent, SWT.WRAP); l.setText("This wizard will generate, among other things, Maven artifacts."); layoutData = new GridData(); layoutData.verticalIndent = 8; l.setLayoutData(layoutData); RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL); rowLayout.marginLeft = 0; rowLayout.marginTop = 0; rowLayout.marginRight = 0; rowLayout.marginBottom = 0; rowLayout.spacing = 0; Composite rowComposite = new Composite(parent, SWT.NONE); rowComposite.setLayout(rowLayout); rowComposite.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true)); new Label(rowComposite, SWT.WRAP).setText("Unfortunately, there is a problem with the "); Link link = new Link(rowComposite, SWT.WRAP | SWT.NO_FOCUS); link.setText("<A>the Petals Maven preferences</A>"); new Label(rowComposite, SWT.WRAP).setText("."); new Label(parent, SWT.WRAP).setText("Please, make them correct."); link.addSelectionListener(new DefaultSelectionListener() { @Override public void widgetSelected(SelectionEvent e) { try { PreferencesUtil.createPreferenceDialogOn(new Shell(), "com.ebmwebsourcing.petals.services.prefs.maven", null, null).open(); } catch (Exception e1) { PetalsServicesPlugin.log(e1, IStatus.ERROR); } } }); } }; // Prepare the input Comparator<AbstractServiceUnitWizard> comparator = new Comparator<AbstractServiceUnitWizard>() { @Override public int compare(AbstractServiceUnitWizard o1, AbstractServiceUnitWizard o2) { String v1 = o1.getComponentVersionDescription().getComponentVersion(); String v2 = o2.getComponentVersionDescription().getComponentVersion(); return -v1.compareTo(v2); // negative so that the most recent is first } }; final Map<String, Collection<AbstractServiceUnitWizard>> componentNameToHandler = new TreeMap<String, Collection<AbstractServiceUnitWizard>>(); final Map<PetalsKeyWords, Set<String>> keywordToComponentName = new TreeMap<PetalsKeyWords, Set<String>>(); for (AbstractServiceUnitWizard handler : ExtensionManager.INSTANCE.findComponentWizards(this.petalsMode)) { for (PetalsKeyWords keyword : handler.getComponentVersionDescription().getKeyWords()) { Set<String> list = keywordToComponentName.get(keyword); if (list == null) list = new TreeSet<String>(); String componentName = handler.getComponentVersionDescription().getComponentName(); list.add(componentName); keywordToComponentName.put(keyword, list); Collection<AbstractServiceUnitWizard> handlers = componentNameToHandler.get(componentName); if (handlers == null) handlers = new TreeSet<AbstractServiceUnitWizard>(comparator); handlers.add(handler); componentNameToHandler.put(componentName, handlers); } } // Add the selection area final PhantomText searchText = new PhantomText(container, SWT.SINGLE | SWT.BORDER); searchText.setDefaultValue("Search..."); GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).span(2, 1).applyTo(searchText); final TreeViewer componentsViewer = new TreeViewer(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); GridDataFactory.fillDefaults().span(2, 1).hint(380, 300).applyTo(componentsViewer.getTree()); componentsViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String result; if (element instanceof String) { IComponentDescription desc = componentNameToHandler.get(element).iterator().next() .getComponentVersionDescription(); String componentName = desc.getComponentName(); String componentAlias = desc.getComponentAlias(); String annotation = desc.getComponentAnnotation(); StringBuilder sb = new StringBuilder(); if (StringUtils.isEmpty(componentName)) sb.append(componentAlias); // Generic component else sb.append(componentAlias + " - " + componentName); if (!StringUtils.isEmpty(annotation)) sb.append(" ( " + annotation + " )"); result = sb.toString(); } else { result = super.getText(element); } return result; } @Override public Image getImage(Object element) { Image result = null; if (element instanceof PetalsKeyWords) { result = ChoicePage.this.keywordToImage.get(element); } else { IComponentDescription desc = componentNameToHandler.get(element).iterator().next() .getComponentVersionDescription(); result = desc.isBc() ? ChoicePage.this.bcImg : ChoicePage.this.seImg; } return result; } }); componentsViewer.setContentProvider(new DefaultTreeContentProvider() { @Override public Object[] getElements(Object inputElement) { return keywordToComponentName.keySet().toArray(); } @Override public Object[] getChildren(Object parentElement) { Object[] result; if (parentElement instanceof PetalsKeyWords) { Collection<String> componentNames = keywordToComponentName.get(parentElement); result = componentNames == null ? new Object[0] : componentNames.toArray(); } else { result = new Object[0]; } return result; } @Override public boolean hasChildren(Object element) { return element instanceof PetalsKeyWords; } }); componentsViewer.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { boolean result = false; String filter = searchText.getTextValue().trim().toLowerCase(); if (filter.length() == 0) result = true; else if (element instanceof PetalsKeyWords) { Set<String> names = keywordToComponentName.get(element); if (names != null) { for (String s : names) { if (select(viewer, null, s)) { result = true; break; } } } } else if (element instanceof String) result = ((String) element).toLowerCase().contains(filter); return result; } }); componentsViewer.setInput(new Object()); if (keywordToComponentName.size() > 0) componentsViewer.expandToLevel(keywordToComponentName.keySet().iterator().next(), 1); // Display the available versions new Label(container, SWT.NONE).setText("Component Version:"); final ComboViewer versionCombo = new ComboViewer(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); GridData layoutData = new GridData(); layoutData.widthHint = 130; versionCombo.getCombo().setLayoutData(layoutData); versionCombo.setContentProvider(new ArrayContentProvider()); versionCombo.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return ((AbstractServiceUnitWizard) element).getComponentVersionDescription().getComponentVersion(); } }); final Label descriptionLabel = new Label(container, SWT.NONE); GridDataFactory.swtDefaults().span(2, 1).indent(0, 10).applyTo(descriptionLabel); // Selection listeners searchText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { componentsViewer.refresh(); if (searchText.getTextValue().trim().length() == 0) componentsViewer.collapseAll(); else componentsViewer.expandAll(); } }); componentsViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { // Get the selection Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); Collection<?> input; if (o == null || o instanceof PetalsKeyWords) input = Collections.emptyList(); else input = componentNameToHandler.get(o); // Default selection - there is always one versionCombo.setInput(input); versionCombo.getCombo().setVisibleItemCount(input.size() > 0 ? input.size() : 1); if (!input.isEmpty()) { versionCombo.setSelection(new StructuredSelection(input.iterator().next())); versionCombo.getCombo().notifyListeners(SWT.Selection, new Event()); } else { setPageComplete(false); setSelectedNode(null); descriptionLabel.setText(""); descriptionLabel.getParent().layout(); } } }); versionCombo.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { AbstractServiceUnitWizard suWizard = (AbstractServiceUnitWizard) ((IStructuredSelection) event .getSelection()).getFirstElement(); if (suWizard == null) return; setPageComplete(true); setSelectedNode(getWizardNode(suWizard)); String desc = ChoicePage.this.petalsMode == PetalsMode.provides ? suWizard.getComponentVersionDescription().getProvideDescription() : suWizard.getComponentVersionDescription().getConsumeDescription(); descriptionLabel.setText(desc); descriptionLabel.getParent().layout(); } }); // Initialize if (PreferencesManager.isMavenTemplateConfigurationValid()) this.helpTooltip.hide(); componentsViewer.getTree().setFocus(); }
From source file:com.ebmwebsourcing.petals.studio.dev.properties.internal.wizards.GenerateConstantsWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { // Create the composite container and define its layout final Composite container = new Composite(parent, SWT.NONE); GridLayoutFactory.swtDefaults().extendedMargins(15, 15, 15, 10).numColumns(2).applyTo(container); container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Container viewer Label l = new Label(container, SWT.NONE); l.setText("Select the output directory to generate the Java constants."); GridDataFactory.swtDefaults().span(2, 1).applyTo(l); TreeViewer viewer = new TreeViewer(container, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.HIDE_SELECTION); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.heightHint = 100;/*from w w w . j a va 2 s .c o m*/ layoutData.horizontalSpan = 2; viewer.getTree().setLayoutData(layoutData); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setContentProvider(new WorkbenchContentProvider() { /* * (non-Javadoc) * @see org.eclipse.ui.model.BaseWorkbenchContentProvider * #getChildren(java.lang.Object) */ @Override public Object[] getChildren(Object o) { List<Object> children = new ArrayList<Object>(); try { if (o instanceof IJavaProject) { for (IPackageFragmentRoot root : ((IJavaProject) o).getPackageFragmentRoots()) { if (root.getResource() instanceof IContainer) children.add(root); } } else if (o instanceof IWorkspaceRoot) { for (IProject p : ((IWorkspaceRoot) o).getProjects()) { if (!p.isAccessible() || !p.hasNature(JavaCore.NATURE_ID)) continue; IJavaProject jp = JavaCore.create(p); if (jp != null) children.add(jp); } } } catch (CoreException e) { PetalsStudioDevPlugin.log(e, IStatus.ERROR); } return children.toArray(new Object[0]); } /* * (non-Javadoc) * @see org.eclipse.ui.model.BaseWorkbenchContentProvider * #hasChildren(java.lang.Object) */ @Override public boolean hasChildren(Object element) { return getChildren(element).length > 0; } }); // Set page input viewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); if (this.originalSelection != null) { try { IJavaProject jp = JavaCore.create(this.originalSelection); for (IPackageFragmentRoot root : jp.getPackageFragmentRoots()) { if (root.getResource() instanceof IContainer) { GenerateConstantsWizardPage.this.target = root; break; } } } catch (JavaModelException e) { PetalsStudioDevPlugin.log(e, IStatus.ERROR, "This should not happen (check in the handler)."); } } if (this.target != null) { viewer.setSelection(new StructuredSelection(this.target), true); viewer.expandToLevel(this.target, 1); viewer.getTree().notifyListeners(SWT.Selection, new Event()); } // Java meta new Label(container, SWT.NONE).setText("Java Package:"); final Text packageText = new Text(container, SWT.SINGLE | SWT.BORDER); packageText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); packageText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { GenerateConstantsWizardPage.this.javaPackage = ((Text) e.widget).getText().trim(); validate(); } }); new Label(container, SWT.NONE).setText("Java Class Name:"); final Text classText = new Text(container, SWT.SINGLE | SWT.BORDER); classText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); classText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { GenerateConstantsWizardPage.this.className = ((Text) e.widget).getText().trim(); validate(); } }); // Add the missing listeners viewer.addPostSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (o instanceof IPackageFragmentRoot) { GenerateConstantsWizardPage.this.target = (IPackageFragmentRoot) o; String pName = GenerateConstantsWizardPage.this.target.getJavaProject().getProject().getName(); packageText.setText(pName.replaceAll("-", ".") + ".generated"); int index = pName.lastIndexOf('.') + 1; if (index <= 0 || index > pName.length()) pName = "Default"; else pName = pName.substring(index); classText.setText(pName); } else { GenerateConstantsWizardPage.this.target = null; } } }); // Set control setControl(container); }
From source file:com.eclipsesource.rowtemplate.demo.RowTemplateDemo.java
License:Open Source License
private void createTree(Composite parent) { TreeViewer treeViewer = new TreeViewer(parent, getStyle()); exampleControl = treeViewer.getTree(); treeViewer.setContentProvider(new ITreeContentProvider() { @Override// ww w . j ava2 s . c o m public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } @Override public void dispose() { } @Override public boolean hasChildren(Object element) { return ((Person) element).getChildren() != null; } @Override public Object getParent(Object element) { return null; } @Override public Object[] getElements(Object inputElement) { return (Person[]) inputElement; } @Override public Object[] getChildren(Object parentElement) { return ((Person) parentElement).getChildren(); } }); configColumnViewer(treeViewer); treeViewer.getTree().addSelectionListener(new SelectionListener(parent)); treeViewer.getTree().setHeaderVisible(headerVisible.getSelection()); treeViewer.getTree().setLinesVisible(headerVisible.getSelection()); }
From source file:com.eclipsesource.tabris.demos.ui.BooksListPage.java
License:Open Source License
public static TreeViewer createTreeViewer(AbstractPage page, Composite container) { TreeViewer viewer = new TreeViewer(container, SWT.V_SCROLL); viewer.setContentProvider(new BooksContentProvider()); addBookSelectionListener(page, viewer); Tree tree = viewer.getTree();//w w w. j ava2 s . c o m tree.setLinesVisible(true); tree.setData(RWT.MARKUP_ENABLED, Boolean.TRUE); onTree(tree).setTemplate(createRowTemplate()); onTree(tree).setItemHeight(68); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tree); viewer.setLabelProvider(new BooksLabelProvider()); new TreeColumn(tree, SWT.LEFT); new TreeColumn(tree, SWT.LEFT); new TreeColumn(tree, SWT.LEFT); return viewer; }