List of usage examples for org.eclipse.jface.viewers ViewerComparator ViewerComparator
public ViewerComparator()
From source file:org.easotope.client.analysis.part.analysis.sampleselector.SampleSelectorComposite.java
License:Open Source License
public SampleSelectorComposite(ChainedPart chainedPart, Composite parent, int style, final boolean singleSamples, final String selectionKey) { super(chainedPart, parent, style); FormLayout formLayout = new FormLayout(); formLayout.marginTop = GuiConstants.FORM_LAYOUT_MARGIN; formLayout.marginLeft = GuiConstants.FORM_LAYOUT_MARGIN; formLayout.marginRight = GuiConstants.FORM_LAYOUT_MARGIN; formLayout.marginBottom = GuiConstants.FORM_LAYOUT_MARGIN; setLayout(formLayout);/*w w w . j a v a 2 s .c om*/ Label label = new Label(this, SWT.NONE); FormData formData = new FormData(); formData.top = new FormAttachment(0); formData.left = new FormAttachment(0); label.setText(Messages.sampleSelectorComposite_title); Composite composite = new Composite(this, SWT.NONE); formData = new FormData(); formData.top = new FormAttachment(label); formData.left = new FormAttachment(0); formData.right = new FormAttachment(100); formData.bottom = new FormAttachment(100); composite.setLayoutData(formData); composite.setLayout(new FillLayout()); int flags = SWT.VIRTUAL | SWT.BORDER; if (!singleSamples) { flags = flags | SWT.MULTI; } treeViewer = new TreeViewer(composite, flags); treeViewer.setLabelProvider( new MyLabelProvider(Display.getDefault().getSystemColor(SWT.COLOR_TITLE_FOREGROUND), Display.getDefault().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND), ColorCache.getColor(getDisplay(), ColorCache.WHITE))); treeViewer.setContentProvider(new ContentProvider(this)); treeViewer.setUseHashlookup(true); treeViewer.setComparator(new ViewerComparator()); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Iterator<?> iterator = structuredSelection.iterator(); UserProjSampleSelection newSelection = new UserProjSampleSelection(); while (iterator.hasNext()) { Object selectionObj = iterator.next(); if (selectionObj instanceof UserElement) { TreeElement treeElement = (TreeElement) selectionObj; newSelection.addUser(treeElement.getId()); } else if (selectionObj instanceof ProjectElement) { TreeElement treeElement = (TreeElement) selectionObj; newSelection.addProject(treeElement.getId()); } else if (selectionObj instanceof SampleElement) { TreeElement treeElement = (TreeElement) selectionObj; newSelection.addSample(treeElement.getId()); } } boolean hasNonSamples = !newSelection.getUserIds().isEmpty() || !newSelection.getProjectIds().isEmpty(); if (singleSamples && hasNonSamples) { treeViewer.setSelection(null); propogateSelection(selectionKey, null); } else { propogateSelection(selectionKey, newSelection); } } } }); TreeElement root = new TreeElement(0, null); root.setNameDateAndHasChildren("root", 0, true); treeElementLookup.put(ROOT, root); treeViewer.setInput(root); UserCache.getInstance().addListener(this); InputCache.getInstance().addListener(this); LoginInfoCache.getInstance().addListener(this); int commandId = UserCache.getInstance().userListGet(this); addWaitingReminder(commandId, ROOT); }
From source file:org.easotope.client.rawdata.navigator.sample.SampleNavigator.java
License:Open Source License
@PostConstruct public void postConstruct() { treeViewer = new TreeViewer(getParent(), SWT.VIRTUAL); treeViewer.setContentProvider(new ContentProvider(this)); treeViewer.setUseHashlookup(true);/*from w ww . j a v a 2s. c o m*/ treeViewer.setComparator(new ViewerComparator()); treeViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { IStructuredSelection thisSelection = (IStructuredSelection) event.getSelection(); Object selectedNode = thisSelection.getFirstElement(); if (selectedNode instanceof ProjectElement) { ProjectElement projectElement = (ProjectElement) selectedNode; HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put(SamplePart.INPUTURI_PARAM_USER, String.valueOf(projectElement.getUserElement().getId())); parameters.put(ProjectPart.INPUTURI_PARAM_PROJECT, String.valueOf(projectElement.getId())); PartManager.openPart(SampleNavigator.this, ProjectPart.ELEMENTID_BASE, ProjectPart.class.getName(), parameters, true); } else if (selectedNode instanceof SampleElement) { SampleElement sampleElement = (SampleElement) selectedNode; HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put(SamplePart.INPUTURI_PARAM_USER, String.valueOf(sampleElement.getProjectElement().getUserElement().getId())); parameters.put(SamplePart.INPUTURI_PARAM_PROJECT, String.valueOf(sampleElement.getProjectElement().getId())); parameters.put(SamplePart.INPUTURI_PARAM_SAMPLE, String.valueOf(sampleElement.getId())); PartManager.openPart(SampleNavigator.this, SamplePart.ELEMENTID_BASE, SamplePart.class.getName(), parameters, true); } else if (selectedNode instanceof ReplicateElement) { ReplicateElement replicateElement = (ReplicateElement) selectedNode; HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put(SampleReplicatePart.INPUTURI_PARAM_REPLICATE, String.valueOf(replicateElement.getId())); PartManager.openPart(SampleNavigator.this, SampleReplicatePart.ELEMENTID_BASE, SampleReplicatePart.class.getName(), parameters, true); } } }); TreeElement root = new TreeElement(0, null); root.setNameDateAndHasChildren("root", 0, true); treeElementLookup.put(ROOT, root); treeViewer.setInput(root); createProject = new Action() { @Override public void run() { createProject(); } }; createProject.setText(Messages.sampleNavigator_addProject); editProject = new Action() { @Override public void run() { editProject(); } }; editProject.setText(Messages.sampleNavigator_editProject); createSample = new Action() { @Override public void run() { createSample(); } }; createSample.setText(Messages.sampleNavigator_addSample); editSample = new Action() { @Override public void run() { editSample(); } }; editSample.setText(Messages.sampleNavigator_editSample); createReplicate = new Action() { @Override public void run() { createReplicate(); } }; createReplicate.setText(Messages.sampleNavigator_addReplicate); editReplicate = new Action() { @Override public void run() { editReplicate(); } }; editReplicate.setText(Messages.sampleNavigator_editReplicate); MenuManager menuMgr = new MenuManager(); menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(new IMenuListener() { @Override public void menuAboutToShow(IMenuManager manager) { fillContextMenu(manager); } }); Menu menu = menuMgr.createContextMenu(treeViewer.getControl()); treeViewer.getControl().setMenu(menu); UserCache.getInstance().addListener(this); InputCache.getInstance().addListener(this); LoginInfoCache.getInstance().addListener(this); int commandId = UserCache.getInstance().userListGet(this); addWaitingReminder(commandId, ROOT); }
From source file:org.ebayopensource.turmeric.eclipse.ui.actions.SOASortAction.java
License:Open Source License
/** * Instantiates a new sOA sort action./* w w w. jav a2s . c o m*/ * * @param viewer the viewer * @param sorter the sorter */ public SOASortAction(StructuredViewer viewer, ViewerComparator sorter) { super("", IAction.AS_CHECK_BOX); setText(getTitle()); setToolTipText(getToolTip()); setImageDescriptor(UIActivator.getImageDescriptor("icons/sort.gif")); fViewer = viewer; // Set the comparator // If one was not specified, use the default if (sorter == null) { fComparator = new ViewerComparator(); } else { fComparator = sorter; } // Determine if the viewer is already sorted // Note: Most likely the default comparator is null if (viewer.getComparator() != sorter) { fSorted = false; } else { fSorted = true; } // Set the status of this action depending on whether it is sorted or // not setChecked(fSorted); }
From source file:org.ebayopensource.turmeric.eclipse.ui.views.registry.RegistryView.java
License:Open Source License
/** * Gets the library comparator./*from w w w. java2 s .c o m*/ * * @return the library comparator */ public ViewerComparator getLibraryComparator() { final ViewerComparator comparator = new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { if (e1 instanceof LibraryType && e2 instanceof LibraryType) { return ((LibraryType) e1).getName().compareTo(((LibraryType) e2).getName()); } return String.CASE_INSENSITIVE_ORDER.compare(e1.toString(), e2.toString()); } }; return comparator; }
From source file:org.ebayopensource.vjet.eclipse.internal.ui.preferences.InstalledSdksBlock.java
License:Open Source License
/** * Sorts by VM type, and name within type. *//*from www .j a va 2 s .c o m*/ private void sortByType() { fVMList.setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof ISdkEnvironment) && (e2 instanceof ISdkEnvironment)) { ISdkEnvironment left = (ISdkEnvironment) e1; ISdkEnvironment right = (ISdkEnvironment) e2; String leftType = left.getSdkName(); String rightType = right.getSdkName(); int res = leftType.compareToIgnoreCase(rightType); if (res != 0) { return res; } return left.getSdkName().compareToIgnoreCase(right.getSdkName()); } return super.compare(viewer, e1, e2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fSortColumn = 3; }
From source file:org.ebayopensource.vjet.eclipse.internal.ui.preferences.InstalledSdksBlock.java
License:Open Source License
/** * Sorts by VM name./*from w ww . jav a2 s. c om*/ */ private void sortByName() { fVMList.setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof ISdkEnvironment) && (e2 instanceof ISdkEnvironment)) { ISdkEnvironment left = (ISdkEnvironment) e1; ISdkEnvironment right = (ISdkEnvironment) e2; return left.getSdkName().compareToIgnoreCase(right.getSdkName()); } return super.compare(viewer, e1, e2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fSortColumn = 1; }
From source file:org.ebayopensource.vjet.eclipse.internal.ui.preferences.InstalledSdksBlock.java
License:Open Source License
/** * Sorts by VM location.//from w w w . j a v a2 s . c om */ private void sortByLocation() { fVMList.setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof ISdkEnvironment) && (e2 instanceof ISdkEnvironment)) { ISdkEnvironment left = (ISdkEnvironment) e1; ISdkEnvironment right = (ISdkEnvironment) e2; return left.getSdkName().compareToIgnoreCase(right.getSdkName()); } return super.compare(viewer, e1, e2); } public boolean isSorterProperty(Object element, String property) { return true; } }); fSortColumn = 2; }
From source file:org.eclipse.acceleo.internal.ide.ui.dialog.TreeSelectionComposite.java
License:Open Source License
/** * Returns a new drill down viewer for this dialog. * //ww w .j a va 2 s .co m * @param heightHint * height hint for the drill down composite */ protected void createTreeViewer(int heightHint) { // Create drill down. DrillDownComposite drillDown = new DrillDownComposite(this, SWT.BORDER); GridData spec = new GridData(SWT.FILL, SWT.FILL, true, true); spec.widthHint = SIZING_SELECTION_PANE_WIDTH; spec.heightHint = heightHint; drillDown.setLayoutData(spec); // Create tree viewer inside drill down. treeViewer = new TreeViewer(drillDown, SWT.NONE); drillDown.setChildTree(treeViewer); treeViewer.setContentProvider(contentProvider); treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()); treeViewer.setComparator(new ViewerComparator()); treeViewer.setUseHashlookup(true); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); resourceSelectionChanged((IResource) selection.getFirstElement()); // allow null } }); treeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { Object item = ((IStructuredSelection) selection).getFirstElement(); if (item == null) { return; } if (treeViewer.getExpandedState(item)) { treeViewer.collapseToLevel(item, 1); } else { treeViewer.expandToLevel(item, 1); } } } }); // This has to be done after the viewer has been laid out treeViewer.setInput(ResourcesPlugin.getWorkspace()); }
From source file:org.eclipse.acceleo.profiler.presentation.ProfilerEditor.java
License:Open Source License
/** * {@inheritDoc}/*from w w w . j a v a2 s.c o m*/ * * @see org.eclipse.emf.ecore.presentation.EcoreEditor#createPages() */ @Override public void createPages() { super.createPages(); selectionViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { final Object selected = ((TreeSelection) event.getSelection()).getFirstElement(); if (selected instanceof ProfileEntry) { // TODO open template editor } } }); selectionViewer.setComparator(new ViewerComparator() { /* (non-Javadoc) */ @Override public int compare(Viewer viewer, Object e1, Object e2) { int ret = 0; if (e1 instanceof ProfileEntry && e2 instanceof ProfileEntry) { ProfileEntry entry1 = (ProfileEntry) e1; ProfileEntry entry2 = (ProfileEntry) e2; switch (sortStatus.getSortOrder()) { case ProfilerSortStatus.SORT_BY_CREATION_TIME: ret = (int) (entry1.getCreateTime() - entry2.getCreateTime()); break; case ProfilerSortStatus.SORT_BY_TIME: ret = (int) (entry2.getDuration() - entry1.getDuration()); break; default: // nothing to do here break; } } return ret; } }); selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory) { @Override public Object[] getChildren(Object object) { if (object instanceof ProfileEntry) { return ((ProfileEntry) object).getCallees().toArray(); } return super.getChildren(object); } @Override public Object[] getElements(Object object) { return getChildren(object); } }); IToolBarManager toolBarManager = getActionBars().getToolBarManager(); toolBarManager.add(new ProfilerSortAction(sortStatus, selectionViewer)); }
From source file:org.eclipse.acute.dotnetnew.DotnetNewWizardPage.java
License:Open Source License
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); setControl(container);// w w w .java 2s.c o m container.setLayout(new GridLayout(4, false)); Label locationLabel = new Label(container, SWT.NONE); locationLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); locationLabel.setText(Messages.DotnetNewWizardPage_location); Image errorImage = FieldDecorationRegistry.getDefault() .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage(); locationText = new Text(container, SWT.BORDER); locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); locationControlDecoration = new ControlDecoration(locationText, SWT.TOP | SWT.LEFT); locationControlDecoration.setImage(errorImage); locationControlDecoration.setShowOnlyOnFocus(true); locationText.addModifyListener(e -> { updateDirectory(locationText.getText()); setPageComplete(isPageComplete()); }); Button browseButton = new Button(container, SWT.NONE); browseButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); browseButton.setText(Messages.DotnetNewWizardPage_browse); browseButton.addSelectionListener(widgetSelectedAdapter(e -> { DirectoryDialog dialog = new DirectoryDialog(browseButton.getShell()); String path = dialog.open(); if (path != null) { updateDirectory(path); } setPageComplete(isPageComplete()); })); Composite linesAboveLink = new Composite(container, SWT.NONE); GridData linesAboveLinkLayoutData = new GridData(SWT.FILL, SWT.FILL); linesAboveLinkLayoutData.heightHint = linesAboveLinkLayoutData.widthHint = 30; linesAboveLink.setLayoutData(linesAboveLinkLayoutData); linesAboveLink.addPaintListener(e -> { e.gc.setForeground(((Control) e.widget).getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); e.gc.drawLine(0, e.height / 2, e.width / 2, e.height / 2); e.gc.drawLine(e.width / 2, e.height / 2, e.width / 2, e.height); }); new Label(container, SWT.NONE); new Label(container, SWT.NONE); new Label(container, SWT.NONE); linkButton = new Button(container, SWT.TOGGLE); linkButton.setToolTipText(Messages.DotnetNewWizardPage_linkNames); linkButton.setSelection(true); try (InputStream iconStream = getClass().getResourceAsStream("/icons/link_obj.png")) { //$NON-NLS-1$ linkImage = new Image(linkButton.getDisplay(), iconStream); linkButton.setImage(linkImage); } catch (IOException e1) { AcutePlugin.logError(e1); } linkButton.addSelectionListener(widgetSelectedAdapter(s -> { isDirectoryAndProjectLinked = linkButton.getSelection(); projectNameText.setEnabled(!linkButton.getSelection()); updateProjectName(); })); Label projectNameLabel = new Label(container, SWT.NONE); projectNameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); projectNameLabel.setText(Messages.DotnetNewWizardPage_projectName); projectNameText = new Text(container, SWT.BORDER); projectNameText.setEnabled(false); projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); projectNameControlDecoration = new ControlDecoration(projectNameText, SWT.TOP | SWT.LEFT); projectNameControlDecoration.setImage(errorImage); projectNameControlDecoration.setShowOnlyOnFocus(true); projectNameText.addModifyListener(e -> { updateProjectName(); setPageComplete(isPageComplete()); }); Composite linesBelowLink = new Composite(container, SWT.NONE); GridData linesBelowLinkLayoutData = new GridData(SWT.FILL, SWT.FILL); linesBelowLinkLayoutData.heightHint = linesBelowLinkLayoutData.widthHint = 30; linesBelowLink.setLayoutData(linesAboveLinkLayoutData); linesBelowLink.addPaintListener(e -> { e.gc.setForeground(((Control) e.widget).getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); e.gc.drawLine(0, e.height / 2, e.width / 2, e.height / 2); e.gc.drawLine(e.width / 2, e.height / 2, e.width / 2, 0); }); new Label(container, SWT.NONE).setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 4, 1)); Label projectTemplateLabel = new Label(container, SWT.NONE); projectTemplateLabel.setText(Messages.DotnetNewWizardPage_projectTemplate); List list = new List(container, SWT.V_SCROLL | SWT.BORDER); GridData listBoxData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); list.setLayoutData(listBoxData); templateViewer = new ListViewer(list); templateViewer.setContentProvider(new ArrayContentProvider()); templateViewer.setComparator(new ViewerComparator()); // default uses getLabel()/toString() templateViewer.addSelectionChangedListener(e -> { setPageComplete(isPageComplete()); }); templateControlDecoration = new ControlDecoration(templateViewer.getControl(), SWT.TOP | SWT.LEFT); templateControlDecoration.setImage(errorImage); updateTemplateList(); //Update Template List with preferences change IPreferenceStore store = AcutePlugin.getDefault().getPreferenceStore(); updateTemplatesListener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(AcutePreferenceInitializer.explicitDotnetPathPreference)) { updateTemplateList(); } } }; store.addPropertyChangeListener(updateTemplatesListener); new Label(container, SWT.NONE); new Label(container, SWT.NONE); Link preferencesLink = new Link(container, SWT.NONE); preferencesLink.setText(Messages.DotnetNewWizardPage_dotnetPreferencesLink); preferencesLink.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1)); preferencesLink.addSelectionListener(widgetSelectedAdapter(s -> Display.getDefault().asyncExec(() -> { PreferenceDialog preferenceDialog = PreferencesUtil.createPreferenceDialogOn(getShell(), AcutePreferencePage.PAGE_ID, new String[] { AcutePreferencePage.PAGE_ID }, null); preferenceDialog.setBlockOnOpen(false); preferenceDialog.open(); }))); new Label(container, SWT.NONE).setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false, 4, 1)); Composite workingSetComposite = new Composite(container, SWT.NONE); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1); workingSetComposite.setLayoutData(layoutData); workingSetComposite.setLayout(new GridLayout(1, false)); String[] workingSetIds = new String[] { "org.eclipse.ui.resourceWorkingSetPage" }; //$NON-NLS-1$ IStructuredSelection wsSel = null; if (this.workingSets != null) { wsSel = new StructuredSelection(this.workingSets.toArray()); } this.workingSetsGroup = new WorkingSetGroup(workingSetComposite, wsSel, workingSetIds); if (directory != null) { updateDirectory(directory.getAbsolutePath()); } }