List of usage examples for org.eclipse.jface.viewers ViewerComparator ViewerComparator
public ViewerComparator()
From source file:net.tourbook.ui.views.tourCatalog.WizardPageReferenceTour.java
License:Open Source License
private void createRefTourTableViewer(final Composite parent) { final TableLayoutComposite layouter = new TableLayoutComposite(parent, SWT.NONE); final GridData gridData = new GridData(GridData.FILL_BOTH); gridData.widthHint = convertWidthInCharsToPixels(30); layouter.setLayoutData(gridData);//from www. j av a2 s .c o m final Table table = new Table(layouter, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK); table.setLinesVisible(false); TableColumn column; column = new TableColumn(table, SWT.NONE); column.setText(Messages.tourCatalog_wizard_Column_tour); layouter.addColumnData(new ColumnWeightData(1, false)); _refTourViewer = new CheckboxTableViewer(table); _refTourViewer.setContentProvider(new RefTourContentProvider()); _refTourViewer.setLabelProvider(new RefTourLabelProvider()); _refTourViewer.setComparator(new ViewerComparator() { @SuppressWarnings("unchecked") @Override public int compare(final Viewer viewer, final Object e1, final Object e2) { return getComparator().compare(((TourReference) e1).getLabel(), ((TourReference) e2).getLabel()); } }); _refTourViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { showReferenceTour(event); } }); _refTourViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(final CheckStateChangedEvent event) { validatePage(); } }); _refTourViewer.setInput(this); }
From source file:net.yatomiya.e4.ui.internal.workbench.renderers.swt.BasicPartList.java
License:Open Source License
public BasicPartList(Shell parent, int shellStyle, int treeStyler, EPartService partService, MElementContainer<?> input, StackRenderer renderer, boolean mru) { super(parent, shellStyle, treeStyler); this.partService = partService; this.input = input; this.renderer = renderer; // this.saveHandler = saveHandler; if (mru && getTableViewer() != null) { getTableViewer().setComparator(new ViewerComparator() { @Override//from w w w. jav a 2 s .c o m public int category(Object element) { if (element instanceof MPart) { MPart part = (MPart) element; CTabItem item = BasicPartList.this.renderer.findItemForPart(part); if (item != null && !item.isShowing()) { return -1; } } return 0; } }); } }
From source file:nexcore.tool.uml.ui.project.explorer.dialog.ContainerSelectionGroup.java
License:Open Source License
/** * Returns a new drill down viewer for this dialog. * //w ww . ja v a 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); ContainerContentProvider cp = new ContainerContentProvider(dialogType); cp.showClosedProjects(showClosedProjects); treeViewer.setContentProvider(cp); 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(); Object obj = selection.getFirstElement(); if (obj instanceof File) { File file = (File) obj; obj = file.getParent(); } containerSelectionChanged((IContainer) obj); // 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:no.javatime.inplace.ui.views.BundleListLabelProvider.java
License:Open Source License
private ViewerComparator getViewerComparator(byte sortType) { if (sortType == MODE) { return new ViewerComparator() { @Override/*from ww w. j ava2 s . c o m*/ @SuppressWarnings("unchecked") public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof BundleProperties) && (e2 instanceof BundleProperties)) { return getComparator().compare(((BundleProperties) e1).getActivationMode(), ((BundleProperties) e2).getActivationMode()) * MODE_ORDER; } return 0; } }; } else if (sortType == STATE) { return new ViewerComparator() { @Override @SuppressWarnings("unchecked") public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof BundleProperties) && (e2 instanceof BundleProperties)) { return getComparator().compare(((BundleProperties) e1).getBundleState(), ((BundleProperties) e2).getBundleState()) * STATE_ORDER; } return 0; } }; } else if (sortType == TRANSITION) { return new ViewerComparator() { @Override @SuppressWarnings("unchecked") public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof BundleProperties) && (e2 instanceof BundleProperties)) { return getComparator().compare(((BundleProperties) e1).getLastTransition(), ((BundleProperties) e2).getLastTransition()) * TRANSITION_ORDER; } return 0; } }; } else if (sortType == STATUS) { return new ViewerComparator() { @Override @SuppressWarnings("unchecked") public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof BundleProperties) && (e2 instanceof BundleProperties)) { return getComparator().compare(((BundleProperties) e1).getBundleStatus(), ((BundleProperties) e2).getBundleStatus()) * STATUS_ORDER; } return 0; } }; } else { // sort type is BUNDLE return new ViewerComparator() { @Override @SuppressWarnings("unchecked") public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof BundleProperties) && (e2 instanceof BundleProperties)) { return getComparator().compare(((BundleProperties) e1).getSymbolicName(), ((BundleProperties) e2).getSymbolicName()) * BUNDLE_ORDER; } return 0; } }; } }
From source file:oic.simulator.clientcontroller.view.LogView.java
License:Open Source License
private void createColumnComparators() { dateComparator = new ViewerComparator() { @Override/* w w w.jav a 2 s . co m*/ public int compare(Viewer viewer, Object e1, Object e2) { LogEntry l1 = (LogEntry) e1; LogEntry l2 = (LogEntry) e2; return l1.getDate().compareTo(l2.getDate()) * sortDirection; } }; severityComparator = new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { LogEntry l1 = (LogEntry) e1; LogEntry l2 = (LogEntry) e2; if (l1.getSeverity() < l2.getSeverity()) { return -1 * sortDirection; } if (l1.getSeverity() > l2.getSeverity()) { return 1 * sortDirection; } return 0; } }; messageComparator = new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { LogEntry l1 = (LogEntry) e1; LogEntry l2 = (LogEntry) e2; return l1.getMessage().compareTo(l2.getMessage()) * sortDirection; } }; }
From source file:org.absmodels.abs.plugin.wizards.composites.CompositeGroup.java
License:Open Source License
protected void setUpTreeViewer() { treeViewer.setComparator(new ViewerComparator()); treeViewer.setUseHashlookup(true);//from w ww . j av a2 s. com setUpTreeListeners(); // This has to be done after the viewer has been laid out treeViewer.setInput(ResourcesPlugin.getWorkspace()); }
From source file:org.apache.directory.studio.apacheds.configuration.editor.PasswordPoliciesMasterDetailsBlock.java
License:Apache License
/** * {@inheritDoc}//ww w .j a v a 2 s.c om */ protected void createMasterPart(final IManagedForm managedForm, Composite parent) { FormToolkit toolkit = managedForm.getToolkit(); // Creating the Section Section section = toolkit.createSection(parent, Section.TITLE_BAR); section.setText(Messages.getString("PasswordPoliciesMasterDetailsBlock.AllPasswordPolicies")); //$NON-NLS-1$ section.marginWidth = 10; section.marginHeight = 5; Composite client = toolkit.createComposite(section, SWT.WRAP); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = false; layout.marginWidth = 2; layout.marginHeight = 2; client.setLayout(layout); toolkit.paintBordersFor(client); section.setClient(client); // Creating the Table and Table Viewer Table table = toolkit.createTable(client, SWT.NULL); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2); gd.heightHint = 20; gd.widthHint = 100; table.setLayoutData(gd); final SectionPart spart = new SectionPart(section); managedForm.addPart(spart); viewer = new TableViewer(table); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { managedForm.fireSelectionChanged(spart, event.getSelection()); } }); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof PasswordPolicyBean) { PasswordPolicyBean passwordPolicy = (PasswordPolicyBean) element; if (passwordPolicy.isEnabled()) { return NLS.bind("{0} (enabled)", passwordPolicy.getPwdId()); } else { return NLS.bind("{0} (disabled)", passwordPolicy.getPwdId()); } } return super.getText(element); } public Image getImage(Object element) { if (element instanceof PasswordPolicyBean) { PasswordPolicyBean passwordPolicy = (PasswordPolicyBean) element; if (PasswordPoliciesPage.isDefaultPasswordPolicy(passwordPolicy)) { return ApacheDS2ConfigurationPlugin.getDefault() .getImage(ApacheDS2ConfigurationPluginConstants.IMG_PASSWORD_POLICY_DEFAULT); } else { return ApacheDS2ConfigurationPlugin.getDefault() .getImage(ApacheDS2ConfigurationPluginConstants.IMG_PASSWORD_POLICY); } } return super.getImage(element); } }); viewer.setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof PasswordPolicyBean) && (e2 instanceof PasswordPolicyBean)) { PasswordPolicyBean passwordPolicy1 = (PasswordPolicyBean) e1; PasswordPolicyBean passwordPolicy2 = (PasswordPolicyBean) e2; String passwordPolicy1Id = passwordPolicy1.getPwdId(); String passwordPolicy2Id = passwordPolicy2.getPwdId(); if ((passwordPolicy1Id != null) && (passwordPolicy2Id != null)) { return passwordPolicy1Id.compareTo(passwordPolicy2Id); } } return super.compare(viewer, e1, e2); } }); // Creating the button(s) addButton = toolkit.createButton(client, Messages.getString("PasswordPoliciesMasterDetailsBlock.Add"), //$NON-NLS-1$ SWT.PUSH); addButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); deleteButton = toolkit.createButton(client, Messages.getString("PasswordPoliciesMasterDetailsBlock.Delete"), //$NON-NLS-1$ SWT.PUSH); deleteButton.setEnabled(false); deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); initFromInput(); addListeners(); }
From source file:org.apache.directory.studio.apacheds.configuration.editor.ReplicationMasterDetailsBlock.java
License:Apache License
/** * {@inheritDoc}//www . j a v a 2s . c o m */ protected void createMasterPart(final IManagedForm managedForm, Composite parent) { FormToolkit toolkit = managedForm.getToolkit(); sashForm.setOrientation(SWT.HORIZONTAL); // Creating the Section Section section = toolkit.createSection(parent, Section.TITLE_BAR); section.setText("All Replication Consummers"); section.marginWidth = 10; section.marginHeight = 5; Composite client = toolkit.createComposite(section, SWT.WRAP); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = false; layout.marginWidth = 2; layout.marginHeight = 2; client.setLayout(layout); toolkit.paintBordersFor(client); section.setClient(client); // Creating the Table and Table Viewer Table table = toolkit.createTable(client, SWT.NULL); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2); gd.heightHint = 20; gd.widthHint = 100; table.setLayoutData(gd); final SectionPart spart = new SectionPart(section); managedForm.addPart(spart); viewer = new TableViewer(table); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { managedForm.fireSelectionChanged(spart, event.getSelection()); } }); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof ReplConsumerBean) { ReplConsumerBean consumer = (ReplConsumerBean) element; return consumer.getReplConsumerId(); } return super.getText(element); } public Image getImage(Object element) { if (element instanceof ReplConsumerBean) { return ApacheDS2ConfigurationPlugin.getDefault() .getImage(ApacheDS2ConfigurationPluginConstants.IMG_REPLICATION_CONSUMER); } return super.getImage(element); } }); viewer.setComparator(new ViewerComparator() { public int compare(Viewer viewer, Object e1, Object e2) { if ((e1 instanceof ReplConsumerBean) && (e2 instanceof ReplConsumerBean)) { ReplConsumerBean o1 = (ReplConsumerBean) e1; ReplConsumerBean o2 = (ReplConsumerBean) e2; String id1 = o1.getReplConsumerId(); String id2 = o2.getReplConsumerId(); if ((id1 != null) && (id2 != null)) { return id1.compareTo(id2); } } return super.compare(viewer, e1, e2); } }); // Creating the button(s) addButton = toolkit.createButton(client, "Add", SWT.PUSH); addButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); deleteButton = toolkit.createButton(client, "Delete", SWT.PUSH); deleteButton.setEnabled(false); deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false)); initFromInput(); addListeners(); }
From source file:org.apache.easyant4e.wizards.EasyAntImportWizardPage.java
License:Apache License
/** * Create the checkbox list for the found projects. * //from ww w . j a v a 2s . c o m * @param workArea */ private void createProjectsList(Composite workArea) { Label title = new Label(workArea, SWT.NONE); title.setText("EasyAnt Projects:"); Composite listComposite = new Composite(workArea, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; layout.marginWidth = 0; layout.makeColumnsEqualWidth = false; listComposite.setLayout(layout); listComposite.setLayoutData( new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH)); projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER); GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); projectsList.getControl().setLayoutData(listData); projectsList.setContentProvider(new ITreeContentProvider() { public Object[] getChildren(Object parentElement) { return null; } public Object[] getElements(Object inputElement) { return getValidProjects(); } public boolean hasChildren(Object element) { return false; } public Object getParent(Object element) { return null; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); projectsList.setLabelProvider(new LabelProvider() { public String getText(Object element) { return ((ProjectRecord) element).getProjectLabel(); } }); projectsList.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { setPageComplete(projectsList.getCheckedElements().length > 0); } }); projectsList.setInput(this); projectsList.setComparator(new ViewerComparator()); createSelectionButtons(listComposite); }
From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ClasspathSection.java
License:Apache License
private void createViewer(Table bundleTable) { viewer = new ProjectTableViewer(bundleTable); viewer.setContentProvider(new DefaultTableProvider() { public Object[] getElements(Object inputElement) { ArrayList<IClasspathEntry> cp = new ArrayList<IClasspathEntry>(); for (IClasspathEntry cpe : JavaHelper.findClasspathEntries(getBundle())) { cp.add(cpe);/*w w w . j a va2s .c o m*/ } Collections.sort(cp, new Comparator<IClasspathEntry>() { public int compare(IClasspathEntry o1, IClasspathEntry o2) { return o1.toString().compareTo(o2.toString()); } }); return cp.toArray(); } }); viewer.setComparator(new ViewerComparator() { @Override public int category(Object element) { return index((IClasspathEntry) element); } }); }