List of usage examples for org.eclipse.jface.viewers ListViewer getControl
@Override
public Control getControl()
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 w ww . ja va 2 s.c om*/ 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.bdaum.zoom.gps.widgets.LocationSelectionDialog.java
License:Open Source License
@Override protected Control createDialogArea(Composite parent) { Composite area = new Composite(parent, SWT.NONE); area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); area.setLayout(new GridLayout(1, false)); ListViewer viewer = new ListViewer(area, SWT.V_SCROLL | SWT.SINGLE); viewer.add(items);/* w w w. j av a 2s . co m*/ viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { result = (String) ((IStructuredSelection) event.getSelection()).getFirstElement(); close(); } }); viewer.getControl().addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { result = null; close(); } }); Shell shell = getShell(); shell.pack(); shell.layout(); viewer.getControl().setFocus(); return area; }
From source file:demo.MenuHandler.java
License:Open Source License
protected void newContact(Event event) { Employee newEmployee = null;// ww w. ja v a 2 s .co m ListViewer contacts = (ListViewer) XWT.findElementByName(event.widget, "contacts"); if (contacts == null) { return; } else { Company input = (Company) contacts.getInput(); newEmployee = Demo_modelFactory.eINSTANCE.createEmployee(); newEmployee.setFirstname("New"); newEmployee.setLastname("Employee"); newEmployee.setBirthday(new Date()); newEmployee.setEmail(""); newEmployee.setPhone(""); newEmployee.setPosition(""); Address address = Demo_modelFactory.eINSTANCE.createAddress(); address.setCity(""); address.setCountry(""); address.setState(""); address.setStreet(""); address.setZipcode(0); newEmployee.setAddress(address); input.getEmployees().add(newEmployee); contacts.refresh(); } Button writable = (Button) XWT.findElementByName(event.widget, "writable"); if (writable != null) { writable.setSelection(true); } if (contacts != null && newEmployee != null) { contacts.setSelection(new StructuredSelection(newEmployee)); contacts.getControl().notifyListeners(SWT.Selection, new Event()); } }
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/*from w w w .j a v a 2s . c om*/ 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/*w w w . j a v a2s . c o 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 ww .j a v a 2s . c om @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 w w w . j a v a 2 s . c o m*/ @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.esdihumboldt.hale.ui.transformation.TransformDataWizardSourcePage.java
License:Open Source License
/** * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) *//*from w w w .j av a 2 s . c o m*/ @Override public void createControl(Composite parent) { Composite content = new Composite(parent, SWT.NONE); content.setLayout(GridLayoutFactory.swtDefaults().create()); final ListViewer listViewer = new ListViewer(content); listViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()); if (!useProjectData) { Button addButton = new Button(content, SWT.PUSH); addButton.setText("Add source file"); addButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create()); addButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InstanceImportWizard importWizard = new InstanceImportWizard(); TransformDataImportAdvisor advisor = new TransformDataImportAdvisor(); // specifying null as actionId results in no call to // ProjectService.rememberIO importWizard.setAdvisor(advisor, null); new HaleWizardDialog(getShell(), importWizard).open(); if (advisor.getInstances() != null) { sourceCollections.add(advisor.getInstances()); listViewer.add(advisor.getLocation()); getContainer().updateButtons(); } } }); } else { // initialize project source data IRunnableWithProgress op = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Prepare data sources", IProgressMonitor.UNKNOWN); ProjectService ps = (ProjectService) PlatformUI.getWorkbench().getService(ProjectService.class); final List<URI> locations = new ArrayList<>(); for (Resource resource : ps.getResources()) { if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) { // resource is source data IOConfiguration conf = resource.copyConfiguration(true); TransformDataImportAdvisor advisor = new TransformDataImportAdvisor(); ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null); if (advisor.getInstances() != null) { sourceCollections.add(advisor.getInstances()); locations.add(advisor.getLocation()); } } } PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { for (URI location : locations) { listViewer.add(location); } } }); monitor.done(); } }; try { ThreadProgressMonitor.runWithProgressDialog(op, false); } catch (Exception e) { throw new IllegalStateException(e); } } setControl(content); }
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}. * // www . j a v a2 s . co m * <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:eu.numberfour.n4js.n4mf.ui.wizard.N4MFWizardNewProjectCreationPage.java
License:Open Source License
private Composite initLibraryOptionsUI(DataBindingContext dbc, Composite parent) { // Additional library project options final Group libraryProjectOptionsGroup = new Group(parent, NONE); libraryProjectOptionsGroup/*from w w w .ja v a 2s . c om*/ .setLayout(GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).create()); emptyPlaceholder(libraryProjectOptionsGroup); final Button createGreeterFileButton = new Button(libraryProjectOptionsGroup, CHECK); createGreeterFileButton.setText("Create a greeter file"); createGreeterFileButton.setLayoutData(GridDataFactory.fillDefaults().create()); new Label(libraryProjectOptionsGroup, SWT.NONE).setText("Implementation ID:"); final Text implementationIdText = new Text(libraryProjectOptionsGroup, BORDER); implementationIdText.setLayoutData(fillDefaults().align(FILL, SWT.CENTER).grab(true, false).create()); final Label implementedProjectsLabel = new Label(libraryProjectOptionsGroup, SWT.NONE); implementedProjectsLabel.setText("Implemented projects:"); implementedProjectsLabel .setLayoutData(GridDataFactory.fillDefaults().grab(false, true).align(SWT.LEFT, SWT.TOP).create()); final ListViewer apiViewer = new ListViewer(libraryProjectOptionsGroup, BORDER | MULTI); apiViewer.getControl().setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).span(1, 1).create()); apiViewer.setContentProvider(ArrayContentProvider.getInstance()); apiViewer.setInput(getAvailableApiProjectIds()); initApiViewerBinding(dbc, apiViewer); initImplementationIdBinding(dbc, implementationIdText); initDefaultCreateGreeterBindings(dbc, createGreeterFileButton); // Invalidate on change apiViewer.addSelectionChangedListener(e -> { setPageComplete(validatePage()); }); // Invalidate on change implementationIdText.addModifyListener(e -> { setPageComplete(validatePage()); }); return libraryProjectOptionsGroup; }