Search in sources :

Example 66 with SelectionEvent

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

the class MachineTranslationPreferencePage method createBingTranslateArea.

private Composite createBingTranslateArea(Composite tparent) {
    Group apiKeySettingGroup = new Group(tparent, SWT.NONE);
    apiKeySettingGroup.setText(Messages.getString("preference.BingPreferencePage.apiKeySettingGroup"));
    apiKeySettingGroup.setLayout(new GridLayout(1, false));
    apiKeySettingGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    HsImageLabel lbKeySetting = new HsImageLabel(Messages.getString("preference.BingPreferencePage.lbKeySetting"), Activator.getImageDescriptor("images/trans_bing_key_32.png"));
    Composite com = lbKeySetting.createControl(apiKeySettingGroup);
    com.setLayout(new GridLayout(3, false));
    Label lblId = new Label(com, SWT.NONE);
    lblId.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblId.setText(Messages.getString("preference.BingPreferencePage.lblId"));
    idText = new Text(com, SWT.BORDER);
    idText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    new Label(com, SWT.NONE);
    Label lblApiKey = new Label(com, SWT.NONE);
    lblApiKey.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblApiKey.setText(Messages.getString("preference.BingPreferencePage.lblApiKey"));
    bingKeyText = new Text(com, SWT.BORDER);
    bingKeyText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    bingStateLable = new Label(com, SWT.NONE);
    bingStateLable.setImage(errorImage);
    new Label(com, SWT.NONE);
    Button validateKey = new Button(com, SWT.NONE);
    validateKey.setText(Messages.getString("preference.BingPreferencePage.validateKey"));
    validateKey.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String id = idText.getText();
            String bingKey = bingKeyText.getText();
            if (id == null || id.equals("")) {
                MessageDialog.openInformation(getShell(), Messages.getString("preference.BingPreferencePage.msgTitle"), Messages.getString("preference.BingPreferencePage.msg1"));
                return;
            }
            if (bingKey == null || bingKey.equals("")) {
                MessageDialog.openInformation(getShell(), Messages.getString("preference.BingPreferencePage.msgTitle"), Messages.getString("preference.BingPreferencePage.msg2"));
                return;
            }
            bingValidator();
            setComponentsState();
            if (!bingState) {
                MessageDialog.openInformation(getShell(), Messages.getString("preference.BingPreferencePage.msgTitle"), Messages.getString("preference.BingPreferencePage.msg3"));
                return;
            }
        }
    });
    new Label(com, SWT.NONE);
    new Label(com, SWT.NONE);
    Link link = new Link(com, SWT.NONE);
    link.setText("<a>" + Messages.getString("preference.BingPreferencePage.link") + "</a>");
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Program.launch("http://msdn.microsoft.com/en-us/library/hh454950.aspx");
        }
    });
    link.setToolTipText("http://msdn.microsoft.com/en-us/library/hh454950.aspx");
    new Label(com, SWT.NONE);
    lbKeySetting.computeSize();
    return tparent;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) HsImageLabel(net.heartsome.cat.common.ui.HsImageLabel) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) HsImageLabel(net.heartsome.cat.common.ui.HsImageLabel) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Link(org.eclipse.swt.widgets.Link)

Example 67 with SelectionEvent

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

the class SrxConfigurationDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridDataFactory.fillDefaults().grab(true, true).hint(400, 400).minSize(400, 400).applyTo(tparent);
    tableViewer = new TableViewer(tparent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    String[] columnNames = new String[] { Messages.getString("srx.SrxConfigurationDialog.columnNames1"), Messages.getString("srx.SrxConfigurationDialog.columnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
        // 处理排序的问题
        switch(i) {
            case 0:
                tableColumn.addSelectionListener(new SelectionAdapter() {

                    // 升序
                    boolean asc = true;

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        tableViewer.setSorter(asc ? XmlConvertOrder.index_ASC : XmlConvertOrder.index_DESC);
                        asc = !asc;
                    }
                });
                break;
            case 1:
                tableColumn.addSelectionListener(new SelectionAdapter() {

                    // 升序
                    boolean asc = true;

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        tableViewer.setSorter(asc ? XmlConvertOrder.xmlName_ASC : XmlConvertOrder.xmlName_DESC);
                        asc = !asc;
                    }
                });
                break;
            default:
                break;
        }
    }
    tableViewer.setInput(getSRXConfigFilesInfo());
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.1, 0.85 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            editSrx();
        }
    });
    refreshTable(null);
    return tparent;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Listener(org.eclipse.swt.widgets.Listener) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerLabelProvider(net.heartsome.cat.ts.ui.advanced.TableViewerLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 68 with SelectionEvent

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

the class SrxConfigurationDialog method createHelpToolItem.

/**
	 * 添加帮助按钮,备注,这里的配置与其他的不一样
	 * robert	2012-09-06
	 */
protected Control createHelpToolItem(Composite parent) {
    // ROBERTHELP 分段规则管理器
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03#segmentation-rule-manager", language);
    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
    toolBar.setCursor(cursor);
    toolBar.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            cursor.dispose();
        }
    });
    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
    helpItem.setImage(helpImage);
    //$NON-NLS-1$
    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
    helpItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
        }
    });
    return toolBar;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 69 with SelectionEvent

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

the class SrxConfigurationDialog method initListener.

/**
	 * 给增删改三个按钮提示添加事件 ;
	 */
private void initListener() {
    addBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CreateOrUpdataSRXDialog createDialog = new CreateOrUpdataSRXDialog(getShell(), true);
            int createResult = createDialog.open();
            if (IDialogConstants.OK_ID == createResult) {
                String addedSrxName = createDialog.getCurSrxName();
                // 添加完成该文件后,解析该文件
                boolean openResult = openSrx(ADConstants.configLocation + ADConstants.AD_SRXConfigFolder + File.separator + addedSrxName);
                if (!openResult) {
                    return;
                }
                AddOrEditSrxConfigDialog addDialog = new AddOrEditSrxConfigDialog(getShell(), addedSrxName, handler);
                addDialog.open();
                refreshTable(addedSrxName);
            }
        }
    });
    editBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            editSrx();
        }
    });
    deleteBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = tableViewer.getSelection();
            if (!selection.isEmpty() && selection != null && selection instanceof StructuredSelection) {
                boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("srx.SrxConfigurationDialog.msgTitle1"), Messages.getString("srx.SrxConfigurationDialog.msg1"));
                if (!response) {
                    return;
                }
                StructuredSelection structSelection = (StructuredSelection) selection;
                @SuppressWarnings("unchecked") Iterator<String[]> it = structSelection.iterator();
                File deleteSrx;
                boolean isTiped = false;
                while (it.hasNext()) {
                    String srxName = it.next()[1];
                    if (isSystemSrx(srxName)) {
                        if (!isTiped) {
                            MessageDialog.openInformation(getShell(), Messages.getString("dialogs.CatalogManagerDialog.msgTitle2"), Messages.getString("srx.SrxConfigurationDialog.msg4"));
                            isTiped = true;
                        }
                        continue;
                    }
                    deleteSrx = new File(ADConstants.configLocation + ADConstants.AD_SRXConfigFolder + File.separator + srxName);
                    if (!deleteSrx.delete()) {
                        MessageDialog.openInformation(getShell(), Messages.getString("srx.SrxConfigurationDialog.msgTitle2"), MessageFormat.format(Messages.getString("srx.SrxConfigurationDialog.msg2"), srxName));
                    }
                }
                refreshTable(null);
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("srx.SrxConfigurationDialog.msgTitle2"), Messages.getString("srx.SrxConfigurationDialog.msg3"));
            }
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Iterator(java.util.Iterator) File(java.io.File)

Example 70 with SelectionEvent

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

the class PreTranslationDialog method createPageContent.

/**
	 * 创建页面内容
	 * @param parent
	 *            ;
	 */
private void createPageContent(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gl_composite = new GridLayout(1, false);
    gl_composite.marginHeight = 0;
    gl_composite.marginWidth = 0;
    gl_composite.verticalSpacing = 0;
    composite.setLayout(gl_composite);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    viewer = new TableViewer(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = viewer.getTable();
    GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    tableGd.heightHint = 220;
    table.setLayoutData(tableGd);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    String[] clmnTitles = new String[] { Messages.getString("dialog.PreTranslationDialog.clmnTitles1"), Messages.getString("dialog.PreTranslationDialog.clmnTitles2"), Messages.getString("dialog.PreTranslationDialog.clmnTitles3"), Messages.getString("dialog.PreTranslationDialog.clmnTitles4") };
    int[] clmnBounds = { 80, 250, 100, 100 };
    for (int i = 0; i < clmnTitles.length; i++) {
        createTableViewerColumn(viewer, clmnTitles[i], clmnBounds[i], i);
    }
    viewer.setLabelProvider(new TableViewerLabelProvider());
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(this.getTableViewerInput());
    // 参数面板
    Composite cmpPerTranParam = new Composite(composite, SWT.BORDER);
    GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(cmpPerTranParam);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(cmpPerTranParam);
    // 预翻译参数
    Group groupMatch = new Group(cmpPerTranParam, SWT.NONE);
    GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(groupMatch);
    GridLayoutFactory.swtDefaults().applyTo(groupMatch);
    groupMatch.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.match"));
    Composite cmpPercent = new Composite(groupMatch, SWT.NONE);
    GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(cmpPercent);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(cmpPercent);
    Label lblLowest = new Label(cmpPercent, SWT.NONE);
    lblLowest.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.lowestmatch"));
    spinner = new Spinner(cmpPercent, SWT.BORDER);
    spinner.setMinimum(1);
    spinner.setIncrement(5);
    spinner.setSelection(70);
    Label lblPercentage = new Label(cmpPercent, SWT.NONE);
    lblPercentage.setText("%");
    btnIgnoreCase = new Button(groupMatch, SWT.CHECK);
    btnIgnoreCase.setSelection(true);
    btnIgnoreCase.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.ignorecase"));
    GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(btnIgnoreCase);
    btnIgnoretag = new Button(groupMatch, SWT.CHECK);
    GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(btnIgnoretag);
    btnIgnoretag.setSelection(true);
    btnIgnoretag.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.ignoretag"));
    btnIgnoretag.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setPanalty(!btnIgnoretag.getSelection());
        }
    });
    Composite cmpPenalty = new Composite(groupMatch, SWT.NONE);
    cmpPenalty.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayoutFactory.fillDefaults().margins(15, 0).numColumns(2).applyTo(cmpPenalty);
    lblTagPenalty = new Label(cmpPenalty, SWT.NONE);
    lblTagPenalty.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.tagPenalty"));
    spinnnerPanalty = new Spinner(cmpPenalty, SWT.BORDER);
    spinnnerPanalty.setSelection(2);
    setPanalty(false);
    // 锁定参数
    String lockGrpText = Messages.getString("dialog.PreTranslationDialog.pertrans.lock");
    Group groupLockWhenPerTrans = new Group(cmpPerTranParam, SWT.MULTI | SWT.WRAP);
    GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(groupLockWhenPerTrans);
    GridLayoutFactory.swtDefaults().numColumns(1).applyTo(groupLockWhenPerTrans);
    groupLockWhenPerTrans.setText(lockGrpText);
    btn101Match = new Button(groupLockWhenPerTrans, SWT.CHECK);
    btn101Match.setSelection(true);
    btn101Match.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.fullMatch"));
    btnContextMatch = new Button(groupLockWhenPerTrans, SWT.CHECK);
    btnContextMatch.setSelection(true);
    btnContextMatch.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.contextMatch"));
    Label lbl = new Label(groupLockWhenPerTrans, SWT.NONE);
    lbl.setText(lockGrpText);
    lbl.setVisible(false);
    // 覆盖策略
    Group groupHandleOldTarget = new Group(cmpPerTranParam, SWT.NONE);
    GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).applyTo(groupHandleOldTarget);
    GridLayoutFactory.swtDefaults().numColumns(1).applyTo(groupHandleOldTarget);
    groupHandleOldTarget.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.handleTargetText"));
    btnKeepOld = new Button(groupHandleOldTarget, SWT.RADIO);
    btnKeepOld.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.keepOld"));
    btnKeepBestMatch = new Button(groupHandleOldTarget, SWT.RADIO);
    btnKeepBestMatch.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.keepBestMatch"));
    btnKeepNew = new Button(groupHandleOldTarget, SWT.RADIO);
    btnKeepNew.setText(Messages.getString("dialog.PreTranslationDialog.pertrans.keepNew"));
    setDefaultValues();
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

SelectionEvent (org.eclipse.swt.events.SelectionEvent)1136 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)923 GridData (org.eclipse.swt.layout.GridData)670 GridLayout (org.eclipse.swt.layout.GridLayout)566 Button (org.eclipse.swt.widgets.Button)558 Composite (org.eclipse.swt.widgets.Composite)553 Label (org.eclipse.swt.widgets.Label)370 SelectionListener (org.eclipse.swt.events.SelectionListener)262 Text (org.eclipse.swt.widgets.Text)253 Group (org.eclipse.swt.widgets.Group)193 ModifyEvent (org.eclipse.swt.events.ModifyEvent)160 ModifyListener (org.eclipse.swt.events.ModifyListener)159 Combo (org.eclipse.swt.widgets.Combo)140 Point (org.eclipse.swt.graphics.Point)98 MenuItem (org.eclipse.swt.widgets.MenuItem)95 Menu (org.eclipse.swt.widgets.Menu)94 TableViewer (org.eclipse.jface.viewers.TableViewer)91 Table (org.eclipse.swt.widgets.Table)91 ToolItem (org.eclipse.swt.widgets.ToolItem)90 ArrayList (java.util.ArrayList)88