Search in sources :

Example 6 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project cogtool by cogtool.

the class ActionSet method createTransitionName.

private Text createTransitionName(Composite parent, String txt) {
    final Text name = new Text(parent, SWT.BORDER);
    final NameInfo info = new NameInfo(txt);
    // Note that we have to use a VerifyListener to prevent editing the
    // contents of the Text, as SWT has made the rather surprising decision
    // that setting its editable field to false also
    // takes away our ability to select and navigate in the field, and copy
    // its contents. Grr.
    name.addVerifyListener(new VerifyListener() {

        public void verifyText(VerifyEvent evt) {
            // the user's trying to modify an already populated Text. Yuk.
            switch(transitionNameState) {
                case NORMAL:
                    info.fullName = evt.text;
                    evt.text = SWTStringUtil.insertEllipsis(info.fullName, name.getSize().x, StringUtil.EQUAL, name.getFont());
                    break;
                case HAS_FOCUS:
                    evt.doit = false;
                    break;
                case GAINING_FOCUS:
                    break;
            }
        }
    });
    name.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent evt) {
            transitionNameState = TransitionNameState.GAINING_FOCUS;
            name.setText(info.fullName);
            transitionNameState = TransitionNameState.HAS_FOCUS;
        }

        @Override
        public void focusLost(FocusEvent evt) {
            transitionNameState = TransitionNameState.NORMAL;
            name.setText(info.fullName);
        }
    });
    name.setText(txt);
    return name;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) VerifyListener(org.eclipse.swt.events.VerifyListener) ManagedText(edu.cmu.cs.hcii.cogtool.util.ManagedText) Text(org.eclipse.swt.widgets.Text) VerifyEvent(org.eclipse.swt.events.VerifyEvent) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 7 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project tdi-studio-se by Talend.

the class SchemaDetailsColumnMouseAdapter method mouseDown.

@Override
public void mouseDown(MouseEvent e) {
    currentPoint = new Point(e.x, e.y);
    // Clean up any previous editor control
    Control oldEditor = getEditor();
    if (oldEditor != null) {
        oldEditor.dispose();
    }
    if (getViewerCell() == null) {
        return;
    }
    // Identify the selected row
    TreeItem item = (TreeItem) getViewerCell().getViewerRow().getItem();
    if (item == null) {
        return;
    }
    if (getColumnIndex() < 1) {
        // ingore first
        return;
    }
    final Object data = item.getData();
    if (!(data instanceof ColumnLineData)) {
        return;
    }
    ColumnLineData lineData = (ColumnLineData) data;
    List<MultiMetadataColumn> metadataColumnsInModel = lineData.getKeyData().getMetadataColumnsInModel();
    final MultiMetadataColumn multiMetadataColumn = metadataColumnsInModel.get(getColumnIndex() - 1);
    Control newEditor = null;
    final EPropertyName property = lineData.getProperty();
    if (UIManager.isFirstForColumnModel(property)) {
        newEditor = createTextControl(item, property, multiMetadataColumn);
    } else {
        switch(property) {
            case NAME:
            case TAGLEVEL:
                break;
            case TYPE:
                newEditor = createComboControl(item, multiMetadataColumn);
                break;
            case LENGTH:
            // case CARD:
            case PATTERN:
                newEditor = createTextControl(item, property, multiMetadataColumn);
                break;
            case KEY:
                /*
                 * ingore record type(first column);
                 * 
                 * if existed key column, should not edit other key.
                 */
                if (getColumnIndex() == uiManager.getSelectedColumnIndex() + 1 || UIManager.existedKeyColumn(metadataColumnsInModel, multiMetadataColumn)) {
                    break;
                }
                newEditor = createCheckBoxControl(item, property, multiMetadataColumn);
                break;
        }
    }
    if (newEditor != null) {
        newEditor.addFocusListener(new FocusAdapter() {

            public void focusLost(FocusEvent e) {
                if (getEditor() != null && !getEditor().isDisposed()) {
                    getEditor().dispose();
                }
            }
        });
        newEditor.setFocus();
        getTreeEditor().setEditor(newEditor, item, getColumnIndex());
    }
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Control(org.eclipse.swt.widgets.Control) EPropertyName(org.talend.designer.filemultischemas.data.EPropertyName) TreeItem(org.eclipse.swt.widgets.TreeItem) Point(org.eclipse.swt.graphics.Point) FocusEvent(org.eclipse.swt.events.FocusEvent) MultiMetadataColumn(org.talend.designer.filemultischemas.data.MultiMetadataColumn)

Example 8 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project tdi-studio-se by Talend.

the class ExportItemWizardPage method createItemRoot.

@SuppressWarnings("restriction")
private void createItemRoot(Composite workArea) {
    Composite projectGroup = new Composite(workArea, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.makeColumnsEqualWidth = false;
    layout.marginWidth = 0;
    projectGroup.setLayout(layout);
    projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    itemFromDirectoryRadio = new Button(projectGroup, SWT.RADIO);
    // itemFromDirectoryRadio.setText(DataTransferMessages.WizardProjectsImportPage_RootSelectTitle);
    //$NON-NLS-1$
    itemFromDirectoryRadio.setText(Messages.getString("DataTransferMessages.WizardProjectsImportPage_RootSelectTitle"));
    this.directoryPathField = new Text(projectGroup, SWT.BORDER);
    String arcFileName = null;
    if (selection != null && selection.getFirstElement() instanceof RepositoryNode) {
        RepositoryNode node = (RepositoryNode) selection.getFirstElement();
        if (node.getObject() == null) {
            arcFileName = node.getLabel();
        } else {
            arcFileName = node.getObject().getLabel();
        }
    }
    this.directoryPathField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    String exportDirPath = reloadExportPath(DIRECTORY_PATH);
    if (exportDirPath != null) {
        if (arcFileName != null) {
            if (new Path(exportDirPath).lastSegment() != null && !new Path(exportDirPath).lastSegment().equals(arcFileName)) {
                exportDirPath = exportDirPath + File.separator + arcFileName;
            }
        }
        this.directoryPathField.setText(exportDirPath);
        this.lastPath = exportDirPath;
    }
    browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);
    // browseDirectoriesButton.setText(DataTransferMessages.DataTransfer_browse);
    //$NON-NLS-1$
    browseDirectoriesButton.setText(Messages.getString("DataTransferMessages.DataTransfer_browse"));
    setButtonLayoutData(browseDirectoriesButton);
    // new project from archive radio button
    itemFromArchiveRadio = new Button(projectGroup, SWT.RADIO);
    // itemFromArchiveRadio.setText(DataTransferMessages.WizardProjectsImportPage_ArchiveSelectTitle);
    //$NON-NLS-1$
    itemFromArchiveRadio.setText(Messages.getString("DataTransferMessages.WizardProjectsImportPage_ArchiveSelectTitle"));
    // project location entry field
    archivePathField = new Text(projectGroup, SWT.BORDER);
    archivePathField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    if (arcFileName != null) {
        String exportArchivePath = reloadExportPath(ARCHIVE_PATH);
        // when first open the exportItem dialog ,the exportPath maybe empty,need judge
        if (exportArchivePath != null && exportArchivePath.trim().length() > 0) {
            File beforeExportArchiveFolder = new File(exportArchivePath).getParentFile();
            /*
                 * TDI-22791, when the exportArchivePath is only name without path. No need check the existed or not.
                 * Because will be create the parent folders, when export item.
                 */
            if (beforeExportArchiveFolder != null) /* && beforeExportArchiveFolder.exists() */
            {
                String newPath = new File(beforeExportArchiveFolder, arcFileName + FileConstants.ZIP_FILE_SUFFIX).getAbsolutePath();
                this.archivePathField.setText(newPath);
            }
        } else if (exportDirPath != null && exportDirPath.trim().length() > 0) {
            String newPath = exportDirPath + File.separator + arcFileName + FileConstants.ZIP_FILE_SUFFIX;
            this.archivePathField.setText(newPath);
        }
    }
    // browse button
    browseArchivesButton = new Button(projectGroup, SWT.PUSH);
    // browseArchivesButton.setText(DataTransferMessages.DataTransfer_browse);
    //$NON-NLS-1$
    browseArchivesButton.setText(Messages.getString("DataTransferMessages.DataTransfer_browse"));
    setButtonLayoutData(browseArchivesButton);
    itemFromDirectoryRadio.setSelection(true);
    archivePathField.setEnabled(false);
    browseArchivesButton.setEnabled(false);
    browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleLocationArchiveButtonPressed();
        }
    });
    directoryPathField.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
                lastPath = directoryPathField.getText().trim();
            }
        }
    });
    directoryPathField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
            lastPath = directoryPathField.getText().trim();
        }
    });
    directoryPathField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            String exportPath = resetExportPath(directoryPathField.getText());
            saveExportPath(DIRECTORY_PATH, exportPath);
        }
    });
    archivePathField.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
                lastPath = archivePathField.getText().trim();
            }
        }
    });
    archivePathField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
            lastPath = archivePathField.getText().trim();
        }
    });
    archivePathField.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            saveExportPath(ARCHIVE_PATH, archivePathField.getText());
        }
    });
    itemFromDirectoryRadio.addSelectionListener(new SelectionAdapter() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            archiveRadioSelected();
        }
    });
    exportDependencies = new Button(workArea, SWT.CHECK);
    //$NON-NLS-1$
    exportDependencies.setText(Messages.getString("ExportItemWizardPage.exportDependenciesText"));
    exportDependencies.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkedDependency.clear();
            implicitDependences.clear();
            CheckboxTreeViewer exportItemsTreeViewer = getItemsTreeViewer();
            Set allNode = new HashSet();
            if (exportDependencies.getSelection()) {
                refreshExportDependNodes();
                exportDependenciesSelected();
                allNode.addAll(checkedDependency);
                allNode.addAll(implicitDependences);
            } else {
                allNode.addAll(initcheckedNodes);
            }
            Set toselect = new HashSet();
            for (Object obj : allNode) {
                ERepositoryObjectType objectType = getObjectType(obj);
                expandRoot(objectType);
                expandParent(exportItemsTreeViewer, obj, objectType);
                checkElement(obj, toselect);
            }
            exportItemsTreeViewer.setCheckedElements(toselect.toArray());
            if (!exportDependencies.getSelection()) {
                for (Object unchecked : uncheckedNodes) {
                    exportItemsTreeViewer.setChecked(unchecked, false);
                }
            }
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) Set(java.util.Set) HashSet(java.util.HashSet) ModifyListener(org.eclipse.swt.events.ModifyListener) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) HashSet(java.util.HashSet) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Composite(org.eclipse.swt.widgets.Composite) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridData(org.eclipse.swt.layout.GridData) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) File(java.io.File)

Example 9 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project tdi-studio-se by Talend.

the class BasicNotePropertyComposite method createTextControl.

/**
     * DOC qwei Comment method "createTextcontrol".
     */
private void createTextControl(Composite parent) {
    //$NON-NLS-1$
    CLabel textLabel = getWidgetFactory().createCLabel(composite, Messages.getString("TextNoteSection.Label"));
    //$NON-NLS-1$
    FormData data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.top = new FormAttachment(colorsAndFontsGroup, 30);
    textLabel.setLayoutData(data);
    //$NON-NLS-1$
    text = getWidgetFactory().createText(composite, "", SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    //$NON-NLS-1$
    data = new FormData();
    data.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
    data.right = new FormAttachment(textLabel, 560);
    data.top = new FormAttachment(textLabel, 0, SWT.TOP);
    // 5 lines
    data.height = 5 * text.getLineHeight();
    text.setLayoutData(data);
    text.setForeground(new Color(null, ColorUtils.stringToRGB((String) note.getPropertyValue(EParameterName.NOTETXT_COLOR.getName()))));
    text.setText(note.getText());
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            if (!text.getText().equals(note.getText())) {
                ChangeNoteTextCommand command = new ChangeNoteTextCommand(note, text.getText());
                getCommandStack().execute(command);
            }
        }
    });
    text.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
            // TODO Auto-generated method stub
            if (!text.getText().equals(note.getText())) {
                ChangeNoteTextCommand command = new ChangeNoteTextCommand(note, text.getText());
                getCommandStack().execute(command);
            }
        }
    });
    textChanged();
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Color(org.eclipse.swt.graphics.Color) KeyListener(org.eclipse.swt.events.KeyListener) FocusEvent(org.eclipse.swt.events.FocusEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) ChangeNoteTextCommand(org.talend.designer.core.ui.editor.cmd.ChangeNoteTextCommand)

Example 10 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.

the class PstmtOneDataDialog method handleValueInPlace.

/**
	 * 
	 * Edit value in place
	 * 
	 * @param item TableItem
	 */
private void handleValueInPlace(final TableItem item) {
    final Text newEditor = new Text(parameterTable, SWT.MULTI | SWT.WRAP);
    final int editColumn = 2;
    newEditor.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            if (!validate(newEditor.getText(), item)) {
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
        }
    });
    newEditor.addFocusListener(new FocusAdapter() {

        public void focusLost(FocusEvent event) {
            if (isChanging) {
                return;
            }
            isChanging = true;
            if (validate(newEditor.getText(), item)) {
                item.setText(editColumn, newEditor.getText());
            }
            newEditor.dispose();
            isChanging = false;
            packTable();
            validate();
        }
    });
    // add listener for key pressed
    newEditor.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            if (event.detail == SWT.TRAVERSE_RETURN) {
                if (isChanging) {
                    return;
                }
                isChanging = true;
                if (validate(newEditor.getText(), item)) {
                    item.setText(editColumn, newEditor.getText());
                }
                newEditor.dispose();
                isChanging = false;
                packTable();
                validate();
                event.doit = true;
                int selItem = 0;
                for (int i = 0; i < parameterTable.getItemCount(); i++) {
                    if (item == parameterTable.getItem(i)) {
                        selItem = i;
                        break;
                    }
                }
                selItem = selItem + 1;
                if (selItem >= parameterTable.getItemCount()) {
                    getButton(IDialogConstants.OK_ID).setFocus();
                } else {
                    handleType(parameterTable.getItem(selItem));
                }
            } else if (event.detail == SWT.TRAVERSE_ESCAPE) {
                if (isChanging) {
                    return;
                }
                isChanging = true;
                newEditor.dispose();
                event.doit = false;
                isChanging = false;
            }
        }
    });
    tableEditor.setEditor(newEditor, item, editColumn);
    newEditor.setText(item.getText(editColumn));
    newEditor.selectAll();
    newEditor.setFocus();
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) TraverseListener(org.eclipse.swt.events.TraverseListener) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

FocusAdapter (org.eclipse.swt.events.FocusAdapter)68 FocusEvent (org.eclipse.swt.events.FocusEvent)64 SelectionEvent (org.eclipse.swt.events.SelectionEvent)42 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)36 Composite (org.eclipse.swt.widgets.Composite)29 GridData (org.eclipse.swt.layout.GridData)28 Text (org.eclipse.swt.widgets.Text)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 Label (org.eclipse.swt.widgets.Label)20 Button (org.eclipse.swt.widgets.Button)17 Menu (org.eclipse.swt.widgets.Menu)17 Point (org.eclipse.swt.graphics.Point)16 MenuManager (org.eclipse.jface.action.MenuManager)15 MenuItem (org.eclipse.swt.widgets.MenuItem)15 ModifyEvent (org.eclipse.swt.events.ModifyEvent)14 ModifyListener (org.eclipse.swt.events.ModifyListener)14 KeyEvent (org.eclipse.swt.events.KeyEvent)12 Combo (org.eclipse.swt.widgets.Combo)12 KeyAdapter (org.eclipse.swt.events.KeyAdapter)11 Group (org.eclipse.swt.widgets.Group)11