Java Code Examples for org.eclipse.jface.viewers.ComboViewer#setComparator()

The following examples show how to use org.eclipse.jface.viewers.ComboViewer#setComparator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MiniSelector.java    From google-cloud-eclipse with Apache License 2.0 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 2
Source File: ContextValueControl.java    From depan with Apache License 2.0 6 votes vote down vote up
public ContextValueControl(Composite parent) {
  super(parent, SWT.NONE);
  setLayout(new FillLayout());

  viewer = new ComboViewer(this, SWT.READ_ONLY | SWT.FLAT);
  viewer.setContentProvider(new ArrayContentProvider());
  viewer.setLabelProvider(CONTROL_LABEL_PROVIDER);
  viewer.setComparator(new AlphabeticSorter(new ViewerObjectToString() {

      @Override
      public String getString(Object object) {
        return CONTROL_LABEL_PROVIDER.getText(object);
      }
    }));

  viewer.setInput(ContextKey.Base.values());

  listener = new ControlSelectionChangedListener();
  viewer.addSelectionChangedListener(listener);
}
 
Example 3
Source File: ComposeModeControl.java    From depan with Apache License 2.0 6 votes vote down vote up
public ComposeModeControl(Composite parent) {
  super(parent, SWT.NONE);
  setLayout(new FillLayout());

  viewer = new ComboViewer(this, SWT.READ_ONLY | SWT.FLAT);
  viewer.setContentProvider(new ArrayContentProvider());
  viewer.setLabelProvider(CONTROL_LABEL_PROVIDER);
  viewer.setComparator(new AlphabeticSorter(new ViewerObjectToString() {

      @Override
      public String getString(Object object) {
        return CONTROL_LABEL_PROVIDER.getText(object);
      }
    }));

  viewer.setInput(ComposeMode.values());

  listener = new ControlSelectionChangedListener();
  viewer.addSelectionChangedListener(listener);
}
 
Example 4
Source File: MapChoiceControl.java    From depan with Apache License 2.0 6 votes vote down vote up
public MapChoiceControl(Composite parent) {
  super(parent, SWT.NONE);
  setLayout(new FillLayout());

  viewer = new ComboViewer(this, SWT.READ_ONLY | SWT.FLAT);
  viewer.setContentProvider(new ControlContentProvider());
  viewer.setLabelProvider(CONTROL_LABEL_PROVIDER);
  viewer.setComparator(new AlphabeticSorter(new ViewerObjectToString() {

      @Override
      public String getString(Object object) {
        return CONTROL_LABEL_PROVIDER.getText(object);
      }
    }));

  listener = new ControlSelectionChangedListener();
  viewer.addSelectionChangedListener(listener);
}
 
Example 5
Source File: ConverterUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 对下拉列表和转换器列表进行绑定
 * @param context
 * @param comboViewer
 * @param model
 *            ;
 */
public static void bindValue(DataBindingContext context, ComboViewer comboViewer, ConverterViewModel model) {
	// ViewerSupport.bind(comboViewer, BeansObservables.observeList(
	// model, "supportTypes", String.class),
	// Properties.selfValue(String.class));
	//		
	//
	// context.bindValue(ViewersObservables
	// .observeSingleSelection(comboViewer), BeansObservables
	// .observeValue(model,
	// "selectedType"));

	// ObservableListContentProvider viewerContentProvider=new ObservableListContentProvider();
	comboViewer.setContentProvider(new ArrayContentProvider());
	comboViewer.setComparator(new ViewerComparator());
	// IObservableMap[] attributeMaps = BeansObservables.observeMaps(
	// viewerContentProvider.getKnownElements(),
	// ConverterBean.class, new String[] { "description" });
	// comboViewer.setLabelProvider(new ObservableMapLabelProvider(
	// attributeMaps));
	// comboViewer.setInput(Observables.staticObservableList(model.getSupportTypes(),ConverterBean.class));

	comboViewer.setInput(model.getSupportTypes());
	IViewerObservableValue selection = ViewersObservables.observeSingleSelection(comboViewer);
	IObservableValue observableValue = BeansObservables.observeDetailValue(selection, PROPERTIES_NAME, null);
	context.bindValue(observableValue, BeansObservables.observeValue(model, PROPERTIES_SELECTED_TYPE));
}
 
Example 6
Source File: ConverterUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 对下拉列表和转换器列表进行绑定
 * @param context
 * @param comboViewer
 * @param model
 *            ;
 */
public static void bindValue(DataBindingContext context, ComboViewer comboViewer, ConverterViewModel model) {
	// ViewerSupport.bind(comboViewer, BeansObservables.observeList(
	// model, "supportTypes", String.class),
	// Properties.selfValue(String.class));
	//		
	//
	// context.bindValue(ViewersObservables
	// .observeSingleSelection(comboViewer), BeansObservables
	// .observeValue(model,
	// "selectedType"));

	// ObservableListContentProvider viewerContentProvider=new ObservableListContentProvider();
	comboViewer.setContentProvider(new ArrayContentProvider());
	comboViewer.setComparator(new ViewerComparator());
	// IObservableMap[] attributeMaps = BeansObservables.observeMaps(
	// viewerContentProvider.getKnownElements(),
	// ConverterBean.class, new String[] { "description" });
	// comboViewer.setLabelProvider(new ObservableMapLabelProvider(
	// attributeMaps));
	// comboViewer.setInput(Observables.staticObservableList(model.getSupportTypes(),ConverterBean.class));

	comboViewer.setInput(model.getSupportTypes());
	IViewerObservableValue selection = ViewersObservables.observeSingleSelection(comboViewer);
	IObservableValue observableValue = BeansObservables.observeDetailValue(selection, PROPERTIES_NAME, null);
	context.bindValue(observableValue, BeansObservables.observeValue(model, PROPERTIES_SELECTED_TYPE));
}
 
Example 7
Source File: ConverterUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public static void bindValue(DataBindingContext context,ComboViewer comboViewer,
			ConverterViewModel model) {
//		ViewerSupport.bind(comboViewer, BeansObservables.observeList(
//				model, "supportTypes", String.class),
//				Properties.selfValue(String.class));
//		
//
//		context.bindValue(ViewersObservables
//				.observeSingleSelection(comboViewer), BeansObservables
//				.observeValue(model,
//						"selectedType"));
		
//		ObservableListContentProvider viewerContentProvider=new ObservableListContentProvider();
		comboViewer.setContentProvider(new ArrayContentProvider());
		comboViewer.setComparator(new ViewerComparator());
//		IObservableMap[] attributeMaps = BeansObservables.observeMaps(
//				viewerContentProvider.getKnownElements(),
//				ConverterBean.class, new String[] { "description" });
//		comboViewer.setLabelProvider(new ObservableMapLabelProvider(
//		attributeMaps));
//		comboViewer.setInput(Observables.staticObservableList(model.getSupportTypes(),ConverterBean.class));
		
		comboViewer.setInput(model.getSupportTypes());
		IViewerObservableValue selection=ViewersObservables.observeSingleSelection(comboViewer);
		IObservableValue observableValue=BeansObservables.observeDetailValue(selection, "name", ConverterBean.class);
		context.bindValue(observableValue, BeansObservables
				.observeValue(model,
						"selectedType"));
	}
 
Example 8
Source File: ConverterUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 对下拉列表和转换器列表进行绑定
 * @param context
 * @param comboViewer
 * @param model
 *            ;
 */
public static void bindValue(DataBindingContext context, ComboViewer comboViewer, ConverterViewModel model) {
	// ViewerSupport.bind(comboViewer, BeansObservables.observeList(
	// model, "supportTypes", String.class),
	// Properties.selfValue(String.class));
	//		
	//
	// context.bindValue(ViewersObservables
	// .observeSingleSelection(comboViewer), BeansObservables
	// .observeValue(model,
	// "selectedType"));

	// ObservableListContentProvider viewerContentProvider=new ObservableListContentProvider();
	comboViewer.setContentProvider(new ArrayContentProvider());
	comboViewer.setComparator(new ViewerComparator());
	// IObservableMap[] attributeMaps = BeansObservables.observeMaps(
	// viewerContentProvider.getKnownElements(),
	// ConverterBean.class, new String[] { "description" });
	// comboViewer.setLabelProvider(new ObservableMapLabelProvider(
	// attributeMaps));
	// comboViewer.setInput(Observables.staticObservableList(model.getSupportTypes(),ConverterBean.class));

	comboViewer.setInput(model.getSupportTypes());
	IViewerObservableValue selection = ViewersObservables.observeSingleSelection(comboViewer);
	IObservableValue observableValue = BeansObservables.observeDetailValue(selection, PROPERTIES_NAME, null);
	context.bindValue(observableValue, BeansObservables.observeValue(model, PROPERTIES_SELECTED_TYPE));
}
 
Example 9
Source File: ConverterUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 对下拉列表和转换器列表进行绑定
 * @param context
 * @param comboViewer
 * @param model
 *            ;
 */
public static void bindValue(DataBindingContext context, ComboViewer comboViewer, ConverterViewModel model) {
	// ViewerSupport.bind(comboViewer, BeansObservables.observeList(
	// model, "supportTypes", String.class),
	// Properties.selfValue(String.class));
	//		
	//
	// context.bindValue(ViewersObservables
	// .observeSingleSelection(comboViewer), BeansObservables
	// .observeValue(model,
	// "selectedType"));

	// ObservableListContentProvider viewerContentProvider=new ObservableListContentProvider();
	comboViewer.setContentProvider(new ArrayContentProvider());
	comboViewer.setComparator(new ViewerComparator());
	// IObservableMap[] attributeMaps = BeansObservables.observeMaps(
	// viewerContentProvider.getKnownElements(),
	// ConverterBean.class, new String[] { "description" });
	// comboViewer.setLabelProvider(new ObservableMapLabelProvider(
	// attributeMaps));
	// comboViewer.setInput(Observables.staticObservableList(model.getSupportTypes(),ConverterBean.class));

	comboViewer.setInput(model.getSupportTypes());
	IViewerObservableValue selection = ViewersObservables.observeSingleSelection(comboViewer);
	IObservableValue observableValue = BeansObservables.observeDetailValue(selection, PROPERTIES_NAME, null);
	context.bindValue(observableValue, BeansObservables.observeValue(model, PROPERTIES_SELECTED_TYPE));
}
 
Example 10
Source File: ConverterUtil.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public static void bindValue(DataBindingContext context,ComboViewer comboViewer,
			ConverterViewModel model) {
//		ViewerSupport.bind(comboViewer, BeansObservables.observeList(
//				model, "supportTypes", String.class),
//				Properties.selfValue(String.class));
//		
//
//		context.bindValue(ViewersObservables
//				.observeSingleSelection(comboViewer), BeansObservables
//				.observeValue(model,
//						"selectedType"));
		
//		ObservableListContentProvider viewerContentProvider=new ObservableListContentProvider();
		comboViewer.setContentProvider(new ArrayContentProvider());
		comboViewer.setComparator(new ViewerComparator());
//		IObservableMap[] attributeMaps = BeansObservables.observeMaps(
//				viewerContentProvider.getKnownElements(),
//				ConverterBean.class, new String[] { "description" });
//		comboViewer.setLabelProvider(new ObservableMapLabelProvider(
//		attributeMaps));
//		comboViewer.setInput(Observables.staticObservableList(model.getSupportTypes(),ConverterBean.class));
		
		comboViewer.setInput(model.getSupportTypes());
		IViewerObservableValue selection=ViewersObservables.observeSingleSelection(comboViewer);
		IObservableValue observableValue=BeansObservables.observeDetailValue(selection, "name", ConverterBean.class);
		context.bindValue(observableValue, BeansObservables
				.observeValue(model,
						"selectedType"));
	}
 
Example 11
Source File: SimpleFileSetsEditor.java    From eclipse-cs with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Control createContents(Composite parent) throws CheckstylePluginException {

  mController = new Controller();

  // group composite containing the config settings
  Group configArea = new Group(parent, SWT.NULL);
  configArea.setText(Messages.SimpleFileSetsEditor_titleSimpleConfig);
  configArea.setLayout(new FormLayout());

  this.mBtnManageConfigs = new Button(configArea, SWT.PUSH);
  this.mBtnManageConfigs.setText(Messages.SimpleFileSetsEditor_btnManageConfigs);
  this.mBtnManageConfigs.addSelectionListener(mController);
  FormData fd = new FormData();
  fd.top = new FormAttachment(0, 3);
  fd.right = new FormAttachment(100, -3);
  this.mBtnManageConfigs.setLayoutData(fd);

  mComboViewer = new ComboViewer(configArea);
  mComboViewer.getCombo().setVisibleItemCount(10);
  mComboViewer.setContentProvider(new CheckConfigurationContentProvider());
  mComboViewer.setLabelProvider(new CheckConfigurationLabelProvider());
  mComboViewer.setComparator(new CheckConfigurationViewerSorter());
  mComboViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  mComboViewer.addSelectionChangedListener(mController);
  fd = new FormData();
  fd.left = new FormAttachment(0, 3);
  fd.top = new FormAttachment(0, 3);
  fd.right = new FormAttachment(mBtnManageConfigs, -3, SWT.LEFT);
  // fd.right = new FormAttachment(100, -3);
  mComboViewer.getCombo().setLayoutData(fd);

  // Description
  Label lblConfigDesc = new Label(configArea, SWT.LEFT);
  lblConfigDesc.setText(Messages.SimpleFileSetsEditor_lblDescription);
  fd = new FormData();
  fd.left = new FormAttachment(0, 3);
  fd.top = new FormAttachment(mComboViewer.getCombo(), 3, SWT.BOTTOM);
  fd.right = new FormAttachment(100, -3);
  lblConfigDesc.setLayoutData(fd);

  this.mTxtConfigDescription = new Text(configArea,
          SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.VERTICAL);
  fd = new FormData();
  fd.left = new FormAttachment(0, 3);
  fd.top = new FormAttachment(lblConfigDesc, 0, SWT.BOTTOM);
  fd.right = new FormAttachment(100, -3);
  fd.bottom = new FormAttachment(100, -3);
  this.mTxtConfigDescription.setLayoutData(fd);

  // init the check configuration combo
  mComboViewer.setInput(mPropertyPage.getProjectConfigurationWorkingCopy());
  if (mDefaultFileSet.getCheckConfig() != null) {
    mComboViewer.setSelection(new StructuredSelection(mDefaultFileSet.getCheckConfig()));
  }

  return configArea;
}