Java Code Examples for org.eclipse.jface.viewers.ViewerComparator

The following are top voted examples for showing how to use org.eclipse.jface.viewers.ViewerComparator. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: termsuite-ui   File: BlockedJobsDialog.java   Source Code and License 7 votes vote down vote up
/**
 * This method creates a dialog area in the parent composite and displays a
 * progress tree viewer of the running jobs.
 *
 * @param parent
 *            The parent Composite.
 */
void showJobDetails(Composite parent) {
	viewer = new DetailedProgressViewer(parent, SWT.MULTI | SWT.H_SCROLL
			| SWT.V_SCROLL | SWT.BORDER, progressService, finishedJobs);
	viewer.setComparator(new ViewerComparator() {
		@Override
		@SuppressWarnings("unchecked")
           public int compare(Viewer testViewer, Object e1, Object e2) {
			return ((Comparable<Object>) e1).compareTo(e2);
		}
	});
	ProgressViewerContentProvider provider = getContentProvider();
	viewer.setContentProvider(provider);
	viewer.setInput(provider);
	viewer.setLabelProvider(new ProgressLabelProvider());
	GridData data = new GridData(GridData.GRAB_HORIZONTAL
			| GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
	data.horizontalSpan = 2;
	int heightHint = convertHeightInCharsToPixels(10);
	data.heightHint = heightHint;
	viewer.getControl().setLayoutData(data);
}
 
Example 2
Project: depan   File: NodeStatsTableControl.java   Source Code and License 7 votes vote down vote up
private void setSortColumn(
    TreeColumn column, int colIndex, int direction) {

  ViewerComparator sorter = buildColumnSorter(colIndex);
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Tree tree = propViewer.getTree();
  tree.setSortColumn(column);
  tree.setSortDirection(direction);

  propViewer.setComparator(sorter);
}
 
Example 3
Project: depan   File: NodeDisplayTableControl.java   Source Code and License 7 votes vote down vote up
private void setSortColumn(
    TreeColumn column, int colIndex, int direction) {

  ViewerComparator sorter = buildColumnSorter(colIndex);
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Tree tree = propViewer.getTree();
  tree.setSortColumn(column);
  tree.setSortDirection(direction);

  propViewer.setComparator(sorter);
}
 
Example 4
Project: Equella   File: JPFProjectSelectionDialog.java   Source Code and License 6 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent)
{
	Composite dialogArea = (Composite) super.createDialogArea(parent);
	Composite composite = new Composite(dialogArea, SWT.NONE);
	createMessageArea(composite);
	listViewer = new TableViewer(composite, SWT.TOP | SWT.BORDER);

	GridData data = new GridData(GridData.FILL_BOTH);
	data.widthHint = 400;
	data.heightHint = 400;
	listViewer.getTable().setLayoutData(data);
	listViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
	listViewer.setContentProvider(new JarProjectContentProvider(null));
	listViewer.setComparator(new ViewerComparator());
	listViewer.setInput(ResourcesPlugin.getWorkspace());
	applyDialogFont(composite);

	listViewer.setSelection(new StructuredSelection(initialSelection));
	GridLayoutFactory.fillDefaults().generateLayout(composite);
	return dialogArea;
}
 
Example 5
Project: egradle   File: EGradleLaunchConfigurationPropertiesTab.java   Source Code and License 6 votes vote down vote up
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	if (newInput == null) {
		return;
	}
	if (viewer instanceof TableViewer) {
		TableViewer tableViewer = (TableViewer) viewer;
		if (tableViewer.getTable().isDisposed()) {
			return;
		}
		tableViewer.setComparator(new ViewerComparator() {
			public int compare(Viewer iviewer, Object e1, Object e2) {
				if (e1 == null) {
					return -1;
				} else if (e2 == null) {
					return 1;
				} else {
					return ((PropertyVariable) e1).getName()
							.compareToIgnoreCase(((PropertyVariable) e2).getName());
				}
			}
		});
	}
}
 
Example 6
Project: google-cloud-eclipse   File: MiniSelector.java   Source Code and License 6 votes vote down vote up
private void create(Composite parent) {
  displayExecutor = DisplayExecutor.create(parent.getDisplay());
  comboViewer = new ComboViewer(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
  comboViewer.setComparator(new ViewerComparator());
  comboViewer.setLabelProvider(new LabelProvider() {
    @Override
    public String getText(Object element) {
      if (element instanceof GcpProject) {
        GcpProject project = (GcpProject) element;
        return project.getName() + " (" + project.getId() + ")";
      }
      return super.getText(element);
    }
  });
  comboViewer.setContentProvider(ArrayContentProvider.getInstance());
  comboViewer.setInput(EMPTY_PROJECTS);
  parent.addDisposeListener(new DisposeListener() {
    @Override
    public void widgetDisposed(DisposeEvent event) {
      cancelFetch();
    }
  });

  fetch();
}
 
Example 7
Project: google-cloud-eclipse   File: ProjectSelector.java   Source Code and License 6 votes vote down vote up
public ProjectSelector(Composite parent) {
  super(parent, SWT.NONE);
  GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(this);

  Composite tableComposite = new Composite(this, SWT.NONE);
  TableColumnLayout tableColumnLayout = new TableColumnLayout();
  tableComposite.setLayout(tableColumnLayout);
  GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);
  viewer = new TableViewer(tableComposite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
  createColumns(tableColumnLayout);
  viewer.getTable().setHeaderVisible(true);
  viewer.getTable().setLinesVisible(false);

  input = WritableList.withElementType(GcpProject.class);
  projectProperties = PojoProperties.values(new String[] {"name", "id"}); //$NON-NLS-1$ //$NON-NLS-2$
  ViewerSupport.bind(viewer, input, projectProperties);
  viewer.setComparator(new ViewerComparator());

  Composite linkComposite = new Composite(this, SWT.NONE);
  statusLink = new Link(linkComposite, SWT.WRAP);
  statusLink.addSelectionListener(
      new OpenUriSelectionListener(new ErrorDialogErrorHandler(getShell())));
  statusLink.setText("");
  GridDataFactory.fillDefaults().span(2, 1).applyTo(linkComposite);
  GridLayoutFactory.fillDefaults().generateLayout(linkComposite);
}
 
Example 8
Project: Source   File: MappingView.java   Source Code and License 6 votes vote down vote up
/**
 * Add the mapping base {@link ComboViewer} to the given header {@link Composite}.
 * 
 * @param headerComposite
 *            the header {@link Composite}
 * @return the mapping base {@link ComboViewer}
 */
private ComboViewer addMappingBaseCombo(Composite headerComposite) {

	final Label selectMappingBaseLabel = new Label(headerComposite, SWT.NONE);
	selectMappingBaseLabel.setToolTipText("Select a mapping base.");
	selectMappingBaseLabel.setText("Mapping base:");
	final ComboViewer mappingCombo = new ComboViewer(headerComposite, SWT.READ_ONLY);
	Combo combo = mappingCombo.getCombo();
	combo.setToolTipText("Select the mapping base to use.");
	mappingCombo.setContentProvider(new MappingBaseRegistryContentProvider());
	mappingCombo.setLabelProvider(new MappingLabelProvider(MappingLabelProvider.SOURCE));
	mappingCombo.setComparator(new ViewerComparator());
	mappingCombo.setInput(MappingUtils.getMappingRegistry());
	mappingCombo.addSelectionChangedListener(new BaseComboSelectionChangedListener());

	return mappingCombo;
}
 
Example 9
Project: bts   File: E4PreferencesHandler.java   Source Code and License 6 votes vote down vote up
@Execute
	public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,  E4PreferenceRegistry prefReg, 
			@Optional @Named("preferencePageId") String pageId)
	{
		PreferenceManager pm = prefReg.getPreferenceManager();
		PreferenceDialog dialog = new PreferenceDialog(shell, pm);
		if (pageId != null)
		{
			dialog.setSelectedNode(pageId);
		}

		dialog.create();
		dialog.getTreeViewer().setComparator(new ViewerComparator());
//		dialog.getTreeViewer().expandAll();
		dialog.open();
		
	}
 
Example 10
Project: depan   File: NodeStatsTableControl.java   Source Code and License 6 votes vote down vote up
private ViewerComparator buildColumnSorter(int columnIndex) {
  switch (columnIndex) {
  case INDEX_ROOT:
    return new RootSorter();
  case INDEX_RANK:
    return new RankSorter();
  case INDEX_PREDS:
    return new PredecessorCountSorter();
  case INDEX_SUCCS:
    return new SuccessorCountSorter();
  }

  // By default, use an alphabetic sort over the column labels.
  ITableLabelProvider labelProvider =
      (ITableLabelProvider) propViewer.getLabelProvider();
  ViewerComparator result = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, columnIndex));
  return result;
}
 
Example 11
Project: depan   File: NodeKindTableControl.java   Source Code and License 6 votes vote down vote up
private void setSortColumn(
    TableColumn column, int colIndex, int direction) {

  ITableLabelProvider labelProvider =
      (ITableLabelProvider) kindViewer.getLabelProvider();
  ViewerComparator sorter = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, colIndex));
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Table tableControl = (Table) kindViewer.getControl();
  kindViewer.setComparator(sorter);
  tableControl.setSortColumn(column);
  tableControl.setSortDirection(direction);
}
 
Example 12
Project: depan   File: NodeDisplayTableControl.java   Source Code and License 6 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {
  if (INDEX_VISIBLE == colIndex) {
    return new BooleanVisibleSorter();
  }
  if (INDEX_XPOS == colIndex) {
    return new PositionSorter(true);
  }
  if (INDEX_YPOS == colIndex) {
    return new PositionSorter(false);
  }

  // By default, use an alphabetic sort over the column labels.
  ITableLabelProvider labelProvider =
      (ITableLabelProvider) propViewer.getLabelProvider();
  ViewerComparator result = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, colIndex));
  return result;
}
 
Example 13
Project: gwt-eclipse-plugin   File: LegacyGWTHostPageSelectionDialog.java   Source Code and License 6 votes vote down vote up
private LegacyGWTHostPageSelectionDialog(Shell parent, IProject project,
    Map<String, Set<String>> hostPagesByModule, boolean isExternal) {
  super(parent, new LegacyHostPageSelectionLabelProvider(),
      new LegacyGWTHostPageSelectionContentProvider());

  this.isExternal = isExternal;
  this.project = project;
  this.isEmpty = hostPagesByModule.isEmpty();
  this.useHostPage = !isEmpty;

  setValidator(new LegacyHostPageSelectionStatusValidator());
  setTitle("Host page selection");
  setMessage("Choose a host page to launch the application with:");

  setInput(LegacyGWTHostPageSelectionTreeItem.buildTree(hostPagesByModule));
  setComparator(new ViewerComparator());
}
 
Example 14
Project: APICloud-Studio   File: ProjectNaturesPage.java   Source Code and License 6 votes vote down vote up
private ViewerComparator getViewerComperator()
{
	return new ViewerComparator(new Comparator<String>()
	{

		public int compare(String o1, String o2)
		{
			// set Aptana natures ahead of others
			if (ResourceUtil.isAptanaNature(o1))
			{
				return ResourceUtil.isAptanaNature(o2) ? o1.compareTo(o2) : -1;
			}
			return ResourceUtil.isAptanaNature(o2) ? 1 : o1.compareTo(o2);
		}
	});
}
 
Example 15
Project: APICloud-Studio   File: WizardFolderImportPage.java   Source Code and License 6 votes vote down vote up
private ViewerComparator getViewerComperator()
{
	return new ViewerComparator(new Comparator<String>()
	{

		public int compare(String o1, String o2)
		{
			// set Aptana natures ahead of others
			if (ResourceUtil.isAptanaNature(o1))
			{
				return ResourceUtil.isAptanaNature(o2) ? o1.compareTo(o2) : -1;
			}
			return ResourceUtil.isAptanaNature(o2) ? 1 : o1.compareTo(o2);
		}
	});
}
 
Example 16
Project: APICloud-Studio   File: CListTable.java   Source Code and License 6 votes vote down vote up
private void createTable(Composite parent)
{
	tableViewer = new TableViewer(parent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
	tableViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	tableViewer.setContentProvider(ArrayContentProvider.getInstance());
	tableViewer.setLabelProvider(new LabelProvider());
	tableViewer.setComparator(new ViewerComparator());
	tableViewer.setInput(items);
	tableViewer.addSelectionChangedListener(new ISelectionChangedListener()
	{

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

	});
	updateStates();
}
 
Example 17
Project: APICloud-Studio   File: CommonOutlinePage.java   Source Code and License 6 votes vote down vote up
public void propertyChange(PropertyChangeEvent event)
{
	String property = event.getProperty();

	if (property.equals(IPreferenceConstants.LINK_OUTLINE_WITH_EDITOR))
	{
		boolean isLinked = Boolean.parseBoolean(StringUtil.getStringValue(event.getNewValue()));

		fToggleLinkingAction.setChecked(isLinked);
		TreeViewer viewer = getTreeViewer();
		if (isLinked)
		{
			setEditorSelection((IStructuredSelection) viewer.getSelection(), false);
		}
	}
	else if (property.equals(IPreferenceConstants.SORT_OUTLINE_ALPHABETIC))
	{
		boolean sort = Boolean.parseBoolean(StringUtil.getStringValue(event.getNewValue()));
		getTreeViewer().setComparator(sort ? new ViewerComparator() : null);
	}
}
 
Example 18
Project: OpenSPIFe   File: TreeTableViewer.java   Source Code and License 6 votes vote down vote up
@Override
public void run() {
	synchronized (elementsBeingUpdated) {
		elementsBeingUpdated.removeAll(elementsNeedingUpdates);
	}
	Tree tree = getTree();
	if (tree.isDisposed()) return;
	List<TreeItem> selection = Arrays.asList(tree.getSelection());
	ViewerComparator comparator = getComparator();
	Item[] treeChildren = (comparator != null ? getChildren(tree) : null);
	for (O element : elementsNeedingUpdates) {
		boolean refreshCalled = handleObjectUpdated(element, selection, treeChildren);
		if (refreshCalled) {
			break;
		}
	}
}
 
Example 19
Project: Eclipse-Postfix-Code-Completion   File: NLSSearchResultPage.java   Source Code and License 6 votes vote down vote up
@Override
protected void configureTableViewer(TableViewer viewer) {
	viewer.setComparator(new ViewerComparator() {
		@Override
		public int category(Object element) {
			if (element instanceof FileEntry) {
				return 0;
			} else {
				return 1;
			}
		}
	});
	viewer.setLabelProvider(new ColoringLabelProvider(new NLSSearchResultLabelProvider2(this)));
	fContentProvider= new TextSearchTableContentProvider();
	viewer.setContentProvider(fContentProvider);
}
 
Example 20
Project: Eclipse-Postfix-Code-Completion   File: CallHierarchyViewPart.java   Source Code and License 6 votes vote down vote up
private void updateView() {
if (fInputElements != null) {
	showPage(PAGE_VIEWER);

	int includeMask= getIncludeMask();
	CallHierarchy.getDefault().setSearchScope(getSearchScope(includeMask));

	// set input to null so that setComparator does not cause a refresh on the old contents:
	fCallHierarchyViewer.setInput(null);
	if (fCurrentCallMode == CALL_MODE_CALLERS) {
		// sort caller hierarchy alphabetically (bug 111423) and make RealCallers the last in 'Expand With Constructors' mode
		fCallHierarchyViewer.setComparator(new ViewerComparator() {
			@Override
			public int category(Object element) {
				return element instanceof RealCallers ? 1 : 0;
			}
		});
  			fCallHierarchyViewer.setMethodWrappers(getCallerRoots());
	} else {
		fCallHierarchyViewer.setComparator(null);
		fCallHierarchyViewer.setMethodWrappers(getCalleeRoots());
	}
	setContentDescription(includeMask);
}
  }
 
Example 21
Project: Eclipse-Postfix-Code-Completion   File: JavadocStandardWizardPage.java   Source Code and License 6 votes vote down vote up
private void createListDialogField(Composite composite) {
	Composite c= new Composite(composite, SWT.NONE);
	c.setFont(composite.getFont());
	c.setLayout(createGridLayout(3));
	c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL, 4, 0));
	((GridLayout) c.getLayout()).marginWidth= 0;

	String[] buttonlabels= new String[] { JavadocExportMessages.JavadocStandardWizardPage_selectallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_clearallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_configurebutton_label};

	JavadocLinkDialogLabelProvider labelProvider= new JavadocLinkDialogLabelProvider();

	ListAdapter adapter= new ListAdapter();

	fListDialogField= new CheckedListDialogField<JavadocLinkRef>(adapter, buttonlabels, labelProvider);
	fListDialogField.setDialogFieldListener(adapter);
	fListDialogField.setCheckAllButtonIndex(0);
	fListDialogField.setUncheckAllButtonIndex(1);
	fListDialogField.setViewerComparator(new ViewerComparator());

	createLabel(c, SWT.NONE, JavadocExportMessages.JavadocStandardWizardPage_referencedclasses_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 4, 0));
	fListDialogField.doFillIntoGrid(c, 3);

	LayoutUtil.setHorizontalGrabbing(fListDialogField.getListControl(null));

	fListDialogField.enableButton(2, false);
}
 
Example 22
Project: Eclipse-Postfix-Code-Completion   File: CodeAssistFavoritesConfigurationBlock.java   Source Code and License 6 votes vote down vote up
private void createFavoriteList(Composite parent) {
	String[] buttonLabels= new String[] {
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_newType_button,
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_newMember_button,
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_edit_button,
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_remove_button
	};

	ListAdapter adapter= new ListAdapter();

	fList= new ListDialogField<String>(adapter, buttonLabels, new ListLabelProvider());
	fList.setDialogFieldListener(adapter);
	fList.setLabelText(PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_description);
	fList.setRemoveButtonIndex(IDX_REMOVE);
	fList.enableButton(IDX_EDIT, false);
	fList.setViewerComparator(new ViewerComparator());

	PixelConverter pixelConverter= new PixelConverter(parent);

	fList.doFillIntoGrid(parent, 3);
	LayoutUtil.setHorizontalSpan(fList.getLabelControl(null), 2);
	LayoutUtil.setWidthHint(fList.getLabelControl(null), pixelConverter.convertWidthInCharsToPixels(60));
	LayoutUtil.setHorizontalGrabbing(fList.getListControl(null));
}
 
Example 23
Project: Eclipse-Postfix-Code-Completion   File: ExclusionInclusionDialog.java   Source Code and License 6 votes vote down vote up
private ListDialogField<String> createListContents(CPListElement entryToEdit, String key, String label, ImageDescriptor descriptor, String[] buttonLabels) {
	ExclusionPatternAdapter adapter= new ExclusionPatternAdapter();

	ListDialogField<String> patternList= new ListDialogField<String>(adapter, buttonLabels, new ExclusionInclusionLabelProvider(descriptor));
	patternList.setDialogFieldListener(adapter);
	patternList.setLabelText(label);
	patternList.setRemoveButtonIndex(IDX_REMOVE);
	patternList.enableButton(IDX_EDIT, false);

	IPath[] pattern= (IPath[]) entryToEdit.getAttribute(key);

	ArrayList<String> elements= new ArrayList<String>(pattern.length);
	for (int i= 0; i < pattern.length; i++) {
		elements.add(pattern[i].toString());
	}
	patternList.setElements(elements);
	patternList.selectFirstElement();
	patternList.enableButton(IDX_ADD_MULTIPLE, fCurrSourceFolder != null);
	patternList.setViewerComparator(new ViewerComparator());
	return patternList;
}
 
Example 24
Project: Eclipse-Postfix-Code-Completion   File: SetFilterWizardPage.java   Source Code and License 6 votes vote down vote up
private ListDialogField<String> createListContents(CPListElement entryToEdit, String key, String label, ImageDescriptor descriptor, String[] buttonLabels) {
	ExclusionPatternAdapter adapter= new ExclusionPatternAdapter();

	ListDialogField<String> patternList= new ListDialogField<String>(adapter, buttonLabels, new ExclusionInclusionLabelProvider(descriptor));
	patternList.setDialogFieldListener(adapter);
	patternList.setLabelText(label);
	patternList.enableButton(IDX_EDIT, false);

	IPath[] pattern= (IPath[]) entryToEdit.getAttribute(key);

	ArrayList<String> elements= new ArrayList<String>(pattern.length);
	for (int i= 0; i < pattern.length; i++) {
		String patternName= pattern[i].toString();
		if (patternName.length() > 0)
			elements.add(patternName);
	}
	patternList.setElements(elements);
	patternList.selectFirstElement();
	patternList.enableButton(IDX_ADD_MULTIPLE, fCurrSourceFolder != null);
	patternList.setViewerComparator(new ViewerComparator());
	return patternList;
}
 
Example 25
Project: translationstudio8   File: ProjectSettingDialog.java   Source Code and License 6 votes vote down vote up
/**
 * Selects the saved item in the tree of preference pages. If it cannot do this it saves the first one.
 */
protected void selectSavedItem() {
	IPreferenceNode node = findNodeMatching(getSelectedNodePreference());
	if (node == null) {
		IPreferenceNode[] nodes = preferenceManager.getRootSubNodes();
		ViewerComparator comparator = getTreeViewer().getComparator();
		if (comparator != null)	{
			comparator.sort(null, nodes);
		}			
		for (int i = 0; i < nodes.length; i++) {
			IPreferenceNode selectedNode = nodes[i];
			if (selectedNode != null) {
				node = selectedNode;
				break;
			}
		}
	}
	if (node != null) {
		getTreeViewer().setSelection(new StructuredSelection(node), true);
		// Keep focus in tree. See bugs 2692, 2621, and 6775.
		getTreeViewer().getControl().setFocus();
		boolean expanded = getTreeViewer().getExpandedState(node);
		getTreeViewer().setExpandedState(node, !expanded);
	}
}
 
Example 26
Project: cmake4cdt   File: ArchTable.java   Source Code and License 6 votes vote down vote up
public Table createTableControl(Composite parent) {
		Table table = getTableControl();
		if (table == null) {
			tableParent = parent;
			tableViewer = new TableViewer(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
			createColumns(tableViewer);
			table = tableViewer.getTable();
		    table.setHeaderVisible(true);
		    table.setLinesVisible(true);
			table.setFont(parent.getFont());
			tableViewer.setComparator(new ViewerComparator());
			
			tableViewer.setContentProvider(ArrayContentProvider.getInstance());
			
//			tableViewer.setInput( atlist );
		} else {
			checkParent(table, parent);
		}
		return table;
	}
 
Example 27
Project: gef-gwt   File: SafeRunnableDialog.java   Source Code and License 6 votes vote down vote up
/**
 * Return a viewer sorter for looking at the jobs.
 * 
 * @return ViewerSorter
 */
private ViewerComparator getViewerComparator() {
	return new ViewerComparator() {
		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer,
		 *      java.lang.Object, java.lang.Object)
		 */
		public int compare(Viewer testViewer, Object e1, Object e2) {
			String message1 = ((IStatus) e1).getMessage();
			String message2 = ((IStatus) e2).getMessage();
			if (message1 == null)
				return 1;
			if (message2 == null)
				return -1;

			return message1.compareTo(message2);
		}
	};
}
 
Example 28
Project: Eclipse-Postfix-Code-Completion-Juno38   File: NLSSearchResultPage.java   Source Code and License 6 votes vote down vote up
@Override
protected void configureTableViewer(TableViewer viewer) {
	viewer.setComparator(new ViewerComparator() {
		@Override
		public int category(Object element) {
			if (element instanceof FileEntry) {
				return 0;
			} else {
				return 1;
			}
		}
	});
	viewer.setLabelProvider(new ColoringLabelProvider(new NLSSearchResultLabelProvider2(this)));
	fContentProvider= new TextSearchTableContentProvider();
	viewer.setContentProvider(fContentProvider);
}
 
Example 29
Project: Eclipse-Postfix-Code-Completion-Juno38   File: CallHierarchyViewPart.java   Source Code and License 6 votes vote down vote up
private void updateView() {
if (fInputElements != null) {
	showPage(PAGE_VIEWER);

	int includeMask= getIncludeMask();
	CallHierarchy.getDefault().setSearchScope(getSearchScope(includeMask));

	// set input to null so that setComparator does not cause a refresh on the old contents:
	fCallHierarchyViewer.setInput(null);
	if (fCurrentCallMode == CALL_MODE_CALLERS) {
		// sort caller hierarchy alphabetically (bug 111423) and make RealCallers the last in 'Expand With Constructors' mode
		fCallHierarchyViewer.setComparator(new ViewerComparator() {
			@Override
			public int category(Object element) {
				return element instanceof RealCallers ? 1 : 0;
			}
		});
  			fCallHierarchyViewer.setMethodWrappers(getCallerRoots());
	} else {
		fCallHierarchyViewer.setComparator(null);
		fCallHierarchyViewer.setMethodWrappers(getCalleeRoots());
	}
	setContentDescription(includeMask);
}
  }
 
Example 30
Project: Eclipse-Postfix-Code-Completion-Juno38   File: JavadocStandardWizardPage.java   Source Code and License 6 votes vote down vote up
private void createListDialogField(Composite composite) {
	Composite c= new Composite(composite, SWT.NONE);
	c.setFont(composite.getFont());
	c.setLayout(createGridLayout(3));
	c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL, 4, 0));
	((GridLayout) c.getLayout()).marginWidth= 0;

	String[] buttonlabels= new String[] { JavadocExportMessages.JavadocStandardWizardPage_selectallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_clearallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_configurebutton_label};

	JavadocLinkDialogLabelProvider labelProvider= new JavadocLinkDialogLabelProvider();

	ListAdapter adapter= new ListAdapter();

	fListDialogField= new CheckedListDialogField<JavadocLinkRef>(adapter, buttonlabels, labelProvider);
	fListDialogField.setDialogFieldListener(adapter);
	fListDialogField.setCheckAllButtonIndex(0);
	fListDialogField.setUncheckAllButtonIndex(1);
	fListDialogField.setViewerComparator(new ViewerComparator());

	createLabel(c, SWT.NONE, JavadocExportMessages.JavadocStandardWizardPage_referencedclasses_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 4, 0));
	fListDialogField.doFillIntoGrid(c, 3);

	LayoutUtil.setHorizontalGrabbing(fListDialogField.getListControl(null));

	fListDialogField.enableButton(2, false);
}
 
Example 31
Project: Eclipse-Postfix-Code-Completion-Juno38   File: CodeAssistFavoritesConfigurationBlock.java   Source Code and License 6 votes vote down vote up
private void createFavoriteList(Composite parent) {
	String[] buttonLabels= new String[] {
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_newType_button,
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_newMember_button,
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_edit_button,
			PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_remove_button
	};

	ListAdapter adapter= new ListAdapter();

	fList= new ListDialogField<String>(adapter, buttonLabels, new ListLabelProvider());
	fList.setDialogFieldListener(adapter);
	fList.setLabelText(PreferencesMessages.CodeAssistStaticMembersConfigurationBlock_description);
	fList.setRemoveButtonIndex(IDX_REMOVE);
	fList.enableButton(IDX_EDIT, false);
	fList.setViewerComparator(new ViewerComparator());

	PixelConverter pixelConverter= new PixelConverter(parent);

	fList.doFillIntoGrid(parent, 3);
	LayoutUtil.setHorizontalSpan(fList.getLabelControl(null), 2);
	LayoutUtil.setWidthHint(fList.getLabelControl(null), pixelConverter.convertWidthInCharsToPixels(60));
	LayoutUtil.setHorizontalGrabbing(fList.getListControl(null));
}
 
Example 32
Project: Eclipse-Postfix-Code-Completion-Juno38   File: ExclusionInclusionDialog.java   Source Code and License 6 votes vote down vote up
private ListDialogField<String> createListContents(CPListElement entryToEdit, String key, String label, ImageDescriptor descriptor, String[] buttonLabels) {
	ExclusionPatternAdapter adapter= new ExclusionPatternAdapter();

	ListDialogField<String> patternList= new ListDialogField<String>(adapter, buttonLabels, new ExclusionInclusionLabelProvider(descriptor));
	patternList.setDialogFieldListener(adapter);
	patternList.setLabelText(label);
	patternList.setRemoveButtonIndex(IDX_REMOVE);
	patternList.enableButton(IDX_EDIT, false);

	IPath[] pattern= (IPath[]) entryToEdit.getAttribute(key);

	ArrayList<String> elements= new ArrayList<String>(pattern.length);
	for (int i= 0; i < pattern.length; i++) {
		elements.add(pattern[i].toString());
	}
	patternList.setElements(elements);
	patternList.selectFirstElement();
	patternList.enableButton(IDX_ADD_MULTIPLE, fCurrSourceFolder != null);
	patternList.setViewerComparator(new ViewerComparator());
	return patternList;
}
 
Example 33
Project: Eclipse-Postfix-Code-Completion-Juno38   File: SetFilterWizardPage.java   Source Code and License 6 votes vote down vote up
private ListDialogField<String> createListContents(CPListElement entryToEdit, String key, String label, ImageDescriptor descriptor, String[] buttonLabels) {
	ExclusionPatternAdapter adapter= new ExclusionPatternAdapter();

	ListDialogField<String> patternList= new ListDialogField<String>(adapter, buttonLabels, new ExclusionInclusionLabelProvider(descriptor));
	patternList.setDialogFieldListener(adapter);
	patternList.setLabelText(label);
	patternList.enableButton(IDX_EDIT, false);

	IPath[] pattern= (IPath[]) entryToEdit.getAttribute(key);

	ArrayList<String> elements= new ArrayList<String>(pattern.length);
	for (int i= 0; i < pattern.length; i++) {
		String patternName= pattern[i].toString();
		if (patternName.length() > 0)
			elements.add(patternName);
	}
	patternList.setElements(elements);
	patternList.selectFirstElement();
	patternList.enableButton(IDX_ADD_MULTIPLE, fCurrSourceFolder != null);
	patternList.setViewerComparator(new ViewerComparator());
	return patternList;
}
 
Example 34
Project: tmxeditor8   File: ProjectSettingDialog.java   Source Code and License 6 votes vote down vote up
/**
 * Selects the saved item in the tree of preference pages. If it cannot do this it saves the first one.
 */
protected void selectSavedItem() {
	IPreferenceNode node = findNodeMatching(getSelectedNodePreference());
	if (node == null) {
		IPreferenceNode[] nodes = preferenceManager.getRootSubNodes();
		ViewerComparator comparator = getTreeViewer().getComparator();
		if (comparator != null)	{
			comparator.sort(null, nodes);
		}			
		for (int i = 0; i < nodes.length; i++) {
			IPreferenceNode selectedNode = nodes[i];
			if (selectedNode != null) {
				node = selectedNode;
				break;
			}
		}
	}
	if (node != null) {
		getTreeViewer().setSelection(new StructuredSelection(node), true);
		// Keep focus in tree. See bugs 2692, 2621, and 6775.
		getTreeViewer().getControl().setFocus();
		boolean expanded = getTreeViewer().getExpandedState(node);
		getTreeViewer().setExpandedState(node, !expanded);
	}
}
 
Example 35
Project: version-tiger   File: EditVersionPage.java   Source Code and License 6 votes vote down vote up
private void bindUniverseDefinition(ComboViewer universeDefinitionCombo) {
	universeDefinitionCombo.setContentProvider(new ArrayContentProvider());
	universeDefinitionCombo.setLabelProvider(new ProjectUniverseLabelProvider());
	universeDefinitionCombo.setComparator(new ViewerComparator());
	Set<ProjectUniverse> projectUniverses = getProjectUniverses();
	universeDefinitionCombo.setInput(projectUniverses);

	IObservableValue selectedUniverseDefinition = ViewerProperties.singleSelection().observe(universeDefinitionCombo);
	IObservableValue universeDefinition = BeansObservables.observeValue(editVersionModel, EditVersionModel.PN_PROJECT_UNIVERSE);
	dbc.bindValue(selectedUniverseDefinition, universeDefinition);

	ProjectUniverse projectUniverse = findUniverse(projectUniverses, getUniverseId());
	if (projectUniverse == null) {
		projectUniverse = findUniverse(projectUniverses, UniverseDefinitions.ALL_WORKSPACE_PROJECTS_UNIVERSE_ID);
	}
	/* We simply use the first element in the list as the initial selection. */
	if (0 < universeDefinitionCombo.getCombo().getItemCount()) {
		universeDefinitionCombo.setSelection(new StructuredSelection(projectUniverse));
	}
}
 
Example 36
Project: elexis-3-core   File: SelectBestellungDialog.java   Source Code and License 6 votes vote down vote up
private void setComparator(){
	fTableViewer.setComparator(new ViewerComparator() {
		private TimeTool t1 = new TimeTool();
		private TimeTool t2 = new TimeTool();
		
		@Override
		public int compare(Viewer viewer, Object b1, Object b2){
			setTimeTool((Bestellung) b1, t1);
			setTimeTool((Bestellung) b2, t2);
			if (t1.after(t2))
				return -1;
			if (t2.after(t1))
				return 1;
			return 0;
		}
		
		private void setTimeTool(Bestellung bestellung, TimeTool timeTool){
			try {
				String[] i = bestellung.getId().split(":"); //$NON-NLS-1$
				timeTool.set(i[1]);
			} catch (Exception e) {
				timeTool.set("1.1.1970");
			}
		}
	});
}
 
Example 37
Project: n4js   File: CustomElementSelectionDialog.java   Source Code and License 5 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	CustomElementSelectionForm form = new CustomElementSelectionForm(parent, SWT.FILL);
	form.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	TreeViewer v = form.getTreeViewer();
	for (ViewerFilter filter : filters) {
		v.addFilter(filter);
	}
	this.treeViewer = v;

	WorkbenchContentProvider contentProvider = new WorkbenchContentProvider();
	ILabelProvider labelProvider = new WorkbenchLabelProvider();

	this.treeViewer.setContentProvider(contentProvider);
	this.treeViewer.setLabelProvider(labelProvider);

	this.treeViewer.setComparator(new ViewerComparator());

	this.treeViewer.setAutoExpandLevel(this.getAutoExpandLevel());

	form.setElementLabel(this.elementLabel);

	this.elementNameInput = form.getElementInput();

	form.getElementInput().addPropertyChangeListener(new PropertyChangeListener() {

		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			if (evt.getPropertyName().equals(SuffixText.TEXT_PROPERTY) ||
					evt.getPropertyName().equals(SuffixText.SUFFIX_PROPERTY)) {
				validateElementInput();
				elementInputChanged();
			}

		}
	});
	return form;
}
 
Example 38
Project: n4js   File: AbstractExportToSingleFileWizardPage.java   Source Code and License 5 votes vote down vote up
/**
 * Creates the checkbox tree and list for selecting resources.
 *
 * @param parent
 *            the parent control
 */
protected void createProjectList(Composite parent) {

	// create the input element, which has the root resource
	// as its only child
	List<IProject> input = new ArrayList<>();
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
			.getProjects();
	for (int i = 0; i < projects.length; i++) {
		if (projects[i].isOpen()) {
			input.add(projects[i]);
		}
	}

	listViewer = CheckboxTableViewer.newCheckList(parent, SWT.TOP
			| SWT.BORDER);
	GridData data = new GridData(GridData.FILL_BOTH);
	listViewer.getTable().setLayoutData(data);

	listViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
	listViewer.setContentProvider(getContentProvider());
	listViewer.setComparator(new ViewerComparator());

	// check for initial modification to avoid work if no changes are made
	listViewer.addCheckStateListener(new ICheckStateListener() {
		@Override
		public void checkStateChanged(CheckStateChangedEvent event) {
			if (event.getChecked()) {
				for (Object currentlyChecked : listViewer.getCheckedElements()) {
					if (currentlyChecked != event.getElement()) {
						listViewer.setChecked(currentlyChecked, false);
					}
				}
			}
			updateWidgetEnablements();
		}
	});
	listViewer.setInput(workspace);
}
 
Example 39
Project: neoscada   File: AttributesPart.java   Source Code and License 5 votes vote down vote up
@Override
public void createPart ( final Composite parent )
{
    super.createPart ( parent );

    this.viewer = new TableViewer ( parent, SWT.FULL_SELECTION );

    final TableLayout tableLayout = new TableLayout ();

    final TableViewerColumn col1 = new TableViewerColumn ( this.viewer, SWT.NONE );
    col1.getColumn ().setText ( Messages.AttributesPart_NameLabel );
    tableLayout.addColumnData ( new ColumnWeightData ( 50 ) );

    final TableViewerColumn col2 = new TableViewerColumn ( this.viewer, SWT.NONE );
    col2.getColumn ().setText ( Messages.AttributesPart_TypeLabel );
    tableLayout.addColumnData ( new ColumnWeightData ( 20 ) );

    final TableViewerColumn col3 = new TableViewerColumn ( this.viewer, SWT.NONE );
    col3.getColumn ().setText ( Messages.AttributesPart_ValueLabel );
    tableLayout.addColumnData ( new ColumnWeightData ( 50 ) );

    this.viewer.getTable ().setHeaderVisible ( true );
    this.viewer.getTable ().setLayout ( tableLayout );

    ViewerSupport.bind ( this.viewer, this.entries, new IValueProperty[] { PojoProperties.value ( "name" ), PojoProperties.value ( "type" ), PojoProperties.value ( "value" ) } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    this.viewer.setComparator ( new ViewerComparator () );
}
 
Example 40
Project: Equella   File: JPFRepositoryPage.java   Source Code and License 5 votes vote down vote up
@Override
protected Control createContents(Composite parent)
{
	Composite composite = new Composite(parent, SWT.NONE);

	initialize();

	createDescriptionLabel(composite);

	listViewer = new TableViewer(composite, SWT.TOP | SWT.BORDER);

	if( !project.isOpen() )
		listViewer.getControl().setEnabled(false);

	listViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
	listViewer.setContentProvider(new JarProjectContentProvider(project));
	listViewer.setComparator(new ViewerComparator());
	listViewer.setInput(project.getWorkspace());

	String regName = getPreferenceStore().getString(JPFClasspathPlugin.PREF_REGISTRY_NAME);
	if( !regName.isEmpty() )
	{
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		listViewer.setSelection(new StructuredSelection(root.getProject(regName)));
	}
	listViewer.addSelectionChangedListener(new ISelectionChangedListener()
	{
		@Override
		public void selectionChanged(SelectionChangedEvent event)
		{
			modified = true;
		}
	});
	applyDialogFont(composite);

	GridLayoutFactory.fillDefaults().generateLayout(composite);

	return composite;
}
 
Example 41
Project: termsuite-ui   File: DetailedProgressViewer.java   Source Code and License 5 votes vote down vote up
@Override
public void add(Object[] elements) {
	ViewerComparator sorter = getComparator();

	// Use a Set in case we are getting something added that exists
	Set<Object> newItems = new HashSet<>(elements.length);

	Control[] existingChildren = control.getChildren();
	for (int i = 0; i < existingChildren.length; i++) {
		if (existingChildren[i].getData() != null)
			newItems.add(existingChildren[i].getData());
	}

	for (int i = 0; i < elements.length; i++) {
		if (elements[i] != null)
			newItems.add(elements[i]);
	}

	JobTreeElement[] infos = new JobTreeElement[newItems.size()];
	newItems.toArray(infos);

	if (sorter != null) {
		sorter.sort(this, infos);
	}

	// Update with the new elements to prevent flash
	for (int i = 0; i < existingChildren.length; i++) {
		((ProgressInfoItem) existingChildren[i]).dispose();
	}

	int totalSize = Math.min(newItems.size(), MAX_DISPLAYED);

	for (int i = 0; i < totalSize; i++) {
		ProgressInfoItem item = createNewItem(infos[i]);
		item.setColor(i);
	}

	control.layout(true);
	updateForShowingProgress();
}
 
Example 42
Project: team-explorer-everywhere   File: GitSourceSettingsControl.java   Source Code and License 5 votes vote down vote up
private void setupBranchViewers() {
    final IContentProvider contentProvider = new ContentProviderAdapter() {
        @Override
        public Object[] getElements(final Object input) {
            @SuppressWarnings("unchecked")
            final List<GitBranch> branches = ((List<GitBranch>) input);

            return branches.toArray(new GitBranch[branches.size()]);
        }
    };
    branchViewer.setContentProvider(contentProvider);
    branchComboViewer.setContentProvider(contentProvider);

    final LabelProvider labelProvider = new LabelProvider() {
        @Override
        public String getText(final Object element) {
            return ((GitBranch) element).getRemoteName();
        }
    };
    branchViewer.setLabelProvider(labelProvider);
    branchComboViewer.setLabelProvider(labelProvider);

    final ViewerComparator viewerComparator = new ViewerComparator() {
        @Override
        public int compare(final Viewer viewer, final Object e1, final Object e2) {
            return ((GitBranch) e1).compareTo(((GitBranch) e2));
        }
    };
    branchViewer.setComparator(viewerComparator);
    branchComboViewer.setComparator(viewerComparator);
}
 
Example 43
Project: GrepBugsPluginEclipse   File: CodeScannerView.java   Source Code and License 5 votes vote down vote up
private Control buildMatchResultsViewer(Composite parent) {

		matchResultsViewer = new TableViewer(parent, SWT.FULL_SELECTION
				| SWT.SINGLE | SWT.BORDER);

		autoResizeViewer(matchResultsViewer);
		TableViewerColumn column = new TableViewerColumn(matchResultsViewer,
				SWT.NONE);
		column.getColumn().setText(Messages.CodeScannerView_RULE);
		column.getColumn().setWidth(100);
		matchResultsViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				if (element instanceof SearchFileDescriptor) {
					SearchFileDescriptor result = (SearchFileDescriptor) element;
					return StringUtils.join(new String[] {
							result.getDisplayName(),
							Messages.CodeScannerView_LINE,
							String.valueOf(result.getLine()) });
				}
				return ""; //$NON-NLS-1$
			}
		});
		matchResultsViewer.setContentProvider(new ArrayContentProvider());
		matchResultsViewer.getTable().setHeaderVisible(false);
		matchResultsViewer.getTable().setLinesVisible(false);
		matchResultsViewer.setComparator(new ViewerComparator(new Comparator<String>() {

			@Override
			public int compare(String o1, String o2) {
				return o1.compareToIgnoreCase(o2);
			}
		}));
		return matchResultsViewer.getControl();
	}
 
Example 44
Project: GrepBugsPluginEclipse   File: CodeScannerView.java   Source Code and License 5 votes vote down vote up
private Control buildTagsViewer(Composite parent) {

		tagsViewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL);

		autoResizeViewer(tagsViewer);

		TableViewerColumn column = new TableViewerColumn(tagsViewer,
				SWT.NONE);
		column.getColumn().setText(Messages.CodeScannerView_RULE_LABEL);
		column.getColumn().setWidth(100);
		tagsViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				if (element instanceof Rule) {
					Rule rule = (Rule) element;
					Collection<SearchFileDescriptor> searchDescriptors = results
							.get(rule);
					if (searchDescriptors == null) {
						searchDescriptors = Sets.newHashSet();
					}
					return StringUtils.join(new String[] { rule.getTags(),
							" (", String.valueOf(searchDescriptors.size()), ")" }); //$NON-NLS-1$ //$NON-NLS-2$
				}
				return ""; //$NON-NLS-1$
			}
		});
	
		tagsViewer.setContentProvider(new ArrayContentProvider());
		tagsViewer.getTable().setHeaderVisible(false);
		tagsViewer.getTable().setLinesVisible(false);
		tagsViewer.setComparator(new ViewerComparator(new Comparator<String>() {

			@Override
			public int compare(String o1, String o2) {
				return o1.compareToIgnoreCase(o2);
			}
		}));
		return tagsViewer.getControl();
	}
 
Example 45
Project: jsbuild-eclipse   File: JSBuildFileView.java   Source Code and License 5 votes vote down vote up
private void setProjectViewerSelectionAfterDeletion() {
	Object[] children = getProjects();
	if (children.length > 0) {
		ViewerComparator comparator = projectViewer.getComparator();
		comparator.sort(projectViewer, children);
		IStructuredSelection selection = new StructuredSelection(
				children[0]);
		projectViewer.setSelection(selection);
		handleSelectionChanged(selection);
	}
}
 
Example 46
Project: bts   File: ShowPreferenceDialogHandler.java   Source Code and License 5 votes vote down vote up
@Execute
public void execute(MApplication app) {
	PreferenceManager pm = configurePreferences();
	PreferenceDialog dialog = new PreferenceDialog(shell, pm);
	dialog.setPreferenceStore(new ScopedPreferenceStore(
			InstanceScope.INSTANCE, "org.bbaw.bts.app"));
	dialog.create();
	dialog.getTreeViewer().setComparator(new ViewerComparator());
	dialog.getTreeViewer().expandAll();
	dialog.open();
}
 
Example 47
Project: bts   File: SelectPerspectiveDialog.java   Source Code and License 5 votes vote down vote up
/**
   * Create a new viewer in the parent.
   * 
   * @param parent the parent <code>Composite</code>.
   */
  private void createViewer(Composite parent) {
      // Add perspective list.
      viewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
      viewer.getTable().setFont(parent.getFont());
      
viewer.setLabelProvider(new DelegatingLabelProviderWithTooltip(
		ContextInjectionFactory.make(PerspectiveLabelProvider.class, context),
		ContextInjectionFactory.make(PerspectiveLabelDecorator.class, context)) {
	
	@Override
	protected Object unwrapElement(Object element) {
		// We do not need to unwrap the element
		return element;
	}
});
      
viewer.setContentProvider(
		ContextInjectionFactory.make(PerspectiveContentProvider.class, context));
      // list.addFilter(activityViewerFilter);
      viewer.setComparator(new ViewerComparator());
      viewer.setInput(window);
      viewer.addSelectionChangedListener(this);
      viewer.addDoubleClickListener(new IDoubleClickListener() {
      	
      	@Override
          public void doubleClick(DoubleClickEvent event) {
              handleDoubleClickEvent();
          }
      });
  }
 
Example 48
Project: junit-tools   File: GroupMethodSelectionCtrl.java   Source Code and License 5 votes vote down vote up
private void initReal(GroupMethodSelectionView grp, IJavaElement javaElement, GeneratorModel jutModel)
		throws JavaModelException {
	this.group = grp;
	this.model = jutModel;
	this.treeClass = javaElement;

	if (viewerFilterMethods == null) {
		this.viewerFilterMethods = new ViewerFilterMethods(null);
		group.getCheckboxTreeViewer().addFilter(viewerFilterMethods);
	}

	group.getCheckboxTreeViewer().setCheckStateProvider(new CheckStateProvider());
	group.getCheckboxTreeViewer().setInput(javaElement);
	group.getCheckboxTreeViewer().expandAll();
	group.getCheckboxTreeViewer().setComparator(new ViewerComparator() {

		@Override
		public int compare(Viewer viewer, Object e1, Object e2) {
			if (e1 instanceof IMethod && e2 instanceof IMethod) {
				IMethod m1, m2;
				m1 = (IMethod) e1;
				m2 = (IMethod) e2;

				return m1.getElementName().compareTo(m2.getElementName());
			}

			return super.compare(viewer, e1, e2);
		}
	});

	initNameFilters();

	// initialize existing methods
	initCheckedMethods();

	group.getCheckboxTreeViewer().refresh();

	addInternalListener(grp);
}
 
Example 49
Project: e4-cookbook-migration-guide   File: PreferencesHandler.java   Source Code and License 5 votes vote down vote up
@Execute
public void execute(Shell shell, @PrefMgr PreferenceManager manager) {
	PreferenceDialog dialog = new PreferenceDialog(shell, manager) {
		@Override
		protected TreeViewer createTreeViewer(Composite parent) {
			TreeViewer viewer = super.createTreeViewer(parent);
			
			viewer.setComparator(new ViewerComparator() {
				
				@Override
				public int category(Object element) {
					// this ensures that the General preferences page is always on top
					// while the other pages are ordered alphabetical
					if (element instanceof ContributedPreferenceNode
							&& ("general".equals(((ContributedPreferenceNode) element).getId()))) {
						return -1;
					}
			        return 0;
			    }
				
			});
			
			return viewer;
		}
	};
	
	dialog.open();
}
 
Example 50
Project: depan   File: ProjectResourceControl.java   Source Code and License 5 votes vote down vote up
protected DrillDownComposite setupContainerControl(Composite parent) {
  DrillDownComposite result = new DrillDownComposite(parent, SWT.BORDER);

  containerViewer = new TreeViewer(result, SWT.NONE);
  result.setChildTree(containerViewer);

  containerViewer.setContentProvider(new WorkbenchContentProvider());
  containerViewer.setLabelProvider(new WorkbenchLabelProvider());
  containerViewer.setComparator(new ViewerComparator());
  containerViewer.setUseHashlookup(true);
  containerViewer.setInput(prepareInput());
  return result;
}
 
Example 51
Project: depan   File: EdgeDisplayTableControl.java   Source Code and License 5 votes vote down vote up
private void setSortColumn(
    TableColumn column, int colIndex, int direction) {

  ViewerComparator sorter = buildColumnSorter(colIndex);
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Table tableControl = (Table) propViewer.getControl();
  propViewer.setComparator(sorter);
  tableControl.setSortColumn(column);
  tableControl.setSortDirection(direction);
}
 
Example 52
Project: depan   File: EdgeDisplayTableControl.java   Source Code and License 5 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {

    // By default, use an alphabetic sort over the column labels.
    ITableLabelProvider labelProvider =
        (ITableLabelProvider) propViewer.getLabelProvider();
    ViewerComparator result = new AlphabeticSorter(
        new LabelProviderToString(labelProvider, colIndex));
    return result;
  }
 
Example 53
Project: depan   File: RelationDisplayTableControl.java   Source Code and License 5 votes vote down vote up
private void setSortColumn(
    TableColumn column, int colIndex, int direction) {

  ViewerComparator sorter = buildColumnSorter(colIndex);
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Table tableControl = (Table) propViewer.getControl();
  propViewer.setComparator(sorter);
  tableControl.setSortColumn(column);
  tableControl.setSortDirection(direction);
}
 
Example 54
Project: depan   File: RelationDisplayTableControl.java   Source Code and License 5 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {

    // By default, use an alphabetic sort over the column labels.
    ITableLabelProvider labelProvider =
        (ITableLabelProvider) propViewer.getLabelProvider();
    ViewerComparator result = new AlphabeticSorter(
        new LabelProviderToString(labelProvider, colIndex));
    return result;
  }
 
Example 55
Project: depan   File: RelationSetTableControl.java   Source Code and License 5 votes vote down vote up
private void setSortColumn(
    TableColumn column, int colIndex, int direction) {

  ViewerComparator sorter = buildColumnSorter(colIndex);
  if (SWT.UP == direction) {
    sorter = new InverseSorter(sorter);
  }

  Table tableControl = (Table) relSetViewer.getControl();
  relSetViewer.setComparator(sorter);
  tableControl.setSortColumn(column);
  tableControl.setSortDirection(direction);
}
 
Example 56
Project: depan   File: RelationSetTableControl.java   Source Code and License 5 votes vote down vote up
private ViewerComparator buildColumnSorter(int colIndex) {
  if (INDEX_VISIBLE == colIndex) {
    return new BooleanViewSorter();
  }

  // By default, use an alphabetic sort over the column labels.
  ITableLabelProvider labelProvider =
      (ITableLabelProvider) relSetViewer.getLabelProvider();
  ViewerComparator result = new AlphabeticSorter(
      new LabelProviderToString(labelProvider, colIndex));
  return result;
}
 
Example 57
Project: gwt-eclipse-plugin   File: HostPagePathSelectionDialog.java   Source Code and License 5 votes vote down vote up
private HostPagePathSelectionDialog(Shell parent, IProject project) {
  super(parent, new HostPagePathLabelProvider(),
      new HostPagePathContentProvider());

  setTitle("Existing Folder Selection");
  setMessage("Choose a location for the HTML page");

  rootTreeItems = HostPagePathTreeItem.createRootItems(project);
  setInput(rootTreeItems);
  setComparator(new ViewerComparator());
}
 
Example 58
Project: SPELL   File: ExecutionSelectionViewerTime.java   Source Code and License 5 votes vote down vote up
/***************************************************************************
 * 
 **************************************************************************/
public ExecutionSelectionViewerTime( Tree tree )
{
	super(tree);
	
	setComparator(new ViewerComparator()
	{
		public int compare(Viewer viewer, Object e1, Object e2)
		{
			ExecutionSelectionNode t1 = (ExecutionSelectionNode) e1;
			ExecutionSelectionNode t2 = (ExecutionSelectionNode) e2;
			int result = 0;
			if (t1.getType().equals(NodeType.ASRUN))
			{
				result = t1.getDate().compareTo(t2.getDate());
				if (result == 0)
				{
					result = t1.getLabel().compareTo(t2.getLabel());
				}
			}
			else
			{
				result = t1.getDate().compareTo(t2.getDate());
			}
			return result;
		};
	});

	for (ExecutionSelectionColumnTime col : ExecutionSelectionColumnTime.values())
	{
		TreeColumn c = new TreeColumn(tree, col.style);
		c.setText(col.title);
		c.setWidth(col.width);
	}

	setContentProvider(new ExecutionSelectionContentProvider());
	setLabelProvider(new ExecutionSelectionLabelProviderTime());

}
 
Example 59
Project: pep-tools   File: FeatureExplorerView.java   Source Code and License 5 votes vote down vote up
private void setContentProvider(ViewerComparator viewerComparator, IContentProvider contentProvider,
		boolean supportsFilters, boolean supportsPlugins) {
	viewer.setComparator(viewerComparator);
	viewer.setContentProvider(contentProvider);

	setViewerFilterActionsEnabled(supportsFilters);
	showPluginsAction.setEnabled(supportsPlugins);

	if (supportsFilters) {
		resetViewerFilters();
	} else {
		viewer.setFilters(new ViewerFilter[] { patternFilter });
	}
}
 
Example 60
Project: eclipse-wtp-json   File: SortAction.java   Source Code and License 5 votes vote down vote up
public SortAction(TreeViewer viewer, IPreferenceStore store,
		String preferenceKey) {
	super(JSONUIMessages.SortAction_0, store, preferenceKey, false); //$NON-NLS-1$
	ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(
			JSONUIPlugin.PLUGIN_ID, JSONEditorPluginImages.IMG_OBJ_SORT);
	setImageDescriptor(desc);
	setToolTipText(getText());
	treeViewer = viewer;
	if (isChecked()) {
		treeViewer.setComparator(new ViewerComparator());
	}
}