Search in sources :

Example 21 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project translationstudio8 by heartsome.

the class CSVSettingDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(5, 5, 5, 5).applyTo(tparent);
    int height = 160;
    if (isTBXConverter) {
        height = 230;
    }
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(320, height).grab(true, true).applyTo(tparent);
    Composite cmpSelFile = new Composite(tparent, SWT.None);
    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).extendedMargins(0, 0, 0, 0).applyTo(cmpSelFile);
    GridDataFactory.fillDefaults().applyTo(cmpSelFile);
    new Label(cmpSelFile, SWT.None).setText(Messages.getString("dialog.CSVSettingDialog.lblFile"));
    txtCSV = new Text(cmpSelFile, SWT.BORDER);
    txtCSV.setEditable(false);
    txtCSV.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnBrowse = new Button(cmpSelFile, SWT.None);
    btnBrowse.setText(Messages.getString("dialog.CSVSettingDialog.btnBrowse"));
    btnBrowse.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setText(Messages.getString("dialog.CSVSettingDialog.dialogTitle"));
            String[] extensions = { "*.csv", "*.txt", "*" };
            String[] filters = { Messages.getString("dialog.CSVSettingDialog.filters1"), Messages.getString("dialog.CSVSettingDialog.filters2"), Messages.getString("dialog.CSVSettingDialog.filters3") };
            dialog.setFilterExtensions(extensions);
            dialog.setFilterNames(filters);
            String fileSep = System.getProperty("file.separator");
            if (txtCSV.getText() != null && !txtCSV.getText().trim().equals("")) {
                dialog.setFilterPath(txtCSV.getText().substring(0, txtCSV.getText().lastIndexOf(fileSep)));
                dialog.setFileName(txtCSV.getText().substring(txtCSV.getText().lastIndexOf(fileSep) + 1));
            } else {
                dialog.setFilterPath(System.getProperty("user.home"));
            }
            String name = dialog.open();
            if (name != null) {
                txtCSV.setText(name);
            }
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    Composite cmpContent = new Composite(tparent, SWT.NONE);
    cmpContent.setLayout(new GridLayout(2, false));
    cmpContent.setLayoutData(new GridData(GridData.FILL_BOTH));
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbColSeparator"));
    cmbColSeparator = new Combo(cmpContent, SWT.NONE);
    cmbColSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    cmbColSeparator.setItems(arrColSeparator);
    cmbColSeparator.select(1);
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbTextDelimiter"));
    cmbTextDelimiter = new Combo(cmpContent, SWT.NONE);
    cmbTextDelimiter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    cmbTextDelimiter.setItems(arrTextDelimiter);
    cmbTextDelimiter.setText("\"");
    cmbTextDelimiter.setTextLimit(1);
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbEncoding"));
    cmbEncoding = new Combo(cmpContent, SWT.READ_ONLY);
    cmbEncoding.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    String[] arrEncoding = LocaleService.getPageCodes();
    cmbEncoding.setItems(arrEncoding);
    cmbEncoding.select(indexOf(arrEncoding, "UTF-8"));
    if (isTBXConverter) {
        createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbLang"));
        cmbLang = new TableComboViewer(cmpContent, SWT.READ_ONLY | SWT.BORDER);
        TableCombo tableCombo = cmbLang.getTableCombo();
        tableCombo.setShowTableLines(false);
        tableCombo.setShowTableHeader(false);
        tableCombo.setDisplayColumnIndex(-1);
        tableCombo.setShowImageWithinSelection(true);
        tableCombo.setShowColorWithinSelection(false);
        tableCombo.setShowFontWithinSelection(false);
        tableCombo.setVisibleItemCount(20);
        cmbLang.getTableCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        ArrayList<Language> languages = new ArrayList<Language>(LocaleService.getDefaultLanguage().values());
        Collections.sort(languages, new Comparator<Language>() {

            public int compare(Language o1, Language o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        cmbLang.setContentProvider(new ArrayContentProvider());
        cmbLang.setLabelProvider(new LanguageLabelProvider());
        cmbLang.setInput(languages);
        cmbLang.getTableCombo().select(0);
        createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbXCSTemplate"));
        cmbXCSTemplate = new Combo(cmpContent, SWT.READ_ONLY);
        cmbXCSTemplate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        if (xcsTemplates.length > 0) {
            cmbXCSTemplate.setItems(xcsTemplates);
            cmbXCSTemplate.select(0);
        }
    }
    return tparent;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo) Combo(org.eclipse.swt.widgets.Combo) TableComboViewer(org.eclipse.nebula.jface.tablecomboviewer.TableComboViewer) GridLayout(org.eclipse.swt.layout.GridLayout) Language(net.heartsome.cat.common.locale.Language) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo) FileDialog(org.eclipse.swt.widgets.FileDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 22 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project translationstudio8 by heartsome.

the class ColumnRemoveDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    tparent.setLayout(new GridLayout());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(150, 200).grab(true, true).applyTo(tparent);
    listColumn = new List(tparent, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL | SWT.MULTI);
    listColumn.setLayoutData(new GridData(GridData.FILL_BOTH));
    for (int i = 0; i < allColumnVector.size(); i++) {
        listColumn.add(allColumnVector.get(i));
    }
    Button btnRemove = new Button(tparent, SWT.None);
    btnRemove.setText(Messages.getString("dialog.ColumnRemoveDialog.btnRemove"));
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(btnRemove);
    btnRemove.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            int total = listColumn.getItemCount();
            int selCount = listColumn.getSelectionCount();
            if (selCount == 0) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.ColumnRemoveDialog.msgTitle"), Messages.getString("dialog.ColumnRemoveDialog.msg1"));
                return;
            }
            if ((total - selCount) < 2) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.ColumnRemoveDialog.msgTitle"), Messages.getString("dialog.ColumnRemoveDialog.msg2"));
                return;
            }
            listColumn.remove(listColumn.getSelectionIndices());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    return tparent;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 23 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project translationstudio8 by heartsome.

the class ColumnTypeDialog method initListener.

/**
	 * 初始化加载配置和保存配置按钮的监听 ;
	 */
private void initListener() {
    btnLoadConfiguration.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent event) {
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            fd.setText(Messages.getString("dialog.ColumnTypeDialog.fdTitle"));
            //$NON-NLS-1$ //$NON-NLS-2$
            String[] extensions = { "*.ctc", "*" };
            String[] names = { Messages.getString("dialog.ColumnTypeDialog.filterName1"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("dialog.ColumnTypeDialog.filterName2") };
            fd.setFilterExtensions(extensions);
            fd.setFilterNames(names);
            fd.setFilterPath(System.getProperty("user.home"));
            String name = fd.open();
            if (name == null) {
                return;
            }
            try {
                VTDGen vg = new VTDGen();
                if (vg.parseFile(name, true)) {
                    VTDNav vn = vg.getNav();
                    VTDUtils vu = new VTDUtils(vn);
                    AutoPilot ap = new AutoPilot(vn);
                    ap.selectXPath("/CSV2TBX-configuration");
                    ap.evalXPath();
                    int count = vu.getChildElementsCount();
                    if (count != arrCmbLangs.length) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ColumnTypeDialog.msgTitle"), Messages.getString("dialog.ColumnTypeDialog.msg1"));
                        return;
                    }
                    String xpath = "/CSV2TBX-configuration/item";
                    ap.selectXPath(xpath);
                    int i = 0;
                    while (ap.evalXPath() != -1) {
                        String propLevel = vu.getCurrentElementAttribut("propLevel", "");
                        //$NON-NLS-1$ //$NON-NLS-2$
                        String propType = vu.getCurrentElementAttribut("propType", "");
                        //$NON-NLS-1$ //$NON-NLS-2$
                        String lang = vu.getCurrentElementAttribut("propLang", "");
                        String propName = vu.getCurrentElementAttribut("propName", "");
                        arrCmbPropsLevel[i].setItems(levelValues);
                        arrCmbPropsLevel[i].select(0);
                        if (!propLevel.equals("")) {
                            //$NON-NLS-1$
                            arrCmbPropsLevel[i].setText(propLevel);
                            if (propLevel.equals(ColProperties.conceptLevel)) {
                                arrCmbLangs[i].setEnabled(false);
                                arrCmbPropsName[i].setItems(conceptPropValues);
                                arrCmbPropsName[i].select(0);
                                arrCmbPropsType[i].setItems(conceptPropTypeValues);
                                arrCmbPropsType[i].select(0);
                            }
                            if (propLevel.equals(ColProperties.langLevel)) {
                                arrCmbLangs[i].setEnabled(true);
                                arrCmbPropsName[i].setItems(TranslationPropValues);
                                arrCmbPropsName[i].select(0);
                                arrCmbPropsType[i].setItems(termDescripPropTypeValues);
                                arrCmbPropsType[i].select(0);
                            }
                        }
                        // Update content for Prop Name combo
                        if (!propName.equals("")) {
                            //$NON-NLS-1$
                            arrCmbPropsName[i].setText(propName);
                        }
                        if (!propLevel.equals("")) {
                            //$NON-NLS-1$
                            if (propLevel.equals(ColProperties.conceptLevel)) {
                                arrCmbPropsType[i].setEnabled(propName.equals(ColProperties.descripName));
                                arrCmbPropsType[i].setItems(conceptPropTypeValues);
                                arrCmbPropsType[i].select(0);
                            }
                            if (propLevel.equals(ColProperties.langLevel)) {
                                arrCmbPropsType[i].setEnabled(!propName.equals(ColProperties.termName));
                                if (propName.equals(ColProperties.descripName)) {
                                    arrCmbPropsType[i].setItems(termDescripPropTypeValues);
                                } else {
                                    arrCmbPropsType[i].setItems(termTermNotePropTypeValues);
                                }
                                arrCmbPropsType[i].select(0);
                            }
                        }
                        // Update content for Prop Type combo
                        if (!propType.equals("")) {
                            //$NON-NLS-1$
                            arrCmbPropsType[i].setText(propType);
                        }
                        // Update content for Language Combo
                        arrCmbLangs[i].setItems(LocaleService.getLanguages());
                        arrCmbLangs[i].select(0);
                        if (!lang.equals("")) {
                            //$NON-NLS-1$
                            arrCmbLangs[i].setText(lang);
                        }
                        i++;
                    }
                }
            } catch (XPathParseException e) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
            } catch (NavException e) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
            } catch (XPathEvalException e) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnSaveConfiguration.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell(), SWT.SAVE);
            fd.setText(Messages.getString("dialog.ColumnTypeDialog.savefdTitle"));
            //$NON-NLS-1$ //$NON-NLS-2$
            String[] extensions = { "*.ctc", "*.*" };
            String[] names = { Messages.getString("dialog.ColumnTypeDialog.filterName1"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("dialog.ColumnTypeDialog.filterName2") };
            fd.setFilterExtensions(extensions);
            fd.setFilterNames(names);
            fd.setFilterPath(System.getProperty("user.home"));
            String name = fd.open();
            if (name == null) {
                return;
            }
            try {
                FileOutputStream output = new FileOutputStream(name);
                //$NON-NLS-1$ //$NON-NLS-2$
                output.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes("UTF-8"));
                //$NON-NLS-1$ //$NON-NLS-2$
                output.write("<CSV2TBX-configuration>\n".getBytes("UTF-8"));
                for (int i = 0; i < arrCmbLangs.length; i++) {
                    String strItem = //$NON-NLS-1$
                    "<item propLang=\"" + arrCmbLangs[i].getText() + "\" propName=\"" + //$NON-NLS-1$
                    arrCmbPropsName[i].getText() + "\" propType=\"" + //$NON-NLS-1$
                    arrCmbPropsType[i].getText() + "\" propLevel=\"" + //$NON-NLS-1$
                    arrCmbPropsLevel[i].getText() + //$NON-NLS-1$
                    "\"/>\n";
                    //$NON-NLS-1$
                    output.write(strItem.getBytes("UTF-8"));
                }
                //$NON-NLS-1$ //$NON-NLS-2$
                output.write("</CSV2TBX-configuration>\n".getBytes("UTF-8"));
                output.close();
            } catch (FileNotFoundException e1) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
            } catch (UnsupportedEncodingException e1) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
            } catch (IOException e1) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) VTDNav(com.ximpleware.VTDNav) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 24 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project translationstudio8 by heartsome.

the class RTFCleanerDialog method createToolBar.

/**
	 * 创建工具栏
	 * @param parent
	 *            父控件
	 */
private void createToolBar(Composite parent) {
    ToolBar toolBar = new ToolBar(parent, SWT.NO_FOCUS | SWT.None);
    toolBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ToolItem addStyleItem = new ToolItem(toolBar, SWT.PUSH);
    addStyleItem.setToolTipText(Messages.getString("dialog.RTFCleanerDialog.addStyleItem"));
    addStyleItem.setImage(new Image(Display.getDefault(), PluginUtil.getAbsolutePath(PluginConstants.PIC_OPEN_CSV_PATH)));
    addStyleItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            handleFile();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) ToolItem(org.eclipse.swt.widgets.ToolItem) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 25 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project translationstudio8 by heartsome.

the class RTFCleanerDialog method createMenu.

/**
	 * 创建菜单 ;
	 */
private void createMenu() {
    Menu menu = new Menu(getShell(), SWT.BAR);
    getShell().setMenuBar(menu);
    getShell().pack();
    Rectangle screenSize = Display.getDefault().getClientArea();
    Rectangle frameSize = getShell().getBounds();
    getShell().setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    Menu fileMenu = new Menu(menu);
    MenuItem fileItem = new MenuItem(menu, SWT.CASCADE);
    fileItem.setMenu(fileMenu);
    fileItem.setText(Messages.getString("dialog.RTFCleanerDialog.fileMenu"));
    MenuItem addStylesItem = new MenuItem(fileMenu, SWT.PUSH);
    addStylesItem.setText(Messages.getString("dialog.RTFCleanerDialog.addStylesItem"));
    addStylesItem.setImage(new Image(Display.getDefault(), PluginUtil.getAbsolutePath(PluginConstants.PIC_OPEN_CSV_PATH)));
    addStylesItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            handleFile();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    new MenuItem(fileMenu, SWT.SEPARATOR);
    MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH);
    exitItem.setText(Messages.getString("dialog.RTFCleanerDialog.exitItem"));
    exitItem.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            close();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) Image(org.eclipse.swt.graphics.Image) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SelectionListener (org.eclipse.swt.events.SelectionListener)190 SelectionEvent (org.eclipse.swt.events.SelectionEvent)184 Button (org.eclipse.swt.widgets.Button)94 GridData (org.eclipse.swt.layout.GridData)91 Composite (org.eclipse.swt.widgets.Composite)88 GridLayout (org.eclipse.swt.layout.GridLayout)87 Label (org.eclipse.swt.widgets.Label)69 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)52 Text (org.eclipse.swt.widgets.Text)45 Group (org.eclipse.swt.widgets.Group)43 FormAttachment (org.eclipse.swt.layout.FormAttachment)36 FormData (org.eclipse.swt.layout.FormData)36 Combo (org.eclipse.swt.widgets.Combo)34 ModifyEvent (org.eclipse.swt.events.ModifyEvent)31 ModifyListener (org.eclipse.swt.events.ModifyListener)31 FormLayout (org.eclipse.swt.layout.FormLayout)26 Point (org.eclipse.swt.graphics.Point)21 ArrayList (java.util.ArrayList)19 FillLayout (org.eclipse.swt.layout.FillLayout)17 Menu (org.eclipse.swt.widgets.Menu)17