List of usage examples for org.eclipse.jface.viewers ComboViewer 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.atlassian.connector.eclipse.internal.crucible.ui.dialogs.CrucibleAddCommentDialog.java
License:Open Source License
protected void createCombo(Composite parent, final CustomFieldDef customField, int selection) { ((GridLayout) parent.getLayout()).numColumns++; Label label = new Label(parent, SWT.NONE); label.setText("Select " + customField.getName()); ((GridLayout) parent.getLayout()).numColumns++; ComboViewer comboViewer = new ComboViewer(parent); comboViewer.setContentProvider(new ArrayContentProvider()); comboViewer.setLabelProvider(new LabelProvider() { @Override// ww w . ja v a 2 s . com public String getText(Object element) { CustomFieldValue fieldValue = (CustomFieldValue) element; return fieldValue.getName(); } }); comboViewer.setInput(customField.getValues()); comboViewer.getCombo().setEnabled(false); customCombos.put(customField, comboViewer); }
From source file:com.atlassian.connector.eclipse.internal.crucible.ui.dialogs.CrucibleEditCommentDialog.java
License:Open Source License
protected void createCombo(Composite parent, final CustomFieldDef customField) { ((GridLayout) parent.getLayout()).numColumns++; Label label = new Label(parent, SWT.NONE); label.setText("Select " + customField.getName()); ((GridLayout) parent.getLayout()).numColumns++; ComboViewer comboViewer = new ComboViewer(parent); comboViewer.setContentProvider(new ArrayContentProvider()); comboViewer.setLabelProvider(new LabelProvider() { @Override/*from ww w .j av a 2s.co m*/ public String getText(Object element) { CustomFieldValue fieldValue = (CustomFieldValue) element; return fieldValue.getName(); } }); final ArrayList<CustomFieldValue> values = MiscUtil.buildArrayList(EMPTY_CUSTOM_FIELD_VALUE); values.addAll(customField.getValues()); comboViewer.setInput(values); comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateButtonsState(); } }); // setting default values for combo final CustomField commentCustomField = comment.getCustomFields().get(customField.getName()); if (commentCustomField != null) { for (CustomFieldValue value : customField.getValues()) { if (value.getName().equals(commentCustomField.getValue())) { ISelection selection = new StructuredSelection(MiscUtil.buildArrayList(value)); comboViewer.setSelection(selection, true); break; } } } else { comboViewer.setSelection(new StructuredSelection(MiscUtil.buildArrayList(EMPTY_CUSTOM_FIELD_VALUE)), true); } customCombos.put(customField, comboViewer); }
From source file:com.bdaum.zoom.ui.internal.preferences.ImportPreferencePage.java
License:Open Source License
private Composite createRawGroup(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); composite.setLayout(new GridLayout(1, false)); Composite rccomp = new Composite(composite, SWT.NONE); rccomp.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); rccomp.setLayout(new GridLayout(2, false)); new Label(rccomp, SWT.NONE).setText(Messages.getString("ImportPreferencePage.raw_converter2")); //$NON-NLS-1$ rcViewer = new ComboViewer(rccomp, SWT.NONE); rcViewer.setContentProvider(ArrayContentProvider.getInstance()); rcViewer.setLabelProvider(new LabelProvider() { @Override/* w ww .java 2s . c om*/ public String getText(Object element) { if (element instanceof IRawConverter) return ((IRawConverter) element).getName(); return super.getText(element); } }); Map<String, IRawConverter> rawConverters = BatchActivator.getDefault().getRawConverters(); rcViewer.setInput(rawConverters.values()); rcViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { updateRawOptions(); validate(); } }); basicsGroup = new CGroup(composite, SWT.NONE); basicsGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); basicsLayout = new StackLayout(); basicsGroup.setLayout(basicsLayout); basicsGroup.setText(Messages.getString("ImportPreferencePage.converter")); //$NON-NLS-1$ for (IRawConverter rc : rawConverters.values()) { String exec = rc.getExecutable(); if (!IRawConverter.NONE.equals(exec)) { Composite basicsComp = new Composite(basicsGroup, SWT.NONE); basicsComp.setLayout(new GridLayout(1, false)); FileEditor fileEditor = new FileEditor(basicsComp, SWT.OPEN | SWT.READ_ONLY, NLS.bind(IRawConverter.OPTIONAL.equals(exec) ? Messages.getString("ImportPreferencePage.external_executable") //$NON-NLS-1$ : Messages.getString("ImportPreferencePage.executable"), rc.getName()), //$NON-NLS-1$ true, Constants.EXEEXTENSION, Constants.EXEFILTERNAMES, null, null, false, true, dialogSettings); fileEditor.addListener(new Listener() { @Override public void handleEvent(Event event) { validate(); } }); String msg = rc.getVersionMessage(); if (msg != null) new Label(basicsComp, SWT.NONE).setText(msg); basicsFileEditors.put(rc.getId(), fileEditor); } } optionsGroup = new CGroup(composite, SWT.NONE); optionsGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false)); optionsLayout = new StackLayout(); optionsGroup.setLayout(optionsLayout); optionsGroup.setText(Messages.getString("ImportPreferencePage.options2")); //$NON-NLS-1$ for (IRawConverter rc : rawConverters.values()) { final IRawConverter rawConverter = rc; List<RawProperty> props = rawConverter.getProperties(); if (!props.isEmpty()) { Composite optionComp = new Composite(optionsGroup, SWT.NONE); optionComp.setLayout(new GridLayout(2, false)); for (RawProperty prop : props) { String type = prop.type; List<RawEnum> enums = prop.enums; if (enums != null && !enums.isEmpty()) { new Label(optionComp, SWT.NONE).setText(prop.name); ComboViewer viewer = new ComboViewer(optionComp, SWT.NONE); viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { if (element instanceof RawEnum) return ((RawEnum) element).value; return super.getText(element); } }); viewer.setContentProvider(ArrayContentProvider.getInstance()); viewer.setInput(enums); optionProps.put(prop.id, viewer); for (RawEnum rawEnum : enums) if (rawEnum.recipe) { viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { RawEnum e = (RawEnum) ((IStructuredSelection) event.getSelection()) .getFirstElement(); rawConverter.setUsesRecipes(e == null ? "" //$NON-NLS-1$ : e.id); updateThumbnailWarning(); } }); break; } } else if ("int".equals(type)) { //$NON-NLS-1$ new Label(optionComp, SWT.NONE).setText(prop.name); Spinner field = new Spinner(optionComp, SWT.BORDER); if (prop.max != null) try { field.setMaximum(Integer.parseInt(prop.max)); } catch (NumberFormatException e) { // do nothing } if (prop.min != null) try { field.setMinimum(Integer.parseInt(prop.min)); } catch (NumberFormatException e) { // do nothing } optionProps.put(prop.id, field); } else if ("boolean".equals(type)) //$NON-NLS-1$ optionProps.put(prop.id, WidgetFactory.createCheckButton(optionComp, prop.name, new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 2, 1))); else if ("label".equals(type)) //$NON-NLS-1$ new Label(optionComp, SWT.NONE).setText(prop.name); else { new Label(optionComp, SWT.NONE).setText(prop.name); optionProps.put(prop.id, new Text(optionComp, SWT.BORDER)); } } optionComps.put(rc.getId(), optionComp); } } allDetectors = CoreActivator.getDefault().getRecipeDetectors(); if (allDetectors != null && !allDetectors.isEmpty()) createRecipeGroup(composite); thumbnailWarning = new Label(composite, SWT.NONE); thumbnailWarning.setData(CSSProperties.ID, CSSProperties.ERRORS); thumbnailWarning.setText(Messages.getString("ImportPreferencePage.raw_thumbnail_warning")); //$NON-NLS-1$ archiveRecipesButton = WidgetFactory.createCheckButton(composite, Messages.getString("ImportPreferencePage.archive_recipes"), new GridData(SWT.BEGINNING, SWT.CENTER, //$NON-NLS-1$ false, false, 2, 1)); synchronizeRecipesButton = WidgetFactory.createCheckButton(composite, Messages.getString("ImportPreferencePage.immediate_update"), new GridData(SWT.BEGINNING, SWT.CENTER, //$NON-NLS-1$ false, false, 2, 1)); return composite; }
From source file:com.bdaum.zoom.ui.internal.views.DataEntryView.java
License:Open Source License
private Object createField(final Composite parent, final QueryField qfield, int style, int horSpan, int widthHint) { Label label = new Label(parent, SWT.NONE); label.setText(qfield.getLabelWithUnit()); label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, true, false, Math.abs(horSpan), 1); layoutData.horizontalIndent = 12;//from w ww .j a v a 2s .c o m final int qtype = qfield.getType(); switch (qtype) { case QueryField.T_BOOLEAN: final Button checkButton = new Button(parent, SWT.CHECK); checkButton.setData(UiConstants.LABEL, label); layoutData.grabExcessHorizontalSpace = false; checkButton.setLayoutData(layoutData); widgetMap.put(qfield, checkButton); checkButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!updateSet.contains(qfield)) putValue(qfield, checkButton.getSelection()); } }); return checkButton; case QueryField.T_DATE: { final DateComponent dateField = new DateComponent(parent, SWT.NONE); dateField.setData(UiConstants.LABEL, label); layoutData.widthHint = widthHint; dateField.setLayoutData(layoutData); dateField.addListener(new Listener() { @Override public void handleEvent(Event event) { if (!updateSet.contains(qfield)) putValue(qfield, dateField.getSelection()); } }); widgetMap.put(qfield, dateField); return dateField; } case QueryField.T_CURRENCY: { IFormatter formatter = qfield.getFormatter(); if (formatter != null) { final Text textField = new Text(parent, SWT.BORDER | style); textField.setData(UiConstants.LABEL, label); layoutData.widthHint = widthHint; textField.setLayoutData(layoutData); widgetMap.put(qfield, textField); textField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { if (!updateSet.contains(qfield)) { Object text = textField.getText(); if (!QueryField.VALUE_MIXED.equals(text)) { try { putValue(qfield, text = qfield.getFormatter().fromString((String) text)); hideFieldDeco(textField); } catch (ParseException e) { showError(textField, e.getMessage()); } } } } }); return textField; } final SpinnerComponent spinner = new SpinnerComponent(parent, SWT.BORDER); spinner.setData(UiConstants.LABEL, label); spinner.setDigits(Format.getCurrencyDigits()); spinner.setIncrement(1); spinner.setPageIncrement((int) Math.pow(10, Format.getCurrencyDigits())); spinner.setMinimum(0); spinner.setMaximum(Integer.MAX_VALUE); spinner.setLayoutData(layoutData); spinner.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { putCurrencyValue(qfield, spinner); } }); spinner.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent keyEvent) { switch (keyEvent.character) { case '+': spinner.setSelection(spinner.getSelection() + 1); putCurrencyValue(qfield, spinner); break; case '-': spinner.setSelection(spinner.getSelection() - 1); putCurrencyValue(qfield, spinner); break; } } }); widgetMap.put(qfield, spinner); return spinner; } case QueryField.T_FLOAT: case QueryField.T_FLOATB: case QueryField.T_POSITIVEFLOAT: { final Text textField = new Text(parent, SWT.BORDER | style); textField.setData(UiConstants.LABEL, label); layoutData.horizontalAlignment = widthHint == SWT.DEFAULT ? SWT.FILL : SWT.LEFT; layoutData.widthHint = widthHint; textField.setLayoutData(layoutData); textField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { if (!updateSet.contains(qfield)) { String text = textField.getText().trim(); if (text.isEmpty()) { putValue(qfield, Double.NaN); hideFieldDeco(textField); } else { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(8); try { double value = nf.parse(text).doubleValue(); if (qtype == QueryField.T_POSITIVEFLOAT && value < 0) showError(textField, Messages.getString("DataEntryView.must_be_positive")); //$NON-NLS-1$ else { putValue(qfield, value); hideFieldDeco(textField); } } catch (ParseException e) { showError(textField, Messages.getString("DataEntryView.bad_fp")); //$NON-NLS-1$ } } } } }); widgetMap.put(qfield, textField); return textField; } case QueryField.T_INTEGER: case QueryField.T_POSITIVEINTEGER: case QueryField.T_LONG: case QueryField.T_POSITIVELONG: if (qfield.getEnumeration() instanceof int[]) { final ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE); comboViewer.getControl().setData(UiConstants.LABEL, label); layoutData.horizontalAlignment = widthHint == SWT.DEFAULT ? SWT.FILL : SWT.LEFT; comboViewer.getCombo().setLayoutData(layoutData); comboViewer.setLabelProvider(new IntArrayLabelProvider(qfield)); comboViewer.setContentProvider(new IntArrayContentProvider(qfield)); comboViewer.setInput(this); comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!comboViewer.getControl().isDisposed() && !updateSet.contains(qfield) && !QueryField.VALUE_MIXED.equals(comboViewer.getCombo().getText())) putValue(qfield, comboViewer.getStructuredSelection().getFirstElement()); } }); widgetMap.put(qfield, comboViewer); return comboViewer; } final SpinnerComponent spinner = new SpinnerComponent(parent, SWT.BORDER); spinner.setData(UiConstants.LABEL, label); spinner.setLayoutData(layoutData); spinner.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { putIntegerValue(qfield, spinner); } }); spinner.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent keyEvent) { switch (keyEvent.character) { case '+': spinner.setSelection(spinner.getSelection() + 1); putIntegerValue(qfield, spinner); break; case '-': spinner.setSelection(spinner.getSelection() - 1); putIntegerValue(qfield, spinner); break; } } }); widgetMap.put(qfield, spinner); return spinner; case QueryField.T_OBJECT: case QueryField.T_LOCATION: case QueryField.T_CONTACT: case QueryField.T_STRING: { layoutData.horizontalAlignment = widthHint == SWT.DEFAULT ? SWT.FILL : SWT.LEFT; if (qfield.getEnumeration() instanceof String[]) { final ComboViewer comboViewer = new ComboViewer(parent, SWT.NONE); comboViewer.getControl().setData(UiConstants.LABEL, label); comboViewer.getCombo().setLayoutData(layoutData); widgetMap.put(qfield, comboViewer); comboViewer.setContentProvider(ArrayContentProvider.getInstance()); comboViewer.setLabelProvider(new StringArrayLabelProvider(qfield)); comboViewer.setInput(qfield.getEnumeration()); comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!updateSet.contains(qfield) && !QueryField.VALUE_MIXED.equals(comboViewer.getCombo().getText())) putValue(qfield, ((IStructuredSelection) comboViewer.getSelection()).getFirstElement()); } }); return comboViewer; } if (qfield.getSpellingOptions() == ISpellCheckingService.NOSPELLING || horSpan < 0) { final Text textField = new Text(parent, SWT.BORDER | style | (horSpan < 0 ? SWT.READ_ONLY : SWT.NONE)); textField.setData(UiConstants.LABEL, label); layoutData.widthHint = widthHint; if ((style & SWT.MULTI) != 0) layoutData.heightHint = 50; textField.setLayoutData(layoutData); widgetMap.put(qfield, textField); if (horSpan < 0) { Button editButton = new Button(parent, SWT.PUSH); textField.setData(EDITBUTTON, editButton); editButton.setToolTipText(NLS.bind(Messages.getString("DataEntryView.edit"), //$NON-NLS-1$ qfield.getLabel())); editButton.setText("..."); //$NON-NLS-1$ editButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Object result = handleEditButton(parent, qfield, valueMap.get(qfield)); if (result != null) { if (result instanceof BagChange) result = ((BagChange<?>) result).getDisplay(); putValue(qfield, result); String text = qfield.value2text(result, CLICK_TO_VIEW_DETAILS); textField.setText(text); updateActions(false); } } }); } else { textField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { if (!updateSet.contains(qfield)) { Object text = textField.getText(); if (!QueryField.VALUE_MIXED.equals(text)) { if (qfield.getFormatter() != null) try { text = qfield.getFormatter().fromString((String) text); putValue(qfield, text); hideFieldDeco(textField); } catch (ParseException e) { showError(textField, e.getMessage()); } else { putValue(qfield, text); hideFieldDeco(textField); } } } } }); } return textField; } final CheckedText checkedTextField = new CheckedText(parent, SWT.BORDER | style); checkedTextField.setData(UiConstants.LABEL, label); checkedTextField.setSpellingOptions(10, qfield.getSpellingOptions()); layoutData.horizontalAlignment = widthHint == SWT.DEFAULT ? SWT.FILL : SWT.LEFT; layoutData.widthHint = widthHint; if ((style & SWT.MULTI) != 0) layoutData.heightHint = 50; checkedTextField.setLayoutData(layoutData); checkedTextField.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { if (!updateSet.contains(qfield)) { String text = checkedTextField.getText(); if (!QueryField.VALUE_MIXED.equals(text)) { putValue(qfield, text); hideFieldDeco(checkedTextField); } } } }); widgetMap.put(qfield, checkedTextField); return checkedTextField; } } return null; }
From source file:com.bdaum.zoom.ui.preferences.AbstractPreferencePage.java
License:Open Source License
/** * Creates a combo viewer//from w w w. java 2s. co m * * @param parent * - parent container * @param lab * - label * @param options * - combo items * @param labelling * - either a String[] object with corresponding labels or a * LabelProvider * @param sort * - true if items are to be sorted alphabetically * @return combo viewer */ public static ComboViewer createComboViewer(Composite parent, String lab, final String[] options, final Object labelling, boolean sort) { if (lab != null) new Label(parent, SWT.NONE).setText(lab); ComboViewer viewer = new ComboViewer(parent); viewer.getControl().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); viewer.setContentProvider(ArrayContentProvider.getInstance()); if (labelling instanceof LabelProvider) viewer.setLabelProvider((LabelProvider) labelling); else viewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { if (labelling instanceof String[]) for (int i = 0; i < options.length; i++) if (options[i].equals(element)) return ((String[]) labelling)[i]; return super.getText(element); } }); if (sort) viewer.setComparator(ZViewerComparator.INSTANCE); viewer.setInput(options); return viewer; }
From source file:com.byterefinery.rmbench.dialogs.DDLExportWizardPage1.java
License:Open Source License
public void createControl(Composite parent) { final DDLExportWizard ddlWizard = (DDLExportWizard) getWizard(); GridLayout layout;/*from w w w . j a v a 2 s.c o m*/ GridData gd; final Composite composite = new Composite(parent, SWT.NONE); layout = new GridLayout(); layout.verticalSpacing = 10; composite.setLayout(layout); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final Composite connectionGroup = new Composite(composite, SWT.NONE); connectionGroup.setLayout(new GridLayout()); connectionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); final Button diffCheck = new Button(connectionGroup, SWT.CHECK); diffCheck.setText(Messages.DDLExportWizard1_generateDiff_label); diffCheck.setSelection(generateDiff); diffCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (!generateDiff) { if (dbmodels.length == 0) { MessageDialog.openInformation(getShell(), RMBenchMessages.ModelView_ExportDialog_Title, Messages.DDLExportWizard1_NoConnection); diffCheck.setSelection(false); return; } } generateDiff = diffCheck.getSelection(); connectionsViewer.getControl().setEnabled(generateDiff); checkCompleteState(); } }); connectionsViewer = new ListViewer(connectionGroup, SWT.SINGLE | SWT.BORDER); gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.minimumHeight = convertHeightInCharsToPixels(4); connectionsViewer.getList().setLayoutData(gd); connectionsViewer.setContentProvider(new ArrayContentProvider()); connectionsViewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { return ((DBModel) element).getName(); } }); connectionsViewer.setInput(dbmodels); if (dbmodel != null) connectionsViewer.setSelection(new StructuredSelection(dbmodel)); connectionsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); dbmodel = (DBModel) selection.getFirstElement(); checkCompleteState(); } }); connectionsViewer.getControl().setEnabled(generateDiff); final Button generateDropCheck = new Button(composite, SWT.CHECK); generateDropCheck.setText(Messages.DDLExportWizard1_generateDrop_text); generateDropCheck.setSelection(generateDrop); generateDropCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { generateDrop = generateDropCheck.getSelection(); } }); final Composite generatorGroup = new Composite(composite, SWT.NONE); generatorGroup.setLayout(new GridLayout()); generatorGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); final Label generatorLabel = new Label(generatorGroup, SWT.NONE); generatorLabel.setText(Messages.DDLExportWizard1_generator_label); generatorLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); final ComboViewer generatorsViewer = new ComboViewer(generatorGroup, SWT.DROP_DOWN | SWT.READ_ONLY); generatorsViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); generatorsViewer.setContentProvider(new ArrayContentProvider()); generatorsViewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { return ((DDLGeneratorExtension) element).getName(); } }); generatorsViewer.setInput(generators); generatorsViewer.setSelection(new StructuredSelection(generatorExtension)); generatorsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); DDLGeneratorExtension genExt = (DDLGeneratorExtension) selection.getFirstElement(); setGenerator(genExt); ddlWizard.setDDLGeneratorWizardPage(genExt.createGeneratorWizardPage(generator)); checkCompleteState(); } }); setControl(composite); checkCompleteState(); }
From source file:com.byterefinery.rmbench.dialogs.ModelPropertiesDialog.java
License:Open Source License
protected Control createDialogArea(Composite parent) { Composite mainComposite = (Composite) super.createDialogArea(parent); final Composite localComposite = new Composite(mainComposite, SWT.NONE); localComposite.setLayout(new GridLayout(2, false)); Label label;// w ww. j a v a2 s. c o m GridData gd; if (storageKey != null) { Composite storageComposite = new Composite(localComposite, SWT.NONE); gd = new GridData(SWT.FILL, SWT.NONE, true, false); gd.horizontalSpan = 2; storageComposite.setLayoutData(gd); GridLayout layout = new GridLayout(); layout.marginWidth = 0; storageComposite.setLayout(layout); label = new Label(storageComposite, SWT.NONE); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.BOTTOM, false, false)); label.setText(Messages.ModelPropertiesDialog_Location + " " + storageKey); label = new Label(storageComposite, SWT.SEPARATOR | SWT.HORIZONTAL); gd = new GridData(SWT.FILL, SWT.BOTTOM, true, false); gd.horizontalSpan = 2; label.setLayoutData(gd); } label = new Label(localComposite, SWT.NONE); label.setText(Messages.ModelPropertiesDialog_Name); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); final Text nameText = new Text(localComposite, SWT.BORDER | SWT.SINGLE); gd = new GridData(SWT.LEFT, SWT.FILL, false, true); gd.widthHint = convertWidthInCharsToPixels(MODEL_NAME_CHARS); nameText.setLayoutData(gd); nameText.setTextLimit(MODEL_NAME_CHARS); nameText.setText(modelName); nameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validateName(nameText.getText()); updateOKButton(); } }); label = new Label(localComposite, SWT.NONE); label.setText(Messages.ModelPropertiesDialog_Database); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); final ComboViewer dbCombo = new ComboViewer(localComposite, SWT.READ_ONLY | SWT.DROP_DOWN); dbCombo.getCombo().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false)); dbCombo.setContentProvider(new ArrayContentProvider()); dbCombo.setLabelProvider(new LabelProvider() { public String getText(Object element) { DatabaseExtension dbExt = (DatabaseExtension) element; return dbExt.getName(); } }); dbCombo.setInput(RMBenchPlugin.getExtensionManager().getDatabaseExtensions()); dbCombo.setSelection(new StructuredSelection(databaseExtension)); dbCombo.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); DatabaseExtension dbext = (DatabaseExtension) selection.getFirstElement(); if (dbext != databaseExtension) { boolean proceed = model.isEmpty() || MessageDialog.openQuestion(getShell(), Messages.ModelPropertiesDialog_ChangeModel_Title, Messages.ModelPropertiesDialog_ChangeModel_Message); if (proceed) { databaseExtension = dbext; updateOKButton(); } else { dbCombo.setSelection(new StructuredSelection(databaseExtension), true); } } } }); label = new Label(localComposite, SWT.NONE); label.setText(Messages.ModelPropertiesDialog_NameGenerator); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); final ComboViewer generatorCombo = new ComboViewer(localComposite, SWT.READ_ONLY | SWT.DROP_DOWN); generatorCombo.getCombo().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false)); generatorCombo.setContentProvider(new ArrayContentProvider()); generatorCombo.setLabelProvider(new LabelProvider() { public String getText(Object element) { NameGeneratorExtension genext = (NameGeneratorExtension) element; return genext.getName(); } }); generatorCombo.setInput(RMBenchPlugin.getExtensionManager().getNameGeneratorExtensions()); generatorCombo.setSelection(new StructuredSelection(generatorExtension)); generatorCombo.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); generatorExtension = (NameGeneratorExtension) selection.getFirstElement(); updateOKButton(); } }); return mainComposite; }
From source file:com.byterefinery.rmbench.dialogs.NewDiagramDialog.java
License:Open Source License
protected Control createDialogArea(Composite parent) { Composite mainComposite = (Composite) super.createDialogArea(parent); final Composite localComposite = new Composite(mainComposite, SWT.NONE); localComposite.setLayout(new GridLayout(2, false)); final Label nameLabel = new Label(localComposite, SWT.NONE); nameLabel.setText(Messages.NewDiagramDialog_Name); nameLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); final Text nameText = new Text(localComposite, SWT.BORDER | SWT.SINGLE); GridData gd = new GridData(SWT.LEFT, SWT.FILL, false, true); gd.widthHint = convertWidthInCharsToPixels(DIAGRAM_NAME_CHARS); nameText.setLayoutData(gd);// w ww . j a v a 2s . c om nameText.setTextLimit(DIAGRAM_NAME_CHARS); nameText.setText(diagramName); nameText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validateName(nameText.getText()); updateOKButton(); } }); final Label schemaLabel = new Label(localComposite, SWT.NONE); schemaLabel.setText(Messages.NewDiagramDialog_TargetSchema); schemaLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); final ComboViewer schemaCombo = new ComboViewer(localComposite, SWT.READ_ONLY | SWT.DROP_DOWN); schemaCombo.getCombo().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false)); schemaCombo.setContentProvider(new ArrayContentProvider()); schemaCombo.setLabelProvider(new LabelProvider() { public String getText(Object element) { Schema schema = (Schema) element; return schema.getName(); } }); Schema[] schemas = model.getSchemasArray(); schemaCombo.setInput(schemas); selectedSchema = schemas[0]; schemaCombo.setSelection(new StructuredSelection(selectedSchema), true); schemaCombo.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); selectedSchema = (Schema) selection.getFirstElement(); } }); errorMessageLabel = new Label(localComposite, SWT.NONE); errorMessageLabel.setForeground(ColorConstants.red); gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.horizontalSpan = 2; errorMessageLabel.setLayoutData(gd); return mainComposite; }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.VulnerabilityPage.java
License:Open Source License
private ComboViewer createApplicationCombo(Composite composite, String orgUuid) { ComboViewer combo = new ComboViewer(composite, SWT.READ_ONLY); combo.getControl().setFont(composite.getFont()); combo.setLabelProvider(new ContrastLabelProvider()); combo.setContentProvider(new ArrayContentProvider()); Set<ApplicationUIAdapter> contrastApplications = new LinkedHashSet<>(); int count = 0; if (orgUuid != null) { Applications applications = null; try {/*from www .j a va 2 s . co m*/ applications = getSdk().getApplications(orgUuid); } catch (Exception e) { ContrastUIActivator.log(e); } if (applications != null && applications.getApplications() != null && applications.getApplications().size() > 0) { for (Application application : applications.getApplications()) { ApplicationUIAdapter app = new ApplicationUIAdapter(application, application.getName()); contrastApplications.add(app); count++; } } } ApplicationUIAdapter allApplications = new ApplicationUIAdapter(null, "All Applications(" + count + ")"); contrastApplications.add(allApplications); combo.setInput(contrastApplications); IEclipsePreferences prefs = ContrastCoreActivator.getPreferences(); String appId = prefs.get(Constants.APPLICATION_ID, Constants.ALL_APPLICATIONS); ApplicationUIAdapter selected = allApplications; for (ApplicationUIAdapter adapter : contrastApplications) { if (appId.equals(adapter.getId())) { selected = adapter; break; } } combo.setInput(contrastApplications); combo.setSelection(new StructuredSelection(selected)); return combo; }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.VulnerabilityPage.java
License:Open Source License
private ComboViewer createServerCombo(Composite composite, String orgUuid) { ComboViewer combo = new ComboViewer(composite, SWT.READ_ONLY); combo.getControl().setFont(composite.getFont()); combo.setLabelProvider(new ContrastLabelProvider()); combo.setContentProvider(new ArrayContentProvider()); Set<ServerUIAdapter> contrastServers = new LinkedHashSet<>(); int count = 0; if (orgUuid != null) { Servers servers = null;/*ww w . j ava 2 s. c om*/ try { servers = getSdk().getServers(orgUuid, null); } catch (Exception e) { ContrastUIActivator.log(e); } if (servers != null && servers.getServers() != null) { for (Server server : servers.getServers()) { ServerUIAdapter contrastServer = new ServerUIAdapter(server, server.getName()); contrastServers.add(contrastServer); count++; } } } ServerUIAdapter allServers = new ServerUIAdapter(null, "All Servers(" + count + ")"); contrastServers.add(allServers); IEclipsePreferences prefs = ContrastCoreActivator.getPreferences(); long serverId = prefs.getLong(Constants.SERVER_ID, Constants.ALL_SERVERS); ServerUIAdapter selected = allServers; for (ServerUIAdapter adapter : contrastServers) { if (serverId == adapter.getId()) { selected = adapter; break; } } combo.setInput(contrastServers); combo.setSelection(new StructuredSelection(selected)); return combo; }