Search in sources :

Example 6 with FocusEvent

use of org.eclipse.swt.events.FocusEvent in project dbeaver by serge-rider.

the class PrefPageProjectSettings method createContents.

@Override
protected Control createContents(final Composite parent) {
    Composite composite = UIUtils.createPlaceholder(parent, 1, 5);
    {
        UIUtils.createControlLabel(composite, "Resource locations");
        resourceTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
        resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        resourceTable.setHeaderVisible(true);
        resourceTable.setLinesVisible(true);
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, "Resource");
        UIUtils.createTableColumn(resourceTable, SWT.LEFT, "Folder");
        resourceTable.setHeaderVisible(true);
        resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
        handlerTableEditor = new TableEditor(resourceTable);
        handlerTableEditor.verticalAlignment = SWT.TOP;
        handlerTableEditor.horizontalAlignment = SWT.RIGHT;
        handlerTableEditor.grabHorizontal = true;
        handlerTableEditor.grabVertical = true;
        resourceTable.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent e) {
                disposeOldEditor();
                final TableItem item = resourceTable.getItem(new Point(0, e.y));
                if (item == null) {
                    return;
                }
                int columnIndex = UIUtils.getColumnAtPos(item, e.x, e.y);
                if (columnIndex <= 0) {
                    return;
                }
                if (columnIndex == 1) {
                    final String resourcePath = item.getText(1);
                    if (project != null) {
                        final IFolder folder = project.getFolder(resourcePath);
                        ContainerSelectionDialog dialog = new ContainerSelectionDialog(resourceTable.getShell(), folder, true, "Select " + item.getText(0) + " root folder");
                        dialog.showClosedProjects(false);
                        dialog.setValidator(new ISelectionValidator() {

                            @Override
                            public String isValid(Object selection) {
                                if (selection instanceof IPath) {
                                    final File file = ((IPath) selection).toFile();
                                    if (file.isHidden() || file.getName().startsWith(".")) {
                                        return "Can't use hidden folders";
                                    }
                                    final String[] segments = ((IPath) selection).segments();
                                    if (!project.getName().equals(segments[0])) {
                                        return "Can't store resources in another project";
                                    }
                                }
                                return null;
                            }
                        });
                        if (dialog.open() == IDialogConstants.OK_ID) {
                            final Object[] result = dialog.getResult();
                            if (result.length == 1 && result[0] instanceof IPath) {
                                final IPath plainPath = ((IPath) result[0]).removeFirstSegments(1).removeTrailingSeparator();
                                item.setText(1, plainPath.toString());
                            }
                        }
                    } else {
                        final Text editor = new Text(resourceTable, SWT.NONE);
                        editor.setText(resourcePath);
                        editor.selectAll();
                        handlerTableEditor.setEditor(editor, item, 1);
                        editor.setFocus();
                        editor.addFocusListener(new FocusAdapter() {

                            @Override
                            public void focusLost(FocusEvent e) {
                                item.setText(1, editor.getText());
                            }
                        });
                    }
                }
            }
        });
    }
    performDefaults();
    return composite;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) IPath(org.eclipse.core.runtime.IPath) MouseAdapter(org.eclipse.swt.events.MouseAdapter) ISelectionValidator(org.eclipse.ui.dialogs.ISelectionValidator) Point(org.eclipse.swt.graphics.Point) TableEditor(org.eclipse.swt.custom.TableEditor) FocusEvent(org.eclipse.swt.events.FocusEvent) Point(org.eclipse.swt.graphics.Point) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) GridData(org.eclipse.swt.layout.GridData) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with FocusEvent

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

the class NatTable method initInternalListener.

protected void initInternalListener() {
    modeSupport = new ModeSupport(this);
    modeSupport.registerModeEventHandler(Mode.NORMAL_MODE, new ConfigurableModeEventHandler(modeSupport, this));
    modeSupport.switchMode(Mode.NORMAL_MODE);
    addPaintListener(this);
    addFocusListener(new FocusListener() {

        public void focusLost(final FocusEvent arg0) {
            redraw();
        }

        public void focusGained(final FocusEvent arg0) {
            redraw();
        }
    });
    addListener(SWT.Resize, new Listener() {

        public void handleEvent(final Event e) {
            doCommand(new ClientAreaResizeCommand(NatTable.this));
        }
    });
}
Also used : ModeSupport(net.sourceforge.nattable.ui.mode.ModeSupport) PaintListener(org.eclipse.swt.events.PaintListener) ILayerListener(net.sourceforge.nattable.layer.ILayerListener) FocusListener(org.eclipse.swt.events.FocusListener) Listener(org.eclipse.swt.widgets.Listener) ClientAreaResizeCommand(net.sourceforge.nattable.grid.command.ClientAreaResizeCommand) ConfigurableModeEventHandler(net.sourceforge.nattable.ui.mode.ConfigurableModeEventHandler) IVisualChangeEvent(net.sourceforge.nattable.layer.event.IVisualChangeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) PaintEvent(org.eclipse.swt.events.PaintEvent) ILayerEvent(net.sourceforge.nattable.layer.event.ILayerEvent) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 8 with FocusEvent

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

the class AddOrEditXmlConvertConfigDialog method createRootTxt.

/**
	 * 创建xml根,与存储目录
	 * @param tparent
	 *            ;
	 */
private void createRootTxt(Composite tparent) {
    Composite composite = new Composite(tparent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
    GridLayoutFactory.fillDefaults().spacing(0, SWT.DEFAULT).numColumns(5).applyTo(composite);
    Label rootLbl = new Label(composite, SWT.NONE);
    rootLbl.setText(Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.rootLbl"));
    rootTxt = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).hint(100, SWT.DEFAULT).applyTo(rootTxt);
    // 显示一个图标与“被保存到:”
    Label iconLbl = new Label(composite, SWT.NONE);
    iconLbl.setImage(icon);
    GridDataFactory.fillDefaults().indent(4, SWT.DEFAULT).applyTo(iconLbl);
    Label textLbl = new Label(composite, SWT.NONE);
    textLbl.setText(Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.textLbl"));
    rootTipLbl = new Label(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.LEFT, SWT.CENTER).applyTo(rootTipLbl);
    rootTxt.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String tipText = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootTxt.getText().trim() + ".xml").toOSString();
            rootTipLbl.setText(tipText);
            rootTipLbl.pack();
            rootTipLbl.setToolTipText(tipText);
        }
    });
    // 在添加状态下,当根元素文本框失去焦点后,验证是否为空,验证是否重复
    rootTxt.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            String rootStr = rootTxt.getText().trim();
            if (isAdd || (!rootStr.equals(curRootStr))) {
                if ("".equals(rootStr)) {
                    MessageDialog.openWarning(getShell(), Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msgTitle1"), Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msg1"));
                } else {
                    // 提示文件是否重复
                    String configXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
                    File xmlConfigFile = new File(configXmlLoaction);
                    if (xmlConfigFile.exists()) {
                        String configXmlFullPath = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
                        MessageDialog.openWarning(getShell(), Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msgTitle1"), MessageFormat.format(Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msg2"), configXmlFullPath));
                    }
                }
                super.focusLost(e);
            }
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent) File(java.io.File)

Example 9 with FocusEvent

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

the class AnalysisXmlConvertConfigDialg method createRootTxt.

private void createRootTxt(Composite tparent) {
    Composite composite = new Composite(tparent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
    GridLayoutFactory.fillDefaults().spacing(0, 1).numColumns(5).applyTo(composite);
    Label analysisXmlLbl = new Label(composite, SWT.NONE);
    analysisXmlLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.analysisXmlLbl"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(analysisXmlLbl);
    Composite browseCmp = new Composite(composite, SWT.NONE);
    GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).grab(true, false).span(4, SWT.DEFAULT).applyTo(browseCmp);
    GridLayoutFactory.fillDefaults().numColumns(2).extendedMargins(0, 0, 0, 0).applyTo(browseCmp);
    analysisTxt = new Text(browseCmp, SWT.BORDER);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(analysisTxt);
    Button browseBtn = new Button(browseCmp, SWT.NONE);
    browseBtn.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.browseBtn"));
    Label rootLbl = new Label(composite, SWT.NONE);
    rootLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.rootLbl"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(rootLbl);
    rootTxt = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).hint(100, SWT.DEFAULT).applyTo(rootTxt);
    // 显示一个图标与“被保存到:”
    Label iconLbl = new Label(composite, SWT.NONE);
    iconLbl.setImage(icon);
    GridDataFactory.fillDefaults().indent(4, SWT.DEFAULT).applyTo(iconLbl);
    Label textLbl = new Label(composite, SWT.NONE);
    textLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.textLbl"));
    rootTipLbl = new Label(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.LEFT, SWT.CENTER).applyTo(rootTipLbl);
    rootTxt.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String tipText = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootTxt.getText().trim().toLowerCase() + ".xml").toOSString();
            rootTipLbl.setText(tipText);
            rootTipLbl.pack();
            rootTipLbl.setToolTipText(tipText);
        }
    });
    // 在添加状态下,当根元素文本框失去焦点后,验证是否为空,验证是否重复
    rootTxt.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {

        public void focusLost(FocusEvent e) {
            String rootStr = rootTxt.getText().trim().toLowerCase();
            if ("".equals(rootStr)) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msgTitle"), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msg1"));
            } else {
                // 提示文件是否重复
                String configXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
                File xmlConfigFile = new File(configXmlLoaction);
                if (xmlConfigFile.exists()) {
                    String configXmlFullPath = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
                    MessageDialog.openInformation(getShell(), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msgTitle"), MessageFormat.format(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msg2"), configXmlFullPath));
                }
            }
            super.focusLost(e);
        }
    });
    browseBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            String[] extensions = { "*.xml", "*" };
            String[] names = { Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.filterXML"), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.filterAll") };
            fd.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.fdTitle"));
            fd.setFilterExtensions(extensions);
            fd.setFilterNames(names);
            String xmlLocation = fd.open();
            analysisTxt.setText(xmlLocation);
            // 解析XML文件并且填充到列表
            analysisXml(xmlLocation);
        }
    });
    analysisTxt.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            analysisXml(analysisTxt.getText());
            super.focusLost(e);
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 10 with FocusEvent

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

the class CustomFilterDialog method setGray.

/**
	 * 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒
	 * @param text
	 *            Text控件
	 * @param initTxt
	 *            灰色提醒字符串
	 */
private void setGray(final Text text, final String initTxt) {
    text.setForeground(gray);
    text.setText(initTxt);
    text.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent arg0) {
            if (text.getText().trim().equals("")) {
                if (!text.getForeground().equals(gray)) {
                    text.setForeground(gray);
                }
                text.setText(initTxt);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }

        public void focusGained(FocusEvent arg0) {
            if (text.getText().trim().equals(initTxt)) {
                text.setText("");
                text.setForeground(black);
            } else {
                if (!text.getForeground().equals(black)) {
                    text.setForeground(black);
                }
            }
        }
    });
}
Also used : FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

FocusEvent (org.eclipse.swt.events.FocusEvent)98 FocusAdapter (org.eclipse.swt.events.FocusAdapter)55 SelectionEvent (org.eclipse.swt.events.SelectionEvent)50 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)42 FocusListener (org.eclipse.swt.events.FocusListener)40 GridData (org.eclipse.swt.layout.GridData)34 Text (org.eclipse.swt.widgets.Text)30 GridLayout (org.eclipse.swt.layout.GridLayout)29 Composite (org.eclipse.swt.widgets.Composite)28 Label (org.eclipse.swt.widgets.Label)23 Menu (org.eclipse.swt.widgets.Menu)21 Button (org.eclipse.swt.widgets.Button)19 MenuManager (org.eclipse.jface.action.MenuManager)18 ModifyEvent (org.eclipse.swt.events.ModifyEvent)17 ModifyListener (org.eclipse.swt.events.ModifyListener)17 Group (org.eclipse.swt.widgets.Group)17 Point (org.eclipse.swt.graphics.Point)16 Combo (org.eclipse.swt.widgets.Combo)15 MenuItem (org.eclipse.swt.widgets.MenuItem)15 KeyEvent (org.eclipse.swt.events.KeyEvent)12