Example usage for org.eclipse.jface.viewers ComboViewer ComboViewer

List of usage examples for org.eclipse.jface.viewers ComboViewer ComboViewer

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ComboViewer ComboViewer.

Prototype

public ComboViewer(Composite parent, int style) 

Source Link

Document

Creates a combo viewer on a newly-created combo control under the given parent.

Usage

From source file:com.bdaum.zoom.ui.internal.dialogs.AutomatedRatingDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(area, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout());
    aiService = CoreActivator.getDefault().getAiService();
    ratingProviderIds = aiService.getRatingProviderIds();
    ratingProviderNames = aiService.getRatingProviderNames();
    CGroup providerGroup = CGroup.create(composite, 1, Messages.AutomatedRatingDialog_service);
    new Label(providerGroup, SWT.NONE).setText(Messages.AutomatedRatingDialog_provider);
    if (ratingProviderIds.length > 1) {
        providerViewer = new ComboViewer(providerGroup, SWT.NONE);
        providerViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
        providerViewer.setContentProvider(ArrayContentProvider.getInstance());
        providerViewer.setLabelProvider(new LabelProvider() {
            @Override//  ww w .j ava2 s . c om
            public String getText(Object element) {
                for (int i = 0; i < ratingProviderIds.length; i++)
                    if (ratingProviderIds[i].equals(element))
                        return ratingProviderNames[i];
                return super.getText(element);
            }
        });
        providerViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                selectedProvider = (String) providerViewer.getStructuredSelection().getFirstElement();
                updateModelViewer();
                validate();
            }
        });
    } else {
        new Label(providerGroup, SWT.NONE).setText(ratingProviderNames[0]);
        selectedProvider = ratingProviderIds[0];
    }
    new Label(providerGroup, SWT.NONE).setText(Messages.AutomatedRatingDialog_sujet);
    modelViewer = new ComboViewer(providerGroup, SWT.NONE);
    modelViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    modelViewer.setContentProvider(ArrayContentProvider.getInstance());
    modelViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            for (int i = 0; i < modelIds.length; i++)
                if (modelIds[i].equals(element))
                    return modelLabels[i];
            return super.getText(element);
        }
    });
    modelViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            validate();
        }
    });

    CGroup optionsGroup = CGroup.create(composite, 1, Messages.AutomatedRatingDialog_options);
    new Label(optionsGroup, SWT.NONE).setText(Messages.AutomatedRatingDialog_max_rating);
    maxField = new NumericControl(optionsGroup, SWT.NONE);
    maxField.setMinimum(1);
    maxField.setMaximum(5);
    overwriteButton = WidgetFactory.createCheckButton(optionsGroup, Messages.AutomatedRatingDialog_overwrite,
            null);
    return area;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.EditMetaDialog.java

License:Open Source License

private Composite createHeaderGroup(Composite comp) {
    final Composite header = new Composite(comp, SWT.NONE);
    header.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    header.setLayout(new GridLayout(4, false));
    // Line 1//  ww  w .  j a  va  2s. c  o m
    new Label(header, SWT.NONE).setText(Messages.EditMetaDialog_file_name);
    Composite catGroup = new Composite(header, SWT.NONE);
    catGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.marginWidth = 0;
    catGroup.setLayout(gridLayout);

    fileName = new Text(catGroup, SWT.READ_ONLY | SWT.BORDER);
    fileName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    fileName.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            BatchUtilities.showInFolder(new File(fileName.getText()));
        }
    });
    versionLabel = new Label(catGroup, SWT.NONE);

    GridData data = new GridData(SWT.END, SWT.CENTER, false, false);
    data.horizontalIndent = 20;
    versionLabel.setLayoutData(data);
    // Line 2
    new Label(header, SWT.NONE).setText(Messages.EditMetaDialog_catalog_theme);
    themeField = new ComboViewer(header, SWT.DROP_DOWN | SWT.READ_ONLY);
    themeField.getControl().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    themeField.setContentProvider(ArrayContentProvider.getInstance());
    themeField.setLabelProvider(new LabelProvider());
    themeField.setInput(CoreActivator.getDefault().getThemes().values());
    final BundleContext bundleContext = UiActivator.getDefault().getBundle().getBundleContext();
    final ServiceReference<?> ref = bundleContext.getServiceReference(ISpellCheckingService.class.getName());
    if (ref != null) {
        Label label = new Label(header, SWT.RIGHT);
        label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        label.setText(Messages.EditMetaDialog_language);
        final ISpellCheckingService service = (ISpellCheckingService) bundleContext.getService(ref);
        Collection<String> supportedLanguages = service.getSupportedLanguages();
        bundleContext.ungetService(ref);
        if (supportedLanguages != null && !supportedLanguages.isEmpty()) {
            languageCombo = new ComboViewer(header);
            languageCombo.setContentProvider(ArrayContentProvider.getInstance());
            languageCombo.setLabelProvider(new LabelProvider() {
                @Override
                public String getText(Object element) {
                    if (element instanceof String) {
                        String prefix = (String) element;
                        String variant = ""; //$NON-NLS-1$
                        int p = prefix.indexOf('_');
                        if (p > 0) {
                            p = prefix.indexOf('_', p + 1);
                            if (p > 0) {
                                String v = prefix.substring(p + 1);
                                if ("frami".equals(v)) //$NON-NLS-1$
                                    v = Messages.EditMetaDialog_frami;
                                variant = " (" + v + ')'; //$NON-NLS-1$
                                prefix = prefix.substring(0, p);
                            }
                        }
                        for (Locale locale : Locale.getAvailableLocales())
                            if (locale.toString().equals(prefix))
                                return locale.getDisplayName() + variant;
                    }
                    return super.getText(element);
                }
            });
            languageCombo.setComparator(ZViewerComparator.INSTANCE);
            languageCombo.setInput(supportedLanguages);
        } else {
            CLink link = new CLink(header, SWT.NONE);
            link.setText(Messages.EditMetaDialog_intall_dict);
            link.addListener(new Listener() {
                @Override
                public void handleEvent(Event event) {
                    try {
                        String language = Locale.getDefault().getLanguage();
                        String url = System.getProperty("com.bdaum.zoom.dictionaries." + language); //$NON-NLS-1$
                        if (url == null)
                            url = System.getProperty("com.bdaum.zoom.dictionaries"); //$NON-NLS-1$
                        PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser()
                                .openURL(new URL(url));
                    } catch (PartInitException e1) {
                        // do nothing
                    } catch (MalformedURLException e1) {
                        // should never happen
                    }
                }
            });
        }
    } else {
        Label label = new Label(header, SWT.NONE);
        label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 2, 1));
    }
    // Line 3
    Composite line3Comp = new Composite(header, SWT.NONE);
    line3Comp.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 2, 1));
    GridLayout layout = new GridLayout(3, false);
    layout.marginHeight = layout.marginWidth = 0;
    line3Comp.setLayout(layout);

    new Label(line3Comp, SWT.NONE).setText(Messages.EditMetaDialog_creation_date);

    creationDate = new Text(line3Comp, SWT.READ_ONLY | SWT.BORDER);
    creationDate.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));

    readOnlyButton = WidgetFactory.createCheckButton(line3Comp, Messages.EditMetaDialog_write_protected,
            new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 1, 1));
    readOnlyButton.addListener(new Listener() {
        @Override
        public void handleEvent(Event event) {
            readonly = readOnlyButton.getSelection();
            updateFolderButtons();
            updateButtons();
            updateFields();
        }
    });
    readOnlyButton.setEnabled(!newDb);

    Label label = new Label(header, SWT.RIGHT);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    label.setText(Messages.EditMetaDialog_last_import);

    lastImport = new Text(header, SWT.READ_ONLY | SWT.BORDER);
    lastImport.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (window != null) {
                LastImportCommand command = new LastImportCommand();
                command.init(window);
                command.run();
            }
        }
    });
    // Line 4
    new Label(header, SWT.NONE).setText(Messages.EditMetaDialog_seqno);

    seqNoField = new Text(header, SWT.READ_ONLY | SWT.BORDER);
    seqNoField.setLayoutData(new GridData(80, SWT.DEFAULT));

    label = new Label(header, SWT.RIGHT);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    label.setText(Messages.EditMetaDialog_yearlyseqno);

    yearlySeqNoField = new Text(header, SWT.READ_ONLY | SWT.BORDER);
    yearlySeqNoField.setLayoutData(new GridData(80, SWT.DEFAULT));

    // Line 5
    new Label(header, SWT.NONE).setText(Messages.EditMetaDialog_backup_file);
    Composite backupGroup = new Composite(header, SWT.NONE);
    backupGroup.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 3, 1));
    gridLayout = new GridLayout(3, false);
    gridLayout.marginWidth = 0;
    backupGroup.setLayout(gridLayout);
    backupField = new TextWithVariableGroup(backupGroup, null, 400, Constants.BV_ALL, false, null, null, null); // $NON-NLS-1$
    backupIntervalLink = new CLink(backupGroup, SWT.NONE);
    backupIntervalLink.setText(Messages.EditMetaDialog_configure_interval);
    backupIntervalLink.addListener(new Listener() {
        @Override
        public void handleEvent(Event event) {
            PreferencesUtil
                    .createPreferenceDialogOn(getShell(), GeneralPreferencePage.ID, new String[0], "backup") //$NON-NLS-1$
                    .open();
            updateBackupTooltip();
        }
    });
    final Composite editArea = new Composite(comp, SWT.NONE);
    editArea.setLayout(new GridLayout());
    editArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    return editArea;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.OutputTargetGroup.java

License:Open Source License

/**
 * @param parent//from  w  w  w .ja  v a  2 s  .c om
 *            - parent composite
 * @param gridData
 *            - layout data
 * @param listener
 *            - is informed about all changes except changes in the subfolder
 *            option
 * @param subfolders
 *            - true if the subfolder option shall be shown
 * @param ftp
 *            - true if FTP targets are supported
 * @param showSettingsOption
 *            - true if target specific options can be selected
 */
@SuppressWarnings("unused")
public OutputTargetGroup(final Composite parent, GridData gridData, final Listener listener, boolean subfolders,
        boolean ftp, boolean showSettingsOption) {
    ftpAccounts = FtpAccount.getAllAccounts();
    ftpAccounts.add(0, new FtpAccount());
    group = new CGroup(parent, SWT.NONE);
    group.setText(Messages.OutputTargetGroup_output_target);
    group.setLayoutData(gridData);
    group.setLayout(new GridLayout(ftp ? 4 : 3, false));
    if (ftp) {
        fileButton = new Button(group, SWT.RADIO);
        fileButton.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                updateFields();
                notifyListener(listener, event, FILE);
                browseButton.setEnabled(true);
            }
        });
    }
    final Label folderLabel = new Label(group, SWT.NONE);
    folderLabel.setText(Messages.OutputTargetGroup_local_folder);
    folderField = new Combo(group, SWT.BORDER | SWT.READ_ONLY);
    GridData data = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    data.widthHint = 300;
    folderField.setLayoutData(data);
    if (listener != null)
        folderField.addListener(SWT.Modify, listener);
    browseButton = new Button(group, SWT.PUSH);
    browseButton.setText(Messages.WebGalleryEditDialog_browse);
    browseButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.OPEN);
            dialog.setText(Messages.OutputTargetGroup_output_folder);
            dialog.setMessage(Messages.OutputTargetGroup_select_output_folder);
            String path = folderField.getText();
            if (!path.isEmpty())
                dialog.setFilterPath(path);
            String dir = dialog.open();
            if (dir != null) {
                folderField.setItems(UiUtilities.addToHistoryList(folderField.getItems(), dir));
                folderField.setText(dir);
                notifyListener(listener, event, FILE);
            }
        }
    });
    if (ftp) {
        ftpButton = new Button(group, SWT.RADIO);
        ftpButton.addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                updateFields();
                notifyListener(listener, event, FTP);
                browseButton.setEnabled(false);
            }
        });
        final Label ftpLabel = new Label(group, SWT.NONE);
        ftpLabel.setText(Messages.OutputTargetGroup_ftp_directory);
        ftpViewer = new ComboViewer(group, SWT.BORDER | SWT.READ_ONLY);
        ftpViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
        ftpViewer.setContentProvider(ArrayContentProvider.getInstance());
        ftpViewer.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                if (element instanceof FtpAccount) {
                    String name = ((FtpAccount) element).getName();
                    return name == null ? Messages.OutputTargetGroup_create_new_account : name;
                }
                return super.getText(element);
            }
        });
        editButton = new Button(group, SWT.PUSH);
        editButton.setText(Messages.OutputTargetGroup_edit);
        editButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                Object el = ftpViewer.getStructuredSelection().getFirstElement();
                if (el instanceof FtpAccount) {
                    FtpAccount account = (FtpAccount) el;
                    boolean createNew = account.getName() == null;
                    EditFtpDialog dialog = new EditFtpDialog(editButton.getShell(), account, false, null);
                    if (dialog.open() == Window.OK) {
                        FtpAccount result = dialog.getResult();
                        if (createNew) {
                            ftpAccounts.add(0, new FtpAccount());
                            ftpViewer.setInput(ftpAccounts);
                            ftpViewer.setSelection(new StructuredSelection(result));
                        } else
                            ftpViewer.update(result, null);
                        FtpAccount.saveAccounts(ftpAccounts);
                    }
                }
            }
        });
        ftpViewer.setInput(ftpAccounts);
        if (ftpAccounts.size() == 1)
            ftpViewer.setSelection(new StructuredSelection(ftpAccounts.get(0)));
        ftpViewer.getCombo().addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                updateFields();
                notifyListener(listener, event, FTP);
            }
        });
    }
    if (subfolders) {
        Meta meta = Core.getCore().getDbManager().getMeta(true);
        String timelinemode = meta.getTimeline();
        final String[] subfolderoptions = Meta.timeline_no.equals(timelinemode)
                ? new String[] { Constants.BY_NONE, Constants.BY_RATING, Constants.BY_CATEGORY,
                        Constants.BY_STATE, Constants.BY_JOB, Constants.BY_EVENT, Constants.BY_DATE,
                        Constants.BY_TIME }
                : new String[] { Constants.BY_NONE, Constants.BY_TIMELINE, Constants.BY_NUM_TIMELINE,
                        Constants.BY_RATING, Constants.BY_CATEGORY, Constants.BY_STATE, Constants.BY_JOB,
                        Constants.BY_EVENT, Constants.BY_DATE, Constants.BY_TIME };
        final String[] OPTIONLABELS = Meta.timeline_no.equals(timelinemode)
                ? new String[] { Messages.OutputTargetGroup_none, Messages.OutputTargetGroup_rating,
                        Messages.OutputTargetGroup_category, Messages.OutputTargetGroup_state,
                        Messages.OutputTargetGroup_job_id, Messages.OutputTargetGroup_event,
                        Messages.OutputTargetGroup_export_date, Messages.OutputTargetGroup_export_time }
                : new String[] { Messages.OutputTargetGroup_none, Messages.OutputTargetGroup_timeline,
                        Messages.OutputTargetGroup_timeline_num, Messages.OutputTargetGroup_rating,
                        Messages.OutputTargetGroup_category, Messages.OutputTargetGroup_state,
                        Messages.OutputTargetGroup_job_id, Messages.OutputTargetGroup_event,
                        Messages.OutputTargetGroup_export_date, Messages.OutputTargetGroup_export_time };
        new Label(group, SWT.NONE);
        new Label(group, SWT.NONE).setText(Messages.OutputTargetGroup_group_by);
        subfolderViewer = new ComboViewer(group);
        subfolderViewer.setContentProvider(ArrayContentProvider.getInstance());
        subfolderViewer.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(Object element) {
                for (int i = 0; i < subfolderoptions.length; i++)
                    if (subfolderoptions[i].equals(element))
                        return OPTIONLABELS[i];
                return super.getText(element);
            }
        });
        subfolderViewer.getCombo().addListener(SWT.Selection, new Listener() {
            @Override
            public void handleEvent(Event event) {
                subfolderoption = ((String) subfolderViewer.getStructuredSelection().getFirstElement());
                notifyListener(listener, event, SUBFOLDER);
            }
        });
        subfolderViewer.setInput(subfolderoptions);
    }
    if (showSettingsOption) {
        settingsOption = WidgetFactory.createCheckButton(group, Messages.OutputTargetGroup_target_specific,
                null, Messages.OutputTargetGroup_target_specific_tooltip);
        settingsOption.addListener(new Listener() {
            @Override
            public void handleEvent(Event event) {
                notifyListener(listener, event, SETTINGS);
            }
        });
    }
}

From source file:com.bdaum.zoom.ui.internal.dialogs.TemplateEditDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite comp = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) comp.getLayout();
    layout.marginWidth = 10;//from   ww w.  j  a  v  a2  s. co  m
    layout.marginHeight = 5;
    layout.verticalSpacing = 10;

    final Composite composite = new Composite(comp, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayout_1 = new GridLayout();
    gridLayout_1.numColumns = 2;
    composite.setLayout(gridLayout_1);
    new Label(composite, SWT.NONE).setText(Messages.TemplateEditDialog_name);
    nameField = new Text(composite, SWT.BORDER);
    nameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    nameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateButtons();
        }
    });

    new Label(composite, SWT.NONE).setText(Messages.TemplateEditDialog_template);
    templateField = new Text(composite, SWT.BORDER);
    templateField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    templateField.addVerifyListener(new VerifyListener() {
        public void verifyText(VerifyEvent e) {
            for (int i = 0; i < e.text.length(); i++)
                if (INVALIDCAHRS.indexOf(e.text.charAt(i)) >= 0) {
                    e.doit = false;
                    return;
                }
        }
    });
    templateField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateButtons();
            computeExample();
        }
    });
    new Label(composite, SWT.NONE).setText(Messages.TemplateEditDialog_example);
    exampleField = new Text(composite, SWT.READ_ONLY | SWT.BORDER);
    final GridData gd_exampleField = new GridData(SWT.FILL, SWT.CENTER, true, false);
    exampleField.setLayoutData(gd_exampleField);

    final Composite buttonComp = new Composite(comp, SWT.NONE);
    buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    buttonComp.setLayout(gridLayout);
    final ISelectionChangedListener varListener = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            templateField.insert(
                    selectedVar = (String) ((IStructuredSelection) event.getSelection()).getFirstElement());
            varViewer.getCombo().setVisible(false);
        }
    };
    addVariableButton = new Button(buttonComp, SWT.PUSH);
    addVariableButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    addVariableButton.setText(Messages.TemplateEditDialog_add_var);
    addVariableButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            varViewer.getCombo().setVisible(true);
            if (selectedVar != null) {
                varViewer.removeSelectionChangedListener(varListener);
                varViewer.setSelection(new StructuredSelection(selectedVar));
                varViewer.addSelectionChangedListener(varListener);
            }
        }
    });
    varViewer = new ComboViewer(buttonComp, SWT.NONE);
    Combo vcontrol = varViewer.getCombo();
    vcontrol.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    vcontrol.setVisibleItemCount(10);
    vcontrol.setVisible(false);
    varViewer.setContentProvider(ArrayContentProvider.getInstance());
    varViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                String varName = ((String) element);
                if (varName.startsWith("{") && varName.endsWith("}")) //$NON-NLS-1$ //$NON-NLS-2$
                    return element + TemplateMessages
                            .getString(TemplateMessages.PREFIX + varName.substring(1, varName.length() - 1));
            }
            return super.getText(element);
        }
    });
    varViewer.addSelectionChangedListener(varListener);
    varViewer.setInput(variables);
    if (asset != null) {
        addMetadataButton = new Button(buttonComp, SWT.PUSH);
        addMetadataButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
        addMetadataButton.setText(Messages.TemplateEditDialog_add_metadata);
        addMetadataButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                TemplateFieldSelectionDialog dialog = new TemplateFieldSelectionDialog(getShell());
                if (dialog.open() != TemplateFieldSelectionDialog.OK)
                    return;
                FieldDescriptor fd = dialog.getResult();
                templateField.insert(Constants.TV_META + (fd.subfield == null ? fd.qfield.getId()
                        : fd.qfield.getId() + '&' + fd.subfield.getId()) + '}');
            }
        });
        new Label(buttonComp, SWT.NONE).setText(Messages.TemplateEditDialog_example_shows_metadata);
    }
    return comp;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.WebGalleryEditDialog.java

License:Open Source License

private void createEngineGroup(Composite comp) {
    comp.setLayout(new GridLayout(2, false));
    CGroup group = new CGroup(comp, SWT.NONE);
    group.setText(Messages.WebGalleryEditDialog_engine);
    group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    group.setLayout(new GridLayout());
    engineViewer = new ComboViewer(group, SWT.READ_ONLY);
    engineViewer.getControl().setLayoutData(new GridData(150, SWT.DEFAULT));
    engineViewer.setContentProvider(ArrayContentProvider.getInstance());
    engineViewer.setLabelProvider(new LabelProvider() {
        @Override/*  ww w . j a  v a 2s  .com*/
        public String getText(Object element) {
            if (element instanceof IConfigurationElement)
                return ((IConfigurationElement) element).getAttribute("name"); //$NON-NLS-1$
            return super.getText(element);
        }
    });
    engineViewer.setComparator(ZViewerComparator.INSTANCE);
    engineViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateParms();
            fillPreview();
        }
    });
    parmComp = new Composite(comp, SWT.NONE);
    parmComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    parmComp.setLayout(new StackLayout());
    emptyComp = new Composite(parmComp, SWT.NONE);
    for (IConfigurationElement element : generators) {
        Composite genComp = new Composite(parmComp, SWT.NONE);
        genComp.setLayout(new GridLayout(2, false));
        String ns = element.getNamespaceIdentifier();
        compMap.put(element.getAttribute("id"), genComp); //$NON-NLS-1$
        Composite lastParent = genComp;
        for (IConfigurationElement child : element.getChildren()) {
            if ("group".equals(child.getName())) { //$NON-NLS-1$
                group = new CGroup(genComp, SWT.NONE);
                group.setText(child.getAttribute("name")); //$NON-NLS-1$
                group.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
                group.setLayout(new GridLayout(2, false));
                lastParent = group;
            } else
                createParmControl(lastParent, ns, child);
        }
    }
}

From source file:com.bdaum.zoom.ui.internal.preferences.AppearancePreferencePage.java

License:Open Source License

private Control createColorSchemeGroup(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));
    CGroup schemeGroup = UiUtilities.createGroup(composite, 2,
            Messages.getString("AppearancePreferencePage.bg_color")); //$NON-NLS-1$
    List<String> dropins = new ArrayList<String>();
    String path = Platform.getInstallLocation().getURL().getPath();
    File installFolder = new File(path);
    scanCSSDropins(dropins, new File(installFolder, CssActivator.DROPINFOLDER));
    scanCSSDropins(dropins, new File(installFolder.getParentFile(), CssActivator.DROPINFOLDER));
    String[] colorOptions = new String[dropins.size() + 5];
    String[] colorLabels = new String[dropins.size() + 5];
    if (Constants.OSX)
        colorLabels[0] = "OS X"; //$NON-NLS-1$
    else if (Constants.WIN32)
        colorLabels[0] = "Windows"; //$NON-NLS-1$
    else if (Platform.WS_GTK.equals(Platform.getWS()))
        colorLabels[0] = "GTK"; //$NON-NLS-1$
    else if (Platform.WS_MOTIF.equals(Platform.getWS()))
        colorLabels[0] = "Motif"; //$NON-NLS-1$
    else/*from  w w w . ja  va2  s .com*/
        colorLabels[0] = Messages.getString("AppearancePreferencePage.platform"); //$NON-NLS-1$
    colorOptions[0] = PreferenceConstants.BACKGROUNDCOLOR_PLATFORM;
    colorLabels[1] = Messages.getString("AppearancePreferencePage.black"); //$NON-NLS-1$
    colorOptions[1] = PreferenceConstants.BACKGROUNDCOLOR_BLACK;
    colorLabels[2] = Messages.getString("AppearancePreferencePage.dark_grey"); //$NON-NLS-1$
    colorOptions[2] = PreferenceConstants.BACKGROUNDCOLOR_DARKGREY;
    colorLabels[3] = Messages.getString("AppearancePreferencePage.grey"); //$NON-NLS-1$
    colorOptions[3] = PreferenceConstants.BACKGROUNDCOLOR_GREY;
    colorLabels[4] = Messages.getString("AppearancePreferencePage.white"); //$NON-NLS-1$
    colorOptions[4] = PreferenceConstants.BACKGROUNDCOLOR_WHITE;
    int j = 5;
    for (String name : dropins)
        colorOptions[j] = colorLabels[j++] = name;
    colorViewer = createComboViewer(schemeGroup, null, colorOptions, colorLabels, false);
    comment = new Label(schemeGroup, SWT.NONE);
    comment.setText(Messages.getString("AppearancePreferencePage.switching_to_platform_colors")); //$NON-NLS-1$
    GridData layoutData = new GridData();
    layoutData.horizontalIndent = 15;
    comment.setLayoutData(layoutData);
    comment.setVisible(false);
    colorViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object newTheme = colorViewer.getStructuredSelection().getFirstElement();
            comment.setVisible(
                    PreferenceConstants.BACKGROUNDCOLOR_PLATFORM.equals(newTheme) && !newTheme.equals(theme));
        }
    });
    CGroup unitGroup = UiUtilities.createGroup(composite, 2,
            Messages.getString("AppearancePreferencePage.units")); //$NON-NLS-1$
    new Label(unitGroup, SWT.NONE).setText(Messages.getString("AppearancePreferencePage.distances")); //$NON-NLS-1$
    distViewer = new ComboViewer(unitGroup, SWT.NONE);
    distViewer.setContentProvider(ArrayContentProvider.getInstance());
    distViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                if (((String) element).startsWith("m")) //$NON-NLS-1$
                    return Messages.getString("AppearancePreferencePage.miles"); //$NON-NLS-1$
                if (((String) element).startsWith("n")) //$NON-NLS-1$
                    return Messages.getString("AppearancePreferencePage.nautical"); //$NON-NLS-1$
            }
            return Messages.getString("AppearancePreferencePage.kilometers"); //$NON-NLS-1$
        }
    });
    distViewer.setInput(new String[] { "k", "m", "n" }); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    new Label(unitGroup, SWT.NONE).setText(Messages.getString("AppearancePreferencePage.physical_dims")); //$NON-NLS-1$
    dimViewer = new ComboViewer(unitGroup, SWT.NONE);
    dimViewer.setContentProvider(ArrayContentProvider.getInstance());
    dimViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                if (((String) element).startsWith("i")) //$NON-NLS-1$
                    return Messages.getString("AppearancePreferencePage.inches"); //$NON-NLS-1$
            }
            return Messages.getString("AppearancePreferencePage.centimeters"); //$NON-NLS-1$
        }
    });
    dimViewer.setInput(new String[] { "c", "i" }); //$NON-NLS-1$//$NON-NLS-2$
    return composite;
}

From source file:com.bdaum.zoom.ui.internal.preferences.ColorCodeGroup.java

License:Open Source License

@SuppressWarnings("unused")
public ColorCodeGroup(Composite autoGroup, int index, PreferencePage page) {
    this.page = page;
    new Label(autoGroup, SWT.BORDER).setImage(Icons.toSwtColors(index));
    new Label(autoGroup, SWT.NONE);
    critGroupCombo = new ComboViewer(autoGroup, SWT.READ_ONLY | SWT.BORDER);
    Combo comboControl = critGroupCombo.getCombo();
    comboControl.setVisibleItemCount(10);
    critGroupCombo.setContentProvider(ArrayContentProvider.getInstance());
    critGroupCombo.setFilters(new ViewerFilter[] { new GroupComboCatFilter() });
    critGroupCombo.setLabelProvider(new GroupComboLabelProvider());
    critGroupCombo.setInput(QueryField.getCategoriesAndSubgroups());
    critGroupCombo.setSelection(new StructuredSelection(QueryField.CATEGORY_ALL));
    comboControl.setLayoutData(new GridData(80, SWT.DEFAULT));
    critFieldCombo = new Combo(autoGroup, SWT.READ_ONLY | SWT.BORDER);
    critFieldCombo.setLayoutData(new GridData(200, SWT.DEFAULT));
    critFieldCombo.setVisibleItemCount(10);
    critRelationCombo = new Combo(autoGroup, SWT.READ_ONLY | SWT.BORDER);
    critRelationCombo.setLayoutData(new GridData(80, SWT.DEFAULT));
    valueComp = new Composite(autoGroup, SWT.NONE);
    valueComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    valueLayout = new StackLayout();
    valueComp.setLayout(valueLayout);/*from   w ww.java  2  s  .  c o  m*/
    enumGroup = createStackGroup(valueComp, 1);
    enumValueCombo = new Combo(enumGroup, SWT.READ_ONLY | SWT.BORDER);
    GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    enumValueCombo.setLayoutData(data);
    textGroup = createStackGroup(valueComp, 1);
    textValueField = new Text(textGroup, SWT.SINGLE | SWT.BORDER);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 320;
    textValueField.setLayoutData(data);
    codeGroup = createStackGroup(valueComp, 1);
    codeValueField = new CodeGroup(codeGroup, SWT.NONE, null);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    codeValueField.setLayoutData(data);
    dateGroup = createStackGroup(valueComp, 1);
    dateValueField = new DateInput(dateGroup, SWT.DATE | SWT.TIME | SWT.DROP_DOWN | SWT.BORDER);
    dateValueField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    enumRangeGroup = createStackGroup(valueComp, 2);
    enumFromField = new Combo(enumRangeGroup, SWT.READ_ONLY | SWT.BORDER);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    enumFromField.setLayoutData(data);
    enumToField = new Combo(enumRangeGroup, SWT.READ_ONLY | SWT.BORDER);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    enumToField.setLayoutData(data);
    codeRangeGroup = createStackGroup(valueComp, 2);
    codeFromField = new CodeGroup(codeRangeGroup, SWT.NONE, null);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    codeFromField.setLayoutData(data);
    codeToField = new CodeGroup(codeRangeGroup, SWT.NONE, null);
    data = new GridData(SWT.LEFT, SWT.CENTER, false, true);
    data.widthHint = 150;
    codeToField.setLayoutData(data);
    textRangeGroup = createStackGroup(valueComp, 2);
    textFromField = new Text(textRangeGroup, SWT.SINGLE | SWT.BORDER);
    textFromField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    textToField = new Text(textRangeGroup, SWT.SINGLE | SWT.BORDER);
    textToField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    dateRangeGroup = createStackGroup(valueComp, 2);
    dateFromField = new DateInput(dateRangeGroup, SWT.DATE | SWT.TIME | SWT.DROP_DOWN | SWT.BORDER);
    dateFromField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    dateToField = new DateInput(dateRangeGroup, SWT.DATE | SWT.TIME | SWT.DROP_DOWN | SWT.BORDER);
    dateToField.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true));
    undefinedGroup = createStackGroup(valueComp, 1);
    Button clearButton = new Button(autoGroup, SWT.PUSH);
    clearButton.setImage(Icons.delete.getImage());
    clearButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            crit = null;
            switchColor();
        }
    });
    critGroupCombo.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            fillFieldCombo();
            resetValues();
        }
    });
    critFieldCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            fillRelationCombo();
            resetValues();
            validate();
        }
    });
    critRelationCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateValueFields(crit);
            validate();
        }
    });
    fillFieldCombo();
}

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  w w  .ja v  a 2 s  . 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;//w w  w  .  jav  a2  s .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.internal.widgets.AbstractCriterionGroup.java

License:Open Source License

public AbstractCriterionGroup(Composite parent, CollectionEditGroup collectionEditGroup, int groupNo,
        boolean enabled, boolean and) {
    this.collectionEditGroup = collectionEditGroup;
    this.groupNo = groupNo;
    this.enabled = enabled;
    this.and = and;
    this.borderStyle = enabled ? SWT.BORDER : SWT.NONE;
    Label opLabel = new Label(parent, SWT.NONE);
    opLabel.setAlignment(SWT.RIGHT);//from w  w w  . j  ava  2 s .c om
    opLabel.setText((and) ? Messages.CriterionGroup_and : Messages.CriterionGroup_or);
    opLabel.setVisible(groupNo > 0);
    children.add(opLabel);
    List<Object> categories = QueryField.getCategoriesAndSubgroups();
    if (enabled) {
        groupCombo = new ComboViewer(parent, SWT.READ_ONLY | borderStyle);
        Combo comboControl = groupCombo.getCombo();
        setLayoutData(comboControl, 160);
        children.add(comboControl);
        comboControl.setVisibleItemCount(categories.size());
        groupCombo.setContentProvider(ArrayContentProvider.getInstance());
        groupCombo.setFilters(new ViewerFilter[] { new GroupComboCatFilter(), getExtensionFilter() });
        groupCombo.setLabelProvider(new GroupComboLabelProvider());
        groupCombo.setInput(categories);
        comboControl.setEnabled(enabled);
        fieldCombo = new Combo(parent, SWT.READ_ONLY | borderStyle);
        setLayoutData(fieldCombo, 180);
        children.add(fieldCombo);
        fieldCombo.setVisibleItemCount(10);
        relationCombo = new Combo(parent, SWT.READ_ONLY | borderStyle);
        setLayoutData(relationCombo, 112);
        children.add(relationCombo);
        relationCombo.setEnabled(enabled);
        fieldCombo.setEnabled(enabled);
    } else {
        groupLab = new Label(parent, SWT.NONE);
        setLayoutData(groupLab, 160);
        children.add(groupLab);
        fieldLab = new Label(parent, SWT.NONE);
        setLayoutData(fieldLab, 180);
        children.add(fieldLab);
        relationLab = new Label(parent, SWT.NONE);
        setLayoutData(relationLab, 112);
        children.add(relationLab);
    }
}