Search in sources :

Example 21 with ComboViewer

use of org.eclipse.jface.viewers.ComboViewer in project linuxtools by eclipse.

the class ImagePushPage method createImageSelectionControls.

@SuppressWarnings("unchecked")
private IObservableValue<String> createImageSelectionControls(final Composite container) {
    final Label nameLabel = new Label(container, SWT.NULL);
    nameLabel.setText(// $NON-NLS-1$
    WizardMessages.getString("ImagePullPushPage.name.label"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(nameLabel);
    final Combo imageNameCombo = new Combo(container, SWT.DROP_DOWN);
    imageNameCombo.setToolTipText(// $NON-NLS-1$
    WizardMessages.getString("ImagePushName.toolTip"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(imageNameCombo);
    final ComboViewer imageNameComboViewer = new ComboViewer(imageNameCombo);
    imageNameComboViewer.setContentProvider(new ArrayContentProvider());
    imageNameComboViewer.setInput(getModel().getImage().repoTags());
    // binding must take place after the input is set, so that default
    // repo/name can be selected.
    final IObservableValue<String> imageNameObservable = BeanProperties.value(ImagePushPageModel.class, ImagePullPushPageModel.SELECTED_IMAGE_NAME).observe(getModel());
    dbc.bindValue(WidgetProperties.selection().observe(imageNameCombo), imageNameObservable);
    // filler for the last column
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(new Label(container, SWT.NONE));
    return imageNameObservable;
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) Label(org.eclipse.swt.widgets.Label) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Combo(org.eclipse.swt.widgets.Combo)

Example 22 with ComboViewer

use of org.eclipse.jface.viewers.ComboViewer in project linuxtools by eclipse.

the class ImageRunSelectionPage method createImageSettingsSection.

/**
 * Creates the {@link Composite} container that will display widgets to
 * select an {@link IDockerImage}, name it and specify the command to run.
 *
 * @param container
 *            the parent {@link Composite}
 */
private void createImageSettingsSection(final Composite container) {
    // Image selection name
    final Label imageSelectionLabel = new Label(container, SWT.NONE);
    imageSelectionLabel.setText(// $NON-NLS-1$
    WizardMessages.getString("ImageRunSelectionPage.imageName"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    final Combo imageSelectionCombo = new Combo(container, SWT.BORDER);
    final ComboViewer imageSelectionComboViewer = new ComboViewer(imageSelectionCombo);
    imageSelectionCombo.setToolTipText(WizardMessages.getString(// $NON-NLS-1$
    "ImageRunSelectionPage.selectTooltip"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(imageSelectionCombo);
    new ControlDecoration(imageSelectionCombo, SWT.TOP | SWT.LEFT);
    new ContentProposalAdapter(imageSelectionCombo, new ComboContentAdapter() {

        @Override
        public void insertControlContents(Control control, String text, int cursorPosition) {
            final Combo combo = (Combo) control;
            final Point selection = combo.getSelection();
            combo.setText(text);
            selection.x = text.length();
            selection.y = selection.x;
            combo.setSelection(selection);
        }
    }, getImageNameContentProposalProvider(imageSelectionCombo), null, null);
    // image search
    final Button searchImageButton = new Button(container, SWT.NONE);
    searchImageButton.setText(// $NON-NLS-1$
    WizardMessages.getString("ImageRunSelectionPage.search"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(searchImageButton);
    searchImageButton.addSelectionListener(onSearchImage());
    // link to pull image
    final Label fillerLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(fillerLabel);
    pullImageLink = new Link(container, SWT.NONE);
    pullImageLink.setText(// $NON-NLS-1$
    WizardMessages.getString("ImageRunSelectionPage.pullImage"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(COLUMNS - 1, 1).applyTo(pullImageLink);
    pullImageLink.addSelectionListener(onPullImage());
    dbc.bindValue(WidgetProperties.enabled().observe(pullImageLink), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NEEDS_PULLING).observe(model));
    // bind combo with model (for values and selection)
    imageSelectionComboViewer.setContentProvider(new ObservableListContentProvider());
    dbc.bindList(WidgetProperties.items().observe(imageSelectionCombo), BeanProperties.list(ImageRunSelectionModel.class, ImageRunSelectionModel.IMAGE_NAMES).observe(model));
    dbc.bindValue(WidgetProperties.selection().observe(imageSelectionCombo), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NAME).observe(model));
    // Container name (optional)
    final Label containerNameLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    containerNameLabel.setText(WizardMessages.getString(// $NON-NLS-1$
    "ImageRunSelectionPage.containerName"));
    final Text containerNameText = new Text(container, SWT.BORDER);
    containerNameText.setToolTipText(WizardMessages.getString(// $NON-NLS-1$
    "ImageRunSelectionPage.containerTooltip"));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(containerNameText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(containerNameText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.CONTAINER_NAME).observe(model));
    // EntryPoint (optional)
    final Label entrypointLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    entrypointLabel.setText(// $NON-NLS-1$
    WizardMessages.getString("ImageRunSelectionPage.entrypoint"));
    // TODO: include SWT.SEARCH | SWT.ICON_SEARCH to support value reset
    final Text entrypointText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(entrypointText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(entrypointText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.ENTRYPOINT).observe(model));
    // Command (optional)
    final Label commandLabel = new Label(container, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
    commandLabel.setText(// $NON-NLS-1$
    WizardMessages.getString("ImageRunSelectionPage.command"));
    final Text commandText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(commandText);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(new Label(container, SWT.NONE));
    dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(commandText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.COMMAND).observe(model));
}
Also used : ComboContentAdapter(org.eclipse.jface.fieldassist.ComboContentAdapter) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) Control(org.eclipse.swt.widgets.Control) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) Link(org.eclipse.swt.widgets.Link)

Example 23 with ComboViewer

use of org.eclipse.jface.viewers.ComboViewer in project yamcs-studio by yamcs.

the class ComboHistoryHelperSample method main.

/**
 * Launch the application.
 * @param args
 */
public static void main(String[] args) {
    Display display = Display.getDefault();
    Shell shell = new Shell();
    shell.setSize(450, 300);
    shell.setText("SWT Application");
    text = new Text(shell, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    text.setBounds(10, 44, 412, 201);
    comboViewer = new ComboViewer(shell, SWT.NONE);
    combo = comboViewer.getCombo();
    combo.setBounds(10, 10, 412, 28);
    new ComboHistoryHelper(null, "tag", combo) {

        @Override
        public void newSelection(final String pvName) {
            // Need to use \r\n. Unbelievable!!!
            String newText = text.getText() + pvName + "\r\n";
            text.setText(newText);
        }
    };
    shell.open();
    shell.layout();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Text(org.eclipse.swt.widgets.Text) Display(org.eclipse.swt.widgets.Display)

Example 24 with ComboViewer

use of org.eclipse.jface.viewers.ComboViewer in project translationstudio8 by heartsome.

the class HSFontSettingComposite method createContent.

public void createContent() {
    if (this.title != null && title.length() != 0) {
        Label titleLabel = new Label(this, SWT.NONE);
        titleLabel.setText(title);
        GridData titleLabelGridData = new GridData();
        titleLabelGridData.horizontalSpan = 2;
        titleLabelGridData.horizontalAlignment = GridData.CENTER;
        titleLabel.setLayoutData(titleLabelGridData);
    }
    Label lblFontName = new Label(this, SWT.NONE);
    lblFontName.setText(Messages.getString("HSFontSettingComposite.fontNameLabel"));
    fontNameComboViewer = new ComboViewer(this);
    fontNameComboViewer.setContentProvider(new ArrayContentProvider());
    Combo fontNameCombo = fontNameComboViewer.getCombo();
    GridData fnGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    fontNameCombo.setLayoutData(fnGd);
    fontNameComboViewer.setInput(getSystemFonts());
    Label lblFontSize = new Label(this, SWT.NONE);
    lblFontSize.setText(Messages.getString("HSFontSettingComposite.fontSizeLabel"));
    fontSizeComboViewer = new ComboViewer(this);
    fontSizeComboViewer.setContentProvider(new ArrayContentProvider());
    Combo fontSize = fontSizeComboViewer.getCombo();
    fontSize.setLayoutData(fnGd);
    fontSizeComboViewer.setInput(new Integer[] { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 });
    Label lblFontPreview = new Label(this, SWT.None);
    lblFontPreview.setText(Messages.getString("HSFontSettingComposite.fontPreViewLabel"));
    previewFontText = new Label(this, SWT.READ_ONLY | SWT.BORDER);
    previewFontText.setText("abcdefg ABCDEFG");
    GridData previewFontTextGridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    previewFontTextGridData.heightHint = 50;
    previewFontText.setLayoutData(previewFontTextGridData);
    fontNameComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            String strFontName = fontNameComboViewer.getCombo().getText();
            String intFontSize = fontSizeComboViewer.getCombo().getText();
            if (strFontName == null || intFontSize == null || strFontName.length() == 0 || intFontSize.length() == 0) {
                return;
            }
            FontData fd = JFaceResources.getDefaultFont().getFontData()[0];
            fd.setName(strFontName);
            fd.setHeight(Integer.parseInt(intFontSize));
            if (previewFont != null && !previewFont.isDisposed()) {
                previewFont.dispose();
            }
            previewFont = new Font(Display.getDefault(), fd);
            previewFontText.setFont(previewFont);
        }
    });
    fontSizeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            String strFontName = fontNameComboViewer.getCombo().getText();
            String intFontSize = fontSizeComboViewer.getCombo().getText();
            if (strFontName == null || intFontSize == null || strFontName.length() == 0 || intFontSize.length() == 0) {
                return;
            }
            FontData fd = JFaceResources.getDefaultFont().getFontData()[0];
            fd.setName(strFontName);
            fd.setHeight(Integer.parseInt(intFontSize));
            if (previewFont != null && !previewFont.isDisposed()) {
                previewFont.dispose();
            }
            previewFont = new Font(Display.getDefault(), fd);
            previewFontText.setFont(previewFont);
        }
    });
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Font(org.eclipse.swt.graphics.Font)

Example 25 with ComboViewer

use of org.eclipse.jface.viewers.ComboViewer in project translationstudio8 by heartsome.

the class ExportTmxDialog method createDialogArea.

/**
	 * Create contents of the dialog.
	 * @param parent
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout(1, false));
    Group dbListGroup = new Group(container, SWT.NONE);
    GridLayout glDbListGroup = new GridLayout(2, false);
    glDbListGroup.horizontalSpacing = 0;
    glDbListGroup.marginHeight = 0;
    glDbListGroup.marginWidth = 0;
    dbListGroup.setLayout(glDbListGroup);
    dbListGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    dbListGroup.setText(Messages.getString("dialog.ExportTmxDialog.dbListGroup"));
    Composite leftComposite = new Composite(dbListGroup, SWT.NONE);
    GridLayout glLeftComposite = new GridLayout(1, false);
    glLeftComposite.verticalSpacing = 0;
    glLeftComposite.marginHeight = 0;
    leftComposite.setLayout(glLeftComposite);
    leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    // 列表和语言设置
    Composite dbListComposite = new Composite(leftComposite, SWT.NONE);
    GridLayout glTopLeftComposite = new GridLayout(1, false);
    glTopLeftComposite.marginHeight = 0;
    glTopLeftComposite.marginWidth = 0;
    dbListComposite.setLayout(glTopLeftComposite);
    dbListComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    dbListViewer = new TableViewer(dbListComposite, SWT.BORDER | SWT.FULL_SELECTION);
    Table table = dbListViewer.getTable();
    GridData gd_table = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_table.heightHint = 100;
    table.setLayoutData(gd_table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    dbListViewer.setContentProvider(new ArrayContentProvider());
    dbListViewer.setInput(dbList);
    createColumn(dbListViewer);
    dbListViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            currentDatabase = (ExportDatabaseBean) selection.getFirstElement();
            loadData();
        }
    });
    Composite langSetComposite = new Composite(leftComposite, SWT.NONE);
    GridLayout gl_langSetComposite = new GridLayout(2, false);
    gl_langSetComposite.marginWidth = 0;
    langSetComposite.setLayout(gl_langSetComposite);
    langSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    Label langSelLabel = new Label(langSetComposite, SWT.NONE);
    langSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    langSelLabel.setText(Messages.getString("dialog.ExportTmxDialog.langSelLabel"));
    hasSelLangListViewer = new ListViewer(langSetComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    org.eclipse.swt.widgets.List list = hasSelLangListViewer.getList();
    GridData glLangList = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    glLangList.heightHint = 76;
    list.setLayoutData(glLangList);
    hasSelLangListViewer.setContentProvider(new ArrayContentProvider());
    hasSelLangListViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty()) {
                return;
            }
            if (currentDatabase != null) {
                currentDatabase.getHasSelectedLangs().clear();
                currentDatabase.getHasSelectedLangs().addAll(sel.toList());
                List<String> canSelSrcLangs = new ArrayList<String>();
                canSelSrcLangs.add("*all*");
                canSelSrcLangs.addAll(sel.toList());
                currentDatabase.setCanSelSrcLangs(canSelSrcLangs);
                srcLangcomboViewer.setInput(canSelSrcLangs);
                if (canSelSrcLangs.contains(currentDatabase.getSrcLang())) {
                    String srcLang = currentDatabase.getSrcLang();
                    if (srcLang != null && !srcLang.equals("")) {
                        for (int i = 0; i < canSelSrcLangs.size(); i++) {
                            if (canSelSrcLangs.get(i).equals(srcLang)) {
                                srcLangcomboViewer.getCombo().select(i);
                                break;
                            }
                        }
                    }
                } else {
                    srcLangcomboViewer.getCombo().select(0);
                }
            }
        }
    });
    Label srcLangSelLabel = new Label(langSetComposite, SWT.NONE);
    srcLangSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    srcLangSelLabel.setBounds(0, 0, 79, 19);
    srcLangSelLabel.setText(Messages.getString("dialog.ExportTmxDialog.srcLangSelLabel"));
    srcLangcomboViewer = new ComboViewer(langSetComposite, SWT.NONE | SWT.READ_ONLY);
    Combo combo = srcLangcomboViewer.getCombo();
    GridData gd_combo = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
    gd_combo.widthHint = 197;
    combo.setLayoutData(gd_combo);
    srcLangcomboViewer.setContentProvider(new ArrayContentProvider());
    srcLangcomboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty()) {
                return;
            }
            if (currentDatabase != null) {
                currentDatabase.setSrcLang((String) sel.getFirstElement());
            }
        }
    });
    // 操作库列的按钮区域
    Composite rightComposite = new Composite(dbListGroup, SWT.NONE);
    GridLayout gl_rightComposite = new GridLayout(1, false);
    gl_rightComposite.marginRight = 5;
    gl_rightComposite.marginHeight = 0;
    gl_rightComposite.marginWidth = 0;
    rightComposite.setLayout(gl_rightComposite);
    rightComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    HSDropDownButton addDbBtn = new HSDropDownButton(rightComposite, SWT.None);
    addDbBtn.setBounds(0, 0, 104, 31);
    addDbBtn.setText(Messages.getString("dialog.ExportTmxDialog.AddDbBtn"));
    Menu menu = addDbBtn.getMenu();
    MenuItem fileItem = new MenuItem(menu, SWT.PUSH);
    fileItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
    fileItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialg = new FileDialog(getShell());
            fileDialg.setFilterExtensions(new String[] { "*.hstm", "*.*" });
            String result = fileDialg.open();
            if (result == null) {
                return;
            }
            File f = new File(result);
            if (!f.exists()) {
                return;
            }
            Map<DatabaseModelBean, String> r = null;
            try {
                r = Utils.convertFile2TmModel(f, true);
            } catch (Exception e1) {
                MessageDialog.openError(getShell(), Messages.getString("tm.dialog.addFileTm.errorTitle"), e1.getMessage());
            }
            if (r == null) {
                return;
            }
            Iterator<DatabaseModelBean> it = r.keySet().iterator();
            if (it.hasNext()) {
                DatabaseModelBean selectedVal = it.next();
                ExportDatabaseBean bean = new ExportDatabaseBean(selectedVal.toDbMetaData(), r.get(selectedVal));
                if (!dbList.contains(bean)) {
                    // 实现: 重写equals方法
                    dbList.add(bean);
                    bean.setIndex(dbList.size() + "");
                }
                dbListViewer.getTable().removeAll();
                dbListViewer.setInput(dbList);
                if (dbList.size() != 0) {
                    deleteDbBtn.setEnabled(true);
                    browserBtn.setEnabled(true);
                    selectCurrentDb(currentDatabase);
                } else {
                    deleteDbBtn.setEnabled(false);
                    browserBtn.setEnabled(false);
                }
            }
        }
    });
    MenuItem serverItem = new MenuItem(menu, SWT.PUSH);
    serverItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddServerTm"));
    serverItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TmDbManagerDialog dialog = new TmDbManagerDialog(getShell());
            dialog.setDialogUseFor(TmDbManagerDialog.TYPE_DBSELECTED);
            if (dialog.open() == Window.OK) {
                Map<DatabaseModelBean, String> selDb = dialog.getHasSelectedDatabase();
                Iterator<Entry<DatabaseModelBean, String>> entryIt = selDb.entrySet().iterator();
                while (entryIt.hasNext()) {
                    Entry<DatabaseModelBean, String> entry = entryIt.next();
                    ExportDatabaseBean bean = new ExportDatabaseBean(entry.getKey().toDbMetaData(), entry.getValue());
                    if (!dbList.contains(bean)) {
                        // 实现: 重写equals方法
                        dbList.add(bean);
                        bean.setIndex(dbList.size() + "");
                    }
                }
                dbListViewer.getTable().removeAll();
                dbListViewer.setInput(dbList);
            }
            if (dbList.size() != 0) {
                deleteDbBtn.setEnabled(true);
                browserBtn.setEnabled(true);
                selectCurrentDb(currentDatabase);
            } else {
                deleteDbBtn.setEnabled(false);
                browserBtn.setEnabled(false);
            }
        }
    });
    deleteDbBtn = new Button(rightComposite, SWT.NONE);
    deleteDbBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    deleteDbBtn.setBounds(0, 0, 104, 31);
    deleteDbBtn.setText(Messages.getString("dialog.ExportTmxDialog.deleteDbBtn"));
    deleteDbBtn.setEnabled(false);
    deleteDbBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) dbListViewer.getSelection();
            if (sel.isEmpty()) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg1"));
                return;
            }
            dbList.removeAll(sel.toList());
            dbListViewer.remove(sel.toArray());
            if (dbList.size() != 0) {
                deleteDbBtn.setEnabled(true);
                browserBtn.setEnabled(true);
                selectCurrentDb(currentDatabase);
            } else {
                currentDatabase = null;
                deleteDbBtn.setEnabled(false);
                browserBtn.setEnabled(false);
            }
        }
    });
    // 过虑规则
    Composite filterSetComposite = new Composite(container, SWT.NONE);
    GridLayout glFilterSetComposite = new GridLayout(4, false);
    glFilterSetComposite.marginWidth = 0;
    glFilterSetComposite.marginHeight = 0;
    filterSetComposite.setLayout(glFilterSetComposite);
    filterSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    hasfilterCbtn = new Button(filterSetComposite, SWT.CHECK);
    hasfilterCbtn.setText(Messages.getString("dialog.ExportTmxDialog.hasfilterCbtn"));
    hasfilterCbtn.setSelection(false);
    hasfilterCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            // TODO 实现选择改变
            filterComboViewer.getCombo().setEnabled(hasfilterCbtn.getSelection());
            filterSetBtn.setEnabled(hasfilterCbtn.getSelection());
            deleteFilterBtn.setEnabled(hasfilterCbtn.getSelection());
        }
    });
    filterComboViewer = new ComboViewer(filterSetComposite, SWT.NONE);
    Combo filterCombo = filterComboViewer.getCombo();
    filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    filterCombo.setEnabled(hasfilterCbtn.getSelection());
    filterComboViewer.setContentProvider(new ArrayContentProvider());
    filterComboViewer.setLabelProvider(new FilterLabelProvider());
    filterComboViewer.setInput(filterList);
    // 有一个空的过滤器
    filterCombo.select(0);
    filterSetBtn = new Button(filterSetComposite, SWT.NONE);
    filterSetBtn.setText(Messages.getString("dialog.ExportTmxDialog.filterSetBtn"));
    filterSetBtn.setEnabled(hasfilterCbtn.getSelection());
    filterSetBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
            ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
            if (bean.equals(filterList.get(0))) {
                // 0位置的始终存在 Empty
                // 新建
                filterSetting(null);
            } else {
                // 编辑
                filterSetting(bean);
            }
        }
    });
    deleteFilterBtn = new Button(filterSetComposite, SWT.NONE);
    deleteFilterBtn.setText(Messages.getString("dialog.ExportTmxDialog.deleteFilterBtn"));
    deleteFilterBtn.setEnabled(hasfilterCbtn.getSelection());
    deleteFilterBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
            ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
            if (bean.equals(filterList.get(0))) {
                // 总是存在一个空的filter,显示为"无"
                return;
            }
            if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg2"))) {
                filterStore.deleteFilterRuleByName(bean.getFilterName(), "TMX");
                int i = filterList.indexOf(bean);
                filterList.remove(i);
                filterComboViewer.setInput(filterList);
                filterComboViewer.getCombo().select(0);
            }
        }
    });
    isTopLevelTmxCbtn = new Button(container, SWT.CHECK);
    isTopLevelTmxCbtn.setText(Messages.getString("dialog.ExportTmxDialog.isTopLevelTmxCbtn"));
    isTopLevelTmxCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean temp = isTopLevelTmxCbtn.getSelection();
            if (temp) {
                isTagCbtn.setSelection(false);
                isTagCbtn.setEnabled(false);
            } else {
                isTagCbtn.setEnabled(true);
            }
        }
    });
    isTagCbtn = new Button(container, SWT.CHECK);
    isTagCbtn.setText(Messages.getString("dialog.ExportTmxDialog.isTagCbtn"));
    isTagCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean temp = isTagCbtn.getSelection();
            if (temp) {
                isTopLevelTmxCbtn.setSelection(false);
                isTopLevelTmxCbtn.setEnabled(false);
            } else {
                isTopLevelTmxCbtn.setEnabled(true);
            }
        }
    });
    isTopLevelTmxCbtn.setSelection(true);
    isTagCbtn.setEnabled(false);
    Composite encodingComposite = new Composite(container, SWT.NONE);
    GridLayout glEncodingComposite = new GridLayout(2, false);
    glEncodingComposite.marginWidth = 0;
    glEncodingComposite.marginHeight = 0;
    encodingComposite.setLayout(glEncodingComposite);
    encodingComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    hasChangedCodingCbtn = new Button(encodingComposite, SWT.CHECK);
    hasChangedCodingCbtn.setText(Messages.getString("dialog.ExportTmxDialog.hasChangedCodingCbtn"));
    hasChangedCodingCbtn.setSelection(false);
    hasChangedCodingCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            encodingComboViewer.getCombo().setEnabled(hasChangedCodingCbtn.getSelection());
        }
    });
    encodingComboViewer = new ComboViewer(encodingComposite, SWT.NONE | SWT.READ_ONLY);
    Combo encodingCombo = encodingComboViewer.getCombo();
    GridData gdEncodingCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gdEncodingCombo.widthHint = 279;
    encodingCombo.setLayoutData(gdEncodingCombo);
    encodingCombo.setEnabled(hasChangedCodingCbtn.getSelection());
    encodingComboViewer.setContentProvider(new ArrayContentProvider());
    encodingComboViewer.setInput(pageCodes);
    Composite tmxFileSetComposite = new Composite(container, SWT.NONE);
    GridLayout glTmxFileSetComposite = new GridLayout(3, false);
    glTmxFileSetComposite.marginWidth = 0;
    glTmxFileSetComposite.marginHeight = 0;
    tmxFileSetComposite.setLayout(glTmxFileSetComposite);
    tmxFileSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label tmxFileLabel = new Label(tmxFileSetComposite, SWT.NONE);
    tmxFileLabel.setText(Messages.getString("dialog.ExportTmxDialog.tmxFileLabel"));
    tmxFileText = new Text(tmxFileSetComposite, SWT.BORDER);
    tmxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tmxFileText.setEnabled(false);
    browserBtn = new Button(tmxFileSetComposite, SWT.NONE);
    browserBtn.setText(Messages.getString("dialog.ExportTmxDialog.browserBtn"));
    browserBtn.setEnabled(false);
    browserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (dbList.size() > 1) {
                DirectoryDialog dlg = new DirectoryDialog(getParentShell());
                String filePath = dlg.open();
                if (filePath != null) {
                    tmxFileText.setText(filePath);
                }
            } else {
                FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
                String[] filterExt = { "*.tmx" };
                dlg.setFilterExtensions(filterExt);
                String filePath = dlg.open();
                if (filePath != null) {
                    tmxFileText.setText(filePath);
                }
            }
        }
    });
    return container;
}
Also used : Group(org.eclipse.swt.widgets.Group) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Combo(org.eclipse.swt.widgets.Combo) ExportFilterBean(net.heartsome.cat.database.bean.ExportFilterBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) ListViewer(org.eclipse.jface.viewers.ListViewer) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Text(org.eclipse.swt.widgets.Text) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) Map(java.util.Map)

Aggregations

ComboViewer (org.eclipse.jface.viewers.ComboViewer)46 Label (org.eclipse.swt.widgets.Label)33 GridData (org.eclipse.swt.layout.GridData)30 Composite (org.eclipse.swt.widgets.Composite)30 Combo (org.eclipse.swt.widgets.Combo)26 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 Button (org.eclipse.swt.widgets.Button)22 GridLayout (org.eclipse.swt.layout.GridLayout)21 Text (org.eclipse.swt.widgets.Text)21 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)18 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)17 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)13 LabelProvider (org.eclipse.jface.viewers.LabelProvider)12 Point (org.eclipse.swt.graphics.Point)11 Group (org.eclipse.swt.widgets.Group)11 Control (org.eclipse.swt.widgets.Control)10 ISelection (org.eclipse.jface.viewers.ISelection)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8