Search in sources :

Example 56 with Composite

use of org.eclipse.swt.widgets.Composite in project translationstudio8 by heartsome.

the class TmDbManagerDialog method initUI.

/**
	 * 根据当前操作不同的数据库类型,初始化界面 ;
	 */
private void initUI(boolean isAdd) {
    MetaData curDbMetaData = dbMetaDataMap.get(getCurrDbType());
    if (!isAdd) {
        Control[] childrens = locationText.getParent().getChildren();
        for (Control c : childrens) {
            if (!(c instanceof Composite)) {
                if (c instanceof Text || c instanceof Button) {
                    c.setEnabled(false);
                }
            } else {
                Composite com = (Composite) c;
                Control[] ch = com.getChildren();
                for (Control chl : ch) {
                    if (c instanceof Text || c instanceof Button) {
                        chl.setEnabled(false);
                    }
                }
            }
        }
    } else {
        if (curDbMetaData.dataPathSupported()) {
            locationText.setEnabled(true);
            borwserBtn.setEnabled(true);
        } else {
            locationText.setEnabled(false);
            borwserBtn.setEnabled(false);
        }
        if (curDbMetaData.serverNameSupported()) {
            hostText.setEnabled(true);
        } else {
            hostText.setEnabled(false);
        }
        if (curDbMetaData.instanceSupported()) {
            instanceText.setEnabled(true);
        } else {
            instanceText.setEnabled(false);
        }
        if (curDbMetaData.portSupported()) {
            portText.setEnabled(true);
        } else {
            portText.setEnabled(false);
        }
        if (curDbMetaData.userNameSupported()) {
            usernameText.setEnabled(true);
        } else {
            usernameText.setEnabled(false);
        }
        if (curDbMetaData.passwordSupported()) {
            passwordText.setEnabled(true);
        } else {
            passwordText.setEnabled(false);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Button(org.eclipse.swt.widgets.Button) MetaData(net.heartsome.cat.common.bean.MetaData) Text(org.eclipse.swt.widgets.Text)

Example 57 with Composite

use of org.eclipse.swt.widgets.Composite in project translationstudio8 by heartsome.

the class NewTmDbImportPage method createControl.

/**
	 * Create contents of the wizard.
	 * @param parent
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new GridLayout(3, false));
    Label lblTmx = new Label(container, SWT.NONE);
    lblTmx.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblTmx.setText(Messages.getString("wizard.NewTmDbImportPage.lblTmx"));
    tmxFileText = new Text(container, SWT.BORDER);
    tmxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tmxFileText.setEditable(false);
    Button tmxFileBorwserBtn = new Button(container, SWT.NONE);
    tmxFileBorwserBtn.setText(Messages.getString("wizard.NewTmDbImportPage.tmxFileBorwserBtn"));
    tmxFileBorwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dlg = new FileDialog(getShell());
            String[] filterExt = { "*.tmx;*.xlsx;*.txt" };
            dlg.setFilterExtensions(filterExt);
            String path = dlg.open();
            if (path != null) {
                tmxFileText.setText(path);
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 58 with Composite

use of org.eclipse.swt.widgets.Composite in project translationstudio8 by heartsome.

the class ProjectSettingTMPage method createContents.

/**
	 * Create contents of the preference page.
	 * @param parent
	 */
@Override
public Control createContents(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tableViewer.setContentProvider(new ArrayContentProvider());
    createColumn(tableViewer);
    tableViewer.setInput(curDbList);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            DatabaseModelBean dbModel = (DatabaseModelBean) selection.getFirstElement();
            if (null == dbModel) {
                return;
            }
            if (Constants.DBTYPE_SQLITE.equals(dbModel.getDbType())) {
                String path = dbModel.getItlDBLocation() + File.separator + dbModel.getDbName();
                File file = new File(path);
                if (!file.exists()) {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.FileNotFound"));
                    return;
                } else {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.title"));
                }
            }
            if (dbModel != null && !dbModel.isHasMatch()) {
                setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.msg1"));
            }
        }
    });
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite.setLayout(new GridLayout(5, false));
    new Label(composite, SWT.NONE);
    HSDropDownButton addBtn = new HSDropDownButton(composite, SWT.NONE);
    addBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.addBtn"));
    Menu addMenu = addBtn.getMenu();
    MenuItem item = new MenuItem(addMenu, SWT.PUSH);
    item.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
    item.addSelectionListener(new SelectionAdapter() {

        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, false);
            } 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();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(selectedVal);
                addToCurrDbList(dbList);
            }
        }
    });
    MenuItem serverItem = new MenuItem(addMenu, 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) {
                Iterator<DatabaseModelBean> it = dialog.getHasSelectedDatabase().keySet().iterator();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                while (it.hasNext()) {
                    dbList.add(it.next());
                }
                addToCurrDbList(dbList);
            }
        }
    });
    Button createBtn = new Button(composite, SWT.NONE);
    createBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.createBtn"));
    createBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            NewTmDbWizard wizard = new NewTmDbWizard();
            ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
            if (dlg.open() == 0) {
                DatabaseModelBean dbModel = wizard.getCreateDb();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(dbModel);
                addToCurrDbList(dbList);
            }
        }
    });
    Button removeBtn = new Button(composite, SWT.NONE);
    removeBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.removeBtn"));
    removeBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeForCurrDbList((IStructuredSelection) tableViewer.getSelection());
        }
    });
    Button importTmxBtn = new Button(composite, SWT.NONE);
    importTmxBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.importTmxBtn"));
    importTmxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            Iterator<?> it = selection.iterator();
            if (it.hasNext()) {
                DatabaseModelBean dbModel = (DatabaseModelBean) it.next();
                ImportTmxWizard wizard = new ImportTmxWizard(dbModel);
                ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
                if (dlg.open() == 0) {
                    checkDbHashMatch(dbModel);
                    tableViewer.refresh();
                }
                // 刷新项目
                ResourceUtils.refreshCurentSelectProject();
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("projectsetting.ProjectSettingTMPage.msgTitle"), Messages.getString("projectsetting.ProjectSettingTMPage.msg2"));
            }
        }
    });
    addBtn.setFocus();
    Point addPoint = addBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = createBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = removeBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importTmxBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(addPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    addBtn.setLayoutData(btnData);
    createBtn.setLayoutData(btnData);
    removeBtn.setLayoutData(btnData);
    importTmxBtn.setLayoutData(btnData);
    return container;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) 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) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) TmDbManagerDialog(net.heartsome.cat.database.ui.tm.dialog.TmDbManagerDialog) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) Point(org.eclipse.swt.graphics.Point) NewTmDbWizard(net.heartsome.cat.database.ui.tm.wizard.NewTmDbWizard) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) Map(java.util.Map)

Example 59 with Composite

use of org.eclipse.swt.widgets.Composite in project translationstudio8 by heartsome.

the class XLIFFEditorStatusLineItem method fill.

public void fill(Composite parent) {
    statusLine = parent;
    new Label(parent, SWT.SEPARATOR);
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout gl = new GridLayout(1, false);
    gl.marginWidth = 0;
    gl.marginHeight = 0;
    gl.marginTop = 0;
    gl.marginRight = 0;
    gl.marginBottom = 0;
    container.setLayout(gl);
    label = new Label(container, SWT.SHADOW_NONE);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true, 1, 1));
    label.setAlignment(SWT.CENTER);
    label.setText(text);
    if (image != null) {
        label.setImage(image);
        label.setToolTipText(text);
    }
//		Point preferredSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
//		int widthHint = preferredSize.x;
//		int heightHint = preferredSize.y;
//		if (widthHint < 0) {
//			// Compute the size base on 'charWidth' average char widths
//			GC gc = new GC(statusLine);
//			gc.setFont(statusLine.getFont());
//			FontMetrics fm = gc.getFontMetrics();
//			widthHint = fm.getAverageCharWidth() * 40;
//			heightHint = fm.getHeight();
//			gc.dispose();
//		}
//		StatusLineLayoutData data = new StatusLineLayoutData();
//		data.widthHint = widthHint;
//		label.setLayoutData(data);
//		StatusLineLayoutData data = new StatusLineLayoutData();
//		data.heightHint = heightHint;
//		speLb.setLayoutData(data);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData)

Example 60 with Composite

use of org.eclipse.swt.widgets.Composite in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method addFilterComposite.

/**
	 * 添加填充过滤器面板内容的面板
	 * @param parent
	 * @return 过滤器面板;
	 */
private void addFilterComposite(Composite main) {
    Composite top = new Composite(main, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).margins(0, 0).applyTo(top);
    top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // 输入行号进行定位
    final String rowLocationStr = Messages.getString("editor.XLIFFEditorImplWithNatTable.rowLocationStr");
    Text txtRowLocation = new Text(top, SWT.BORDER);
    txtRowLocation.setText(rowLocationStr);
    int width = 40;
    if (Util.isLinux()) {
        width = 35;
    }
    GridDataFactory.swtDefaults().hint(width, SWT.DEFAULT).applyTo(txtRowLocation);
    txtRowLocation.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            Text text = (Text) e.widget;
            if (rowLocationStr.equals(text.getText())) {
                text.setText("");
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            Text text = (Text) e.widget;
            if ("".equals(text.getText())) {
                text.setText(rowLocationStr);
            }
        }
    });
    txtRowLocation.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
                String rowNumString = ((Text) event.widget).getText().trim();
                if (rowNumString != null && !"".equals(rowNumString)) {
                    int rowPosition;
                    try {
                        rowPosition = Integer.parseInt(rowNumString) - 1;
                        jumpToRow(rowPosition, false);
                        updateStatusLine();
                    } catch (NumberFormatException e) {
                        Text text = (Text) event.widget;
                        text.setText("");
                    }
                }
            }
        }
    });
    txtRowLocation.addVerifyListener(new VerifyListener() {

        public void verifyText(VerifyEvent event) {
            if (event.keyCode == 0 && event.stateMask == 0) {
            // 文本框得到焦点时
            } else if (Character.isDigit(event.character) || event.character == '\b' || event.keyCode == 127) {
                // 输入数字,或者按下Backspace、Delete键
                if ("".equals(((Text) event.widget).getText().trim()) && event.character == '0') {
                    event.doit = false;
                } else {
                    event.doit = true;
                }
            } else {
                event.doit = false;
            }
        }
    });
    cmbFilter = new Combo(top, SWT.BORDER | SWT.READ_ONLY);
    cmbFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // TODO 完善过滤器初始化数据。
    // cmbFilter.add("所有文本段");
    // cmbFilter.add("未翻译文本段");
    // cmbFilter.add("已翻译文本段");
    // cmbFilter.add("未批准文本段");
    // cmbFilter.add("已批准文本段");
    // cmbFilter.add("有批注文本段");
    // cmbFilter.add("锁定文本段");
    // cmbFilter.add("未锁定文本段");
    // cmbFilter.add("重复文本段");
    // cmbFilter.add("疑问文本段");
    // cmbFilter.add("上下文匹配文本段");
    // cmbFilter.add("完全匹配文本段");
    // cmbFilter.add("模糊匹配文本段");
    // cmbFilter.add("快速翻译文本段");
    // cmbFilter.add("自动繁殖文本段");
    // cmbFilter.add("错误标记文本段");
    // cmbFilter.add("术语不一致文本段");
    // cmbFilter.add("译文不一致文本段");
    // cmbFilter.add("带修订标记文本段");
    final Set<String> filterNames = XLFHandler.getFilterNames();
    for (String filterName : filterNames) {
        cmbFilter.add(filterName);
    }
    // 添加选项改变监听
    cmbFilter.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // Fixed Bug #2243 by Jason 当鼠标焦点在源文单元框中使用过滤器,对过滤后的译文进行操作会提示该行锁定不能操作
            // ActiveCellEditor.commit();
            HsMultiActiveCellEditor.commit(true);
            Combo cmbFilter = (Combo) e.widget;
            boolean isUpdated = handler.doFilter(cmbFilter.getText(), langFilterCondition);
            if (isUpdated) {
                if (table != null) {
                    bodyLayer.getSelectionLayer().clear();
                    if (bodyLayer.selectionLayer.getRowCount() > 0) {
                        // 默认选中第一行
                        HsMultiActiveCellEditor.commit(true);
                        bodyLayer.selectionLayer.doCommand(new SelectCellCommand(bodyLayer.getSelectionLayer(), getTgtColumnIndex(), isHorizontalLayout ? 0 : 1, false, false));
                        HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.this);
                    }
                    table.setFocus();
                }
                // 自动调整 NatTable 大小 ;
                autoResize();
                // 更新状态栏
                updateStatusLine();
                NattableUtil.refreshCommand(XLIFFEditorSelectionPropertyTester.PROPERTY_NAMESPACE, XLIFFEditorSelectionPropertyTester.PROPERTY_ENABLED);
            }
        }
    });
    Button btnSaveFilter = new Button(top, SWT.NONE);
    // TODO 考虑换成图片显示。
    btnSaveFilter.setText(Messages.getString("editor.XLIFFEditorImplWithNatTable.btnAddFilter"));
    btnSaveFilter.setToolTipText(Messages.getString("editor.XLIFFEditorImplWithNatTable.btnAddFilterTooltip"));
    btnSaveFilter.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CustomFilterDialog dialog = new CustomFilterDialog(table.getShell(), cmbFilter);
            dialog.open();
        // int res = dialog.open();
        // if (res == CustomFilterDialog.OK) {
        // cmbFilter.select(cmbFilter.getItemCount() - 1); // 选中最后一行数据
        // cmbFilter.notifyListeners(SWT.Selection, null);
        // }
        }
    });
    // 默认选中第一行数据
    cmbFilter.select(0);
    cmbFilter.notifyListeners(SWT.Selection, null);
    // 更新nattable的列名为语言对
    renameColumn();
    top.pack();
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) VerifyListener(org.eclipse.swt.events.VerifyListener) CustomFilterDialog(net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.CustomFilterDialog) Composite(org.eclipse.swt.widgets.Composite) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Aggregations

Composite (org.eclipse.swt.widgets.Composite)2054 GridData (org.eclipse.swt.layout.GridData)1441 GridLayout (org.eclipse.swt.layout.GridLayout)1419 Label (org.eclipse.swt.widgets.Label)853 Button (org.eclipse.swt.widgets.Button)694 SelectionEvent (org.eclipse.swt.events.SelectionEvent)577 Text (org.eclipse.swt.widgets.Text)519 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)463 Group (org.eclipse.swt.widgets.Group)305 Combo (org.eclipse.swt.widgets.Combo)210 Point (org.eclipse.swt.graphics.Point)198 FillLayout (org.eclipse.swt.layout.FillLayout)188 ModifyListener (org.eclipse.swt.events.ModifyListener)186 SelectionListener (org.eclipse.swt.events.SelectionListener)183 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)182 ModifyEvent (org.eclipse.swt.events.ModifyEvent)168 Table (org.eclipse.swt.widgets.Table)159 TableViewer (org.eclipse.jface.viewers.TableViewer)153 Control (org.eclipse.swt.widgets.Control)149 ArrayList (java.util.ArrayList)107