List of usage examples for org.eclipse.jface.viewers ListViewer setLabelProvider
@Override public void setLabelProvider(IBaseLabelProvider labelProvider)
Viewer framework method ensures that the given label provider is an instance of ILabelProvider. From source file:com.aptana.formatter.ui.preferences.AbstractFormatterSelectionBlock.java
License:Open Source License
protected void configurePreview(Composite composite, int numColumns) { createLabel(composite, FormatterMessages.AbstractFormatterSelectionBlock_preview, numColumns); Composite previewGroup = new Composite(composite, SWT.NONE); previewGroup.setLayout(new GridLayout(1, true)); GridData gd = new GridData(GridData.FILL_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan = numColumns;/*from ww w . ja v a2 s. com*/ previewGroup.setLayoutData(gd); // Adds a SashForm to create left and right areas. The left will hold the list of formatters, while the right // will hold a preview pane SashForm sashForm = new SashForm(previewGroup, SWT.HORIZONTAL); sashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); final ListViewer listViewer = new ListViewer(sashForm, SWT.SINGLE | SWT.BORDER); listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); // Add the right panel (code preview and buttons) Composite rightPanel = new Composite(sashForm, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; rightPanel.setLayout(layout); rightPanel.setLayoutData(new GridData(GridData.FILL_BOTH)); // Previews area final Composite previewPane = new Composite(rightPanel, SWT.BORDER); GridData previewGridData = new GridData(GridData.FILL_BOTH); previewGridData.heightHint = 300; previewGridData.widthHint = 450; previewPane.setLayoutData(previewGridData); previewStackLayout = new StackLayout(); previewPane.setLayout(previewStackLayout); // Set the data into the list listViewer.setContentProvider(ArrayContentProvider.getInstance()); listViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { IScriptFormatterFactory factory = (IScriptFormatterFactory) element; return factory.getName(); } }); listViewer.setInput(this.factories); if (selectedFormatter < 0) { selectedFormatter = 0; } listViewer.setSelection(new StructuredSelection(this.factories[selectedFormatter])); listViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // Update the preview selectedFormatter = listViewer.getList().getSelectionIndex(); if (selectedFormatter > -1 && selectedFormatter < sourcePreviewViewers.size()) { fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter); previewStackLayout.topControl = fSelectedPreviewViewer.getControl(); previewPane.layout(); updatePreview(); } } }); listViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (listViewer.getList().getSelectionIndex() > -1) { editButtonPressed(); } } }); for (IScriptFormatterFactory factory : this.factories) { SourceViewer sourcePreview = createSourcePreview(previewPane, factory); sourcePreviewViewers.add(sourcePreview); } if (selectedFormatter > -1 && sourcePreviewViewers.size() > selectedFormatter) { fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter); previewStackLayout.topControl = fSelectedPreviewViewer.getControl(); previewPane.layout(); } sashForm.setWeights(new int[] { 1, 3 }); // Attach the listeners profileChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (IProfileManager.PROFILE_SELECTED.equals(event.getProperty())) { IProfile profile = (IProfile) event.getNewValue(); fSelectedPreviewViewer = sourcePreviewViewers.get(selectedFormatter); previewStackLayout.topControl = fSelectedPreviewViewer.getControl(); previewPane.layout(); updatePreview(); fDefaultButton.setEnabled(!profile.isBuiltInProfile()); } } }; profileManager.addPropertyChangeListener(profileChangeListener); }
From source file:com.ebmwebsoucing.petals.repositories.explorer.wizards.RepositoryNewWizardPage.java
License:Open Source License
public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginLeft = 15;// w ww.j a v a 2s . com layout.marginRight = 15; layout.marginTop = 20; layout.horizontalSpacing = 15; container.setLayout(layout); container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Name Label label = new Label(container, SWT.NONE); label.setText("Name:"); label.setToolTipText("The name of the repository to create"); Text text = new Text(container, SWT.SINGLE | SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { RepositoryNewWizardPage.this.repositoryName = ((Text) e.widget).getText(); validate(); } }); // Description label = new Label(container, SWT.NONE); label.setText("Description:"); label.setToolTipText("The description of the repository to create"); text = new Text(container, SWT.SINGLE | SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { RepositoryNewWizardPage.this.repositoryDescription = ((Text) e.widget).getText(); validate(); } }); // Separation Composite comp = new Composite(container, SWT.NONE); layout = new GridLayout(2, false); layout.marginWidth = 0; layout.marginTop = 15; comp.setLayout(layout); GridData layoutData = new GridData(GridData.FILL_BOTH); layoutData.horizontalSpan = 2; comp.setLayoutData(layoutData); label = new Label(comp, SWT.NONE); label.setText("Select the Query API this repository supports."); layoutData = new GridData(GridData.FILL_HORIZONTAL); layoutData.horizontalSpan = 2; label.setLayoutData(layoutData); // Supported API final ListViewer viewer = new ListViewer(comp, SWT.SINGLE | SWT.BORDER); viewer.getList().setLayoutData(new GridData(GridData.FILL_BOTH)); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { String result = ""; if (element instanceof QueryApiBean) result = ((QueryApiBean) element).getQueryApi().toString() + " - " + ((QueryApiBean) element).getQueryUri(); return result; } }); viewer.setInput(this.queryApiBeans); // Buttons to add / remove an API Composite buttonsContainer = new Composite(comp, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; buttonsContainer.setLayout(layout); buttonsContainer.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, false)); Button addButton = new Button(buttonsContainer, SWT.PUSH); addButton.setText("Add..."); addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); addButton.setToolTipText("Add a new Query API"); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { QueryApiBeanDefinitionDialog dlg = new QueryApiBeanDefinitionDialog(getShell(), null); if (dlg.open() == Window.OK) { RepositoryNewWizardPage.this.queryApiBeans.add(dlg.getQueryApiBean()); viewer.refresh(); validate(); } } }); Button removeButton = new Button(buttonsContainer, SWT.PUSH); removeButton.setText("Remove"); removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); removeButton.setToolTipText("Remove a Query API"); removeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!viewer.getSelection().isEmpty()) { Object o = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); RepositoryNewWizardPage.this.queryApiBeans.remove(o); viewer.refresh(); validate(); } } }); setControl(container); }
From source file:com.vectrace.MercurialEclipse.ui.SWTWidgetHelper.java
License:Open Source License
/** * Creates a ListViewer/*from w w w.ja v a2 s . co m*/ * * @param parent * the parent of the viewer * @param title * the text for the title label * @param heightHint * the nominal height of the list * @param the * label decorator * @return the created list viewer */ public static ListViewer createListViewer(Composite parent, String title, int heightHint, IBaseLabelProvider labelProvider) { if (title != null) { createLabel(parent, title); } ListViewer listViewer = new ListViewer(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.MULTI); listViewer.setContentProvider(new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { return (Object[]) inputElement; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); listViewer.setLabelProvider(labelProvider); GridData data = new GridData(GridData.FILL_BOTH); data.heightHint = heightHint; listViewer.getList().setLayoutData(data); listViewer.setUseHashlookup(true); return listViewer; }
From source file:dummy.generate.executableskill.DummyExecutableSkillsDialog.java
License:Open Source License
private void createExecutableSkillsExportComposite(Composite parent) { Group group = new Group(parent, SWT.NONE); group.setLayout(GridLayoutFactory.fillDefaults().equalWidth(false).margins(4, 3).numColumns(2).create()); group.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); group.setText("Scenario List"); final ListViewer availableScenarioListViewer = new ListViewer(group); availableScenarioListViewer.getControl() .setLayoutData(GridDataFactory.fillDefaults().hint(500, 20).grab(true, true).create()); availableScenarioListViewer.setContentProvider(new ArrayContentProvider()); availableScenarioListViewer.setLabelProvider(new LabelProvider() { @Override// ww w. j a v a 2 s .com public String getText(Object element) { return ((DummyScenario) element).getName(); } }); List<DummyScenario> scenarios = DummyScenario.getAllScenarios(); availableScenarioListViewer.setInput(scenarios); if (scenarios.size() > 0) { chosenExSkillScenario = scenarios.get(0); availableScenarioListViewer.setSelection(new StructuredSelection(chosenExSkillScenario)); } Composite buttonComposite = new Composite(group, SWT.NONE); buttonComposite.setLayout(GridLayoutFactory.fillDefaults().equalWidth(true).create()); buttonComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); createGroupRoleLibSelection(buttonComposite); createGroupDefaultMappingSelection(buttonComposite); exportAMLButton = new Button(group, SWT.PUSH); exportAMLButton.setText("Export AML"); exportAMLButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean success = true; try { String filename = MasterFileDialog.saveFile(SupportedFileType.AML); DummyScenario.doExport(chosenExSkillScenario.getScenarioSkills(), roleLibFilepath, transformationMappingPath, filename); } catch (TransformerException e1) { success = false; } MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_INFORMATION | SWT.YES); messageBox.setText("AML Export"); if (success) { messageBox.setMessage( "Scenario: " + chosenExSkillScenario.getName() + " has been successfully exported"); } else { messageBox.setMessage( "An error occured while exporting scenario " + chosenExSkillScenario.getName() + "."); } } }); final Text goalskillText = new Text(group, SWT.BORDER | SWT.READ_ONLY); GridData textGridData = new GridData(); textGridData.horizontalSpan = 2; textGridData.minimumWidth = 400; textGridData.widthHint = 400; goalskillText.setLayoutData(textGridData); availableScenarioListViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) availableScenarioListViewer.getSelection(); chosenExSkillScenario = (DummyScenario) selection.getFirstElement(); String goalSkills = ""; for (String s : chosenExSkillScenario.getGoalSkills()) { if (!goalSkills.isEmpty()) { goalSkills += ","; } goalSkills += s; } goalskillText.setText(goalSkills); } }); }
From source file:dummy.sendscenario.ScenarioSelectionDialog.java
License:Open Source License
private void createExecutableSkillsExportComposite(Composite parent) { Group group = new Group(parent, SWT.NONE); group.setLayout(GridLayoutFactory.fillDefaults().equalWidth(false).margins(4, 3).create()); group.setLayoutData(GridDataFactory.fillDefaults().hint(500, 300).grab(true, true).create()); group.setText("Scenario List"); final ListViewer availableScenarioListViewer = new ListViewer(group); availableScenarioListViewer.getControl() .setLayoutData(GridDataFactory.fillDefaults().hint(500, 20).grab(true, true).create()); availableScenarioListViewer.setContentProvider(new ArrayContentProvider()); availableScenarioListViewer.setLabelProvider(new LabelProvider() { @Override// ww w . ja v a2 s .co m public String getText(Object element) { return ((DummyScenario) element).getName(); } }); List<DummyScenario> allAvailableScenarios = DummyScenario.getAllScenarios(); availableScenarioListViewer.setInput(allAvailableScenarios); //LISTENERS availableScenarioListViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) availableScenarioListViewer.getSelection(); chosenExSkillScenario = (DummyScenario) selection.getFirstElement(); } }); if (allAvailableScenarios.size() > 0) { chosenExSkillScenario = allAvailableScenarios.get(0); availableScenarioListViewer.setSelection(new StructuredSelection(chosenExSkillScenario)); } }
From source file:eu.esdihumboldt.hale.ui.io.action.wizard.ActionUIWizardPage.java
License:Open Source License
/** * @see ViewerWizardSelectionPage#createViewer(Composite) *//* w w w .j a v a 2 s .c o m*/ @Override protected Pair<StructuredViewer, Control> createViewer(Composite parent) { ListViewer viewer = new ListViewer(parent); viewer.setLabelProvider(new LabelProvider() { @Override public Image getImage(Object element) { if (element instanceof ActionUIWizardNode) { return ((ActionUIWizardNode) element).getImage(); } return super.getImage(element); } @Override public String getText(Object element) { if (element instanceof ActionUIWizardNode) { return ((ActionUIWizardNode) element).getActionUI().getDisplayName(); } return super.getText(element); } }); viewer.setContentProvider(ArrayContentProvider.getInstance()); List<ActionUI> list = ActionUIExtension.getInstance().getFactories(filter); List<ActionUIWizardNode> nodes = new ArrayList<ActionUIWizardNode>(); for (ActionUI action : list) { nodes.add(new ActionUIWizardNode(action, getContainer())); } viewer.setInput(nodes); return new Pair<StructuredViewer, Control>(viewer, viewer.getControl()); }
From source file:eu.esdihumboldt.hale.ui.io.instance.exportconfig.LoadConfigurationInstanceExportPage.java
License:Open Source License
/** * @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite) *///from ww w. j ava 2 s .c om @Override protected void createContent(Composite page) { // page has a grid layout with one column page.setLayout(new GridLayout(1, false)); // create list viewer to select provider ListViewer configurations = new ListViewer(page, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER); configurations.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); configurations.setContentProvider(ArrayContentProvider.getInstance()); // set all available export configurations in the list viewer List<IOConfiguration> confs = getWizard().getExportConfigurations(); configurations.setInput(confs); configurations.setLabelProvider(new LabelProvider() { /** * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) */ @Override public String getText(Object element) { if (element instanceof IOConfiguration) { Map<String, Value> providerConf = ((IOConfiguration) element).getProviderConfiguration(); String name = providerConf.get(PARAM_CONFIGURATION_NAME).getStringRepresentation(); String fileFormat = providerConf.get(PARAM_FILE_FORMAT).getStringRepresentation(); return name + " (" + fileFormat + ")"; } return super.getText(element); } }); configurations.setSelection(new StructuredSelection(confs.iterator().next()), true); description = new Text(page, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); // add listener to set page complete if description is inserted GridData data = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).create(); data.heightHint = 75; description.setLayoutData(data); // process current selection ISelection selection = configurations.getSelection(); setPageComplete(!selection.isEmpty()); update(selection); // process selection changes configurations.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); setPageComplete(!selection.isEmpty()); update(selection); } }); }
From source file:eu.hydrologis.jgrass.gpsnmea.actions.GpsSettingsComposite.java
License:Open Source License
public GpsSettingsComposite(final Shell parent) { gpsWasLoggingWhenOpened = GpsActivator.getDefault().isGpsLogging(); /*/*from w w w. j a v a2s . com*/ * Serial ports panel */ Group group = new Group(parent, SWT.None); group.setText(PreferenceConstants.PORTUSED); group.setLayout(new GridLayout(2, false)); GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); group.setLayoutData(gridData); portLabel = new Label(group, SWT.None); portLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); Button searchPortButton = new Button(group, SWT.BORDER | SWT.PUSH); searchPortButton.setText("search port"); searchPortButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String[] ports = getPorts(); final Shell shell = new Shell(parent.getShell()); shell.setSize(new Point(300, 400)); Point cursorLocation = parent.getShell().getDisplay().getCursorLocation(); shell.setLocation(cursorLocation); shell.setLayout(new GridLayout(2, true)); GridData gridDataList = new GridData( GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); gridDataList.horizontalSpan = 2; final ListViewer v = new ListViewer(shell, SWT.H_SCROLL | SWT.V_SCROLL); v.setLabelProvider(new LabelProvider()); v.setContentProvider(new ArrayContentProvider()); v.setInput(ports); v.getList().setLayoutData(gridDataList); Button ok = new Button(shell, SWT.BORDER | SWT.PUSH); ok.setText("Ok"); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) v.getSelection(); String firstElement = (String) selection.getFirstElement(); portLabel.setText(firstElement); gpsPortUsed = firstElement; // set the preference prefs.setValue(PreferenceConstants.PORTUSED, gpsPortUsed); shell.dispose(); } }); Button cancel = new Button(shell, SWT.BORDER | SWT.PUSH); cancel.setText("Cancel"); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.dispose(); } }); shell.open(); } }); /* * start stop gps connection panel */ Group group2 = new Group(parent, SWT.None); group2.setText("Start / Stop the Gps connection"); group2.setLayout(new GridLayout(2, true)); GridData gridData2 = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); group2.setLayoutData(gridData2); startButton = new Button(group2, SWT.BORDER | SWT.RADIO); startButton.setText("Start Gps"); startButton.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(GpsActivator.PLUGIN_ID, "icons/start16.png") //$NON-NLS-1$ .createImage()); startButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); startButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { PlatformGIS.runInProgressDialog("Starting Gps...", false, new IRunnableWithProgress() { public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { pm.beginTask("Connecting to the gps. This might take a minute...", IProgressMonitor.UNKNOWN); try { if (!GpsActivator.getDefault().isGpsConnected()) { GpsActivator.getDefault().startGps(); GpsActivator.getDefault().startGpsLogging(); isFirst = true; gpsIsOn = true; pm.done(); // add this as listener to gps GpsActivator.getDefault().addObserverToGps(GpsSettingsComposite.this); } } finally { pm.done(); } } }, false); } catch (Exception e1) { String message = "An error occurred while starting the gps logging."; ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, GpsActivator.PLUGIN_ID, e1); e1.printStackTrace(); } } }); stopButton = new Button(group2, SWT.BORDER | SWT.RADIO); stopButton.setText("Stop Gps"); stopButton.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(GpsActivator.PLUGIN_ID, "icons/stop16.png") //$NON-NLS-1$ .createImage()); stopButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); stopButton.setSelection(true); stopButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException { pm.beginTask("Stopping Gps...", IProgressMonitor.UNKNOWN); if (GpsActivator.getDefault().isGpsConnected()) { GpsActivator.getDefault().stopGpsLogging(); GpsActivator.getDefault().stopGps(); } gpsIsOn = false; pm.done(); // remove this as listener to gps GpsActivator.getDefault().removeObserverFromGps(GpsSettingsComposite.this); } }); } catch (Exception e1) { String message = "An error occurred while stopping the gps logging."; ExceptionDetailsDialog.openError(null, message, IStatus.ERROR, GpsActivator.PLUGIN_ID, e1); e1.printStackTrace(); } } }); text = new Text(group2, SWT.BORDER | SWT.MULTI); GridData gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL); gd.horizontalSpan = 2; text.setLayoutData(gd); text.setEditable(false); /* * distance and position preferences */ Group group3 = new Group(parent, SWT.None); group3.setText("Time and position settings"); group3.setLayout(new GridLayout(2, false)); GridData gridData3 = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL); group3.setLayoutData(gridData3); Label intervalLabel = new Label(group3, SWT.NONE); intervalLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); intervalLabel.setText(PreferenceConstants.INTERVAL_SECONDS); intervalText = new Text(group3, SWT.SINGLE | SWT.LEAD | SWT.BORDER); intervalText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); intervalText.setText(""); Label distanceLabel = new Label(group3, SWT.NONE); distanceLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); distanceLabel.setText(PreferenceConstants.DISTANCE_THRESHOLD); distanceText = new Text(group3, SWT.SINGLE | SWT.LEAD | SWT.BORDER); distanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); distanceText.setText(""); dummyModeButton = new Button(parent, SWT.CHECK); dummyModeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false)); dummyModeButton.setText(PreferenceConstants.TESTMODE); dummyModeButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { prefs.setValue(PreferenceConstants.TESTMODE, dummyModeButton.getSelection()); } }); /* * load saved preferences */ loadPreferences(); /* * ok and cancel buttons */ Composite okCancelComposite = new Composite(parent, SWT.NONE); okCancelComposite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); okCancelComposite.setLayout(new GridLayout(2, true)); Button okButton = new Button(okCancelComposite, SWT.PUSH); okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); okButton.setText("ok"); okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { savePreferences(); GpsActivator.getDefault().removeObserverFromGps(GpsSettingsComposite.this); if (!gpsWasLoggingWhenOpened) { GpsActivator.getDefault().stopGpsLogging(); } parent.close(); } }); Button cancelButton = new Button(okCancelComposite, SWT.PUSH); cancelButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); cancelButton.setText("cancel"); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { GpsActivator.getDefault().removeObserverFromGps(GpsSettingsComposite.this); if (!gpsWasLoggingWhenOpened) { GpsActivator.getDefault().stopGpsLogging(); } parent.close(); } }); }
From source file:eu.hydrologis.jgrass.netcdf.export.wizard.ListViewerProvider.java
License:Open Source License
/** * Creates the {@link ListViewer} inside the supplied parent {@link Composite}. * /*from w w w .j a v a 2 s. c om*/ * <p>Note that the parent has to be a gridlayout of 3 cols.</p> * * @param parent the parent composite. * @param itemsList the initial list of items to put in the list. */ public void create(Composite parent, final List<String> startItemsList) { itemsList.addAll(startItemsList); final ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.SINGLE | SWT.VERTICAL | SWT.V_SCROLL); Control control = listViewer.getControl(); GridData gD = new GridData(SWT.FILL, SWT.FILL, true, true); gD.horizontalSpan = 3; control.setLayoutData(gD); listViewer.setContentProvider(new IStructuredContentProvider() { @SuppressWarnings("unchecked") public Object[] getElements(Object inputElement) { List<String> v = (List<String>) inputElement; return v.toArray(); } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { System.out.println("Input changed: old=" + oldInput + ", new=" + newInput); } }); listViewer.setInput(itemsList); listViewer.setLabelProvider(new LabelProvider() { public Image getImage(Object element) { return null; } public String getText(Object element) { return ((String) element); } }); /* * buttons */ final Button buttonAdd = new Button(parent, SWT.PUSH); GridData addGd = new GridData(SWT.FILL, SWT.FILL, true, false); buttonAdd.setLayoutData(addGd); buttonAdd.setText("+"); final Button buttonModify = new Button(parent, SWT.PUSH); GridData modifyGd = new GridData(SWT.FILL, SWT.FILL, true, false); buttonModify.setLayoutData(modifyGd); buttonModify.setText("?"); final Button buttonRemove = new Button(parent, SWT.PUSH); GridData removeGd = new GridData(SWT.FILL, SWT.FILL, true, false); buttonRemove.setLayoutData(removeGd); buttonRemove.setText("-"); buttonAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { final String[] itemString = new String[1]; IInputValidator validator = new IInputValidator() { public String isValid(String newText) { String[] split = newText.split(":"); if (split.length >= 2) { itemString[0] = newText; return null; } else { return "The item format is: \"KEY: VALUE\"."; } } }; InputDialog iDialog = new InputDialog(buttonAdd.getShell(), "Add and item", "Add an item in the form: \"KEY: VALUE\".", "", validator); iDialog.open(); itemsList.add(itemString[0]); listViewer.setInput(itemsList); } }); buttonModify.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); String item = (String) selection.getFirstElement(); if (item == null) { return; } int indexOf = itemsList.indexOf(item); itemsList.remove(item); final String[] itemString = new String[1]; IInputValidator validator = new IInputValidator() { public String isValid(String newText) { String[] split = newText.split(":"); if (split.length == 2) { itemString[0] = newText; return null; } else { return "The item format is: \"KEY: VALUE\"."; } } }; InputDialog iDialog = new InputDialog(buttonAdd.getShell(), "Modify item", "Modify the item in the form: \"KEY: VALUE\".", item, validator); iDialog.open(); itemsList.add(indexOf, itemString[0]); listViewer.setInput(itemsList); } }); buttonRemove.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); String item = (String) selection.getFirstElement(); if (item == null) { return; } itemsList.remove(item); listViewer.setInput(itemsList); } }); }
From source file:io.aos.jface.Ch8.Ch8ListComposite.java
License:Apache License
private void createListViewer(int style) { ListViewer viewer = new ListViewer(this, style); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { return ((ListItem) element).name; }//from ww w. j a va 2 s . c o m }); viewer.addFilter(new ViewerFilter() { public boolean select(Viewer viewer, Object parent, Object element) { return ((ListItem) element).value % 2 == 0; } }); viewer.setSorter(new ViewerSorter() { public int compare(Viewer viewer, Object obj1, Object obj2) { return ((ListItem) obj2).value - ((ListItem) obj1).value; } }); viewer.setContentProvider(new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { return ((List) inputElement).toArray(); } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); List input = new ArrayList(); for (int i = 0; i < 20; i++) { input.add(new ListItem("item " + i, i)); } viewer.setInput(input); }