Search in sources :

Example 26 with Composite

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

the class ProjectSettingTBPage 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.ProjectSettingTBPage.FileNotFoundMsg"));
                    return;
                } else {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTBPage.title"));
                }
            }
            if (dbModel != null && !dbModel.isHasMatch()) {
                setMessage(Messages.getString("projectsetting.ProjectSettingTBPage.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.ProjectSettingTBPage.addBtn"));
    Menu addMenu = addBtn.getMenu();
    MenuItem item = new MenuItem(addMenu, SWT.PUSH);
    item.setText(Messages.getString("tb.dialog.addTb.DropDownButton.AddFileTb"));
    item.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialg = new FileDialog(getShell());
            fileDialg.setFilterExtensions(new String[] { "*.hstb", "*.*" });
            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.convertFile2TbModel(f, false);
            } catch (Exception e1) {
                MessageDialog.openError(getShell(), Messages.getString("tb.dialog.addFileTb.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("tb.dialog.addTb.DropDownButton.AddServerTb"));
    serverItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TermDbManagerDialog dialog = new TermDbManagerDialog(getShell());
            dialog.setDialogUseFor(TermDbManagerDialog.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.ProjectSettingTBPage.createBtn"));
    createBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            NewTermDbWizard wizard = new NewTermDbWizard();
            TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(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.ProjectSettingTBPage.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.ProjectSettingTBPage.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();
                TbxImportWizard wizard = new TbxImportWizard(dbModel);
                TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(getShell(), wizard);
                if (dlg.open() == 0) {
                    checkDbHashMatch(dbModel);
                    tableViewer.refresh();
                }
                // 刷新项目
                ResourceUtils.refreshCurentSelectProject();
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("projectsetting.ProjectSettingTBPage.msgTitle"), Messages.getString("projectsetting.ProjectSettingTBPage.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) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TbxImportWizard(net.heartsome.cat.database.ui.tb.wizard.TbxImportWizard) TermDbManagerDialog(net.heartsome.cat.database.ui.tb.dialog.TermDbManagerDialog) 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) Composite(org.eclipse.swt.widgets.Composite) TermDbManagerImportWizardDialog(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizardDialog) 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) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) Map(java.util.Map) NewTermDbWizard(net.heartsome.cat.database.ui.tb.wizard.NewTermDbWizard)

Example 27 with Composite

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

the class TermDbManagerDialog 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 28 with Composite

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

the class ImportTbxHandler method execute.

/**
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    TermDbManagerImportWizard wizard = new TermDbManagerImportWizard();
    TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(window.getShell(), wizard) {

        // robert help 2012-09-06
        @Override
        protected Control createHelpControl(Composite parent) {
            // ROBERTHELP 导入TBX
            String language = CommonFunction.getSystemLanguage();
            final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03.html#create-tb-wizard-import-tbx", language);
            Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
            ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
            ((GridLayout) parent.getLayout()).numColumns++;
            toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
            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;
        }
    };
    dlg.setHelpAvailable(true);
    dlg.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DisposeListener(org.eclipse.swt.events.DisposeListener) TermDbManagerImportWizardDialog(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizardDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TermDbManagerImportWizard(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizard) ToolBar(org.eclipse.swt.widgets.ToolBar) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 29 with Composite

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

the class PPTXPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite tparent = new Composite(parent, SWT.NONE);
    tparent.setLayout(new GridLayout());
    tparent.setLayoutData(new GridData(GridData.FILL_BOTH));
    Group groupCommon = new Group(tparent, SWT.NONE);
    groupCommon.setLayout(new GridLayout());
    groupCommon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    groupCommon.setText(Messages.getString("preference.PPTXPreferencePage.groupCommon"));
    HsImageLabel imageLabel = new HsImageLabel(Messages.getString("preference.PPTXPreferencePage.imageLabel"), Activator.getImageDescriptor(Constants.PREFERENCE_PPTX_32));
    Composite cmpCommon = imageLabel.createControl(groupCommon);
    cmpCommon.setLayout(new GridLayout());
    cmpCommon.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnNote = new Button(cmpCommon, SWT.CHECK);
    btnNote.setText(Messages.getString("preference.PPTXPreferencePage.btnNote"));
    GridDataFactory.fillDefaults().applyTo(btnNote);
    imageLabel.computeSize();
    btnNote.setSelection(preferenceStore.getBoolean(Constants.PPTX_FILTER));
    return parent;
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) HsImageLabel(net.heartsome.cat.common.ui.HsImageLabel) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData)

Example 30 with Composite

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

the class TSWizardDialog method createPreviousAndNextButtons.

/**
	 * Creates the Previous and Next buttons for this wizard dialog. Creates
	 * standard (<code>SWT.PUSH</code>) buttons and registers for their
	 * selection events. Note that the number of columns in the button bar
	 * composite is incremented. These buttons are created specially to prevent
	 * any space between them.
	 * 
	 * @param parent
	 *            the parent button bar
	 * @return a composite containing the new buttons
	 */
private Composite createPreviousAndNextButtons(Composite parent) {
    // increment the number of columns in the button bar
    ((GridLayout) parent.getLayout()).numColumns++;
    Composite composite = new Composite(parent, SWT.NONE);
    // create a layout with spacing and margins appropriate for the font
    // size.
    GridLayout layout = new GridLayout();
    // will be incremented by createButton
    layout.numColumns = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    composite.setLayout(layout);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER);
    composite.setLayoutData(data);
    composite.setFont(parent.getFont());
    backButton = createButton(composite, IDialogConstants.BACK_ID, IDialogConstants.BACK_LABEL, false);
    nextButton = createButton(composite, IDialogConstants.NEXT_ID, IDialogConstants.NEXT_LABEL, false);
    // make sure screen readers skip visual '<', '>' chars on buttons:
    final String backReaderText = IDialogConstants.BACK_LABEL.replace('<', ' ');
    backButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(AccessibleEvent e) {
            e.result = backReaderText;
        }
    });
    final String nextReaderText = IDialogConstants.NEXT_LABEL.replace('>', ' ');
    nextButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {

        public void getName(AccessibleEvent e) {
            e.result = nextReaderText;
        }
    });
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) AccessibleAdapter(org.eclipse.swt.accessibility.AccessibleAdapter) AccessibleEvent(org.eclipse.swt.accessibility.AccessibleEvent)

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