Search in sources :

Example 71 with GridData

use of org.eclipse.swt.layout.GridData in project translationstudio8 by heartsome.

the class TermDbManagerDialog method createSash.

/**
	 * Create the sash with right control on the right. Note that this method assumes GridData for the layout data of
	 * the rightControl.
	 * @param composite
	 * @param rightControl
	 * @return Sash
	 */
protected Sash createSash(final Composite composite, final Control rightControl) {
    final Sash sash = new Sash(composite, SWT.VERTICAL);
    sash.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    sash.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    // the following listener resizes the tree control based on sash deltas.
    // If necessary, it will also grow/shrink the dialog.
    sash.addListener(SWT.Selection, new Listener() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt. widgets.Event)
			 */
        public void handleEvent(Event event) {
            if (event.detail == SWT.DRAG) {
                return;
            }
            int shift = event.x - sash.getBounds().x;
            GridData data = (GridData) rightControl.getLayoutData();
            int newWidthHint = data.widthHint + shift;
            if (newWidthHint < 20) {
                return;
            }
            Point computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            Point currentSize = getShell().getSize();
            // if the dialog wasn't of a custom size we know we can shrink
            // it if necessary based on sash movement.
            boolean customSize = !computedSize.equals(currentSize);
            data.widthHint = newWidthHint;
            setLastTreeWidth(newWidthHint);
            composite.layout(true);
            // recompute based on new widget size
            computedSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            // necessary.
            if (customSize) {
                computedSize.x = Math.max(computedSize.x, currentSize.x);
            }
            computedSize.y = Math.max(computedSize.y, currentSize.y);
            if (computedSize.equals(currentSize)) {
                return;
            }
            setShellSize(computedSize.x, computedSize.y);
            lastShellSize = getShell().getSize();
        }
    });
    return sash;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener) Sash(org.eclipse.swt.widgets.Sash) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ShellEvent(org.eclipse.swt.events.ShellEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Point(org.eclipse.swt.graphics.Point)

Example 72 with GridData

use of org.eclipse.swt.layout.GridData in project translationstudio8 by heartsome.

the class TermDbManagerDialog method createDialogArea.

/**
	 * Create contents of the dialog.
	 * @param parent
	 */
@Override
protected Control createDialogArea(Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout parentLayout = ((GridLayout) composite.getLayout());
    parentLayout.numColumns = 4;
    parentLayout.marginHeight = 0;
    parentLayout.marginWidth = 0;
    parentLayout.marginTop = 0;
    parentLayout.verticalSpacing = 0;
    parentLayout.horizontalSpacing = 0;
    Control treeControl = createTreeAreaContents(composite);
    createSash(composite, treeControl);
    Label versep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
    GridData verGd = new GridData(GridData.FILL_VERTICAL | GridData.GRAB_VERTICAL);
    versep.setLayoutData(verGd);
    versep.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));
    Composite pageAreaComposite = new Composite(composite, SWT.NONE);
    pageAreaComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout(1, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    pageAreaComposite.setLayout(layout);
    // Build the Page container
    Composite pageContainer = createPageContainer(pageAreaComposite);
    GridData pageContainerData = new GridData(GridData.FILL_BOTH);
    pageContainerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
    pageContainer.setLayoutData(pageContainerData);
    // Build the separator line
    Label bottomSeparator = new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR);
    bottomSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    return composite;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData)

Example 73 with GridData

use of org.eclipse.swt.layout.GridData in project translationstudio8 by heartsome.

the class TBDatabasePage method createContents.

@Override
protected Control createContents(Composite parent) {
    // TODO Auto-generated method stub
    Composite tparent = new Composite(parent, SWT.NONE);
    tparent.setLayout(new GridLayout());
    tparent.setLayoutData(new GridData(GridData.FILL_BOTH));
    // 添加术语匹配是否忽略大小写
    {
        Group commonGroup1 = new Group(tparent, SWT.NONE);
        commonGroup1.setLayout(new GridLayout());
        commonGroup1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        commonGroup1.setText(Messages.getString("preference.TBDatabasePage.commontitle"));
        HsImageLabel imageLbale1 = new HsImageLabel(Messages.getString("preference.TBDatabasePage.commonsearchterm"), Activator.getImageDescriptor("images/preference/tb/tb_update_32.png"));
        Composite comp1 = imageLbale1.createControl(commonGroup1);
        btnCaseSensitive = new Button(comp1, SWT.CHECK);
        btnCaseSensitive.setText(Messages.getString("preference.TBDatabasePage.commonCasesensitive"));
        btnCaseSensitive.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        imageLbale1.computeSize();
    }
    Group commonGroup = new Group(tparent, SWT.NONE);
    commonGroup.setLayout(new GridLayout());
    commonGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    commonGroup.setText(Messages.getString("preference.TBDatabasePage.commonGroup"));
    HsImageLabel imageLbale = new HsImageLabel(Messages.getString("preference.TBDatabasePage.imageLbale"), Activator.getImageDescriptor("images/preference/tb/tb_update_32.png"));
    Composite comp = imageLbale.createControl(commonGroup);
    btnAlwaysAdd = new Button(comp, SWT.RADIO);
    btnAlwaysAdd.setText(Messages.getString("preference.TBDatabasePage.btnAlwaysAdd"));
    btnAlwaysAdd.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnRepeatOverwrite = new Button(comp, SWT.RADIO);
    btnRepeatOverwrite.setText(Messages.getString("preference.TBDatabasePage.btnRepeatOverwrite"));
    btnRepeatOverwrite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnRepeatMerge = new Button(comp, SWT.RADIO);
    btnRepeatMerge.setText(Messages.getString("preference.TBDatabasePage.btnRepeatMerge"));
    btnRepeatMerge.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnRepeatIgnore = new Button(comp, SWT.RADIO);
    btnRepeatIgnore.setText(Messages.getString("preference.TBDatabasePage.btnRepeatIgnore"));
    btnRepeatIgnore.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    parent.pack();
    imageLbale.computeSize();
    int intUpdateTB = preferenceStore.getInt(TBPreferenceConstants.TB_UPDATE);
    setInitValues(intUpdateTB);
    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 74 with GridData

use of org.eclipse.swt.layout.GridData 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 75 with GridData

use of org.eclipse.swt.layout.GridData in project translationstudio8 by heartsome.

the class TermDbManagerDialog method createHelpControl.

/**
	 * 添加帮助按钮 robert 2012-09-06
	 */
@Override
protected Control createHelpControl(Composite parent) {
    // ROBERTHELP 术语库管理
    String language = CommonFunction.getSystemLanguage();
    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch06s04.html#tb-management", 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;
}
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)

Aggregations

GridData (org.eclipse.swt.layout.GridData)2385 GridLayout (org.eclipse.swt.layout.GridLayout)1659 Composite (org.eclipse.swt.widgets.Composite)1448 Label (org.eclipse.swt.widgets.Label)982 Button (org.eclipse.swt.widgets.Button)732 SelectionEvent (org.eclipse.swt.events.SelectionEvent)719 Text (org.eclipse.swt.widgets.Text)578 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)577 Group (org.eclipse.swt.widgets.Group)509 Combo (org.eclipse.swt.widgets.Combo)234 ModifyListener (org.eclipse.swt.events.ModifyListener)225 ModifyEvent (org.eclipse.swt.events.ModifyEvent)214 SelectionListener (org.eclipse.swt.events.SelectionListener)213 Table (org.eclipse.swt.widgets.Table)196 Point (org.eclipse.swt.graphics.Point)167 TableViewer (org.eclipse.jface.viewers.TableViewer)162 FillLayout (org.eclipse.swt.layout.FillLayout)134 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)118 Control (org.eclipse.swt.widgets.Control)117 Image (org.eclipse.swt.graphics.Image)114