Search in sources :

Example 31 with Listener

use of org.eclipse.swt.widgets.Listener in project ACS by ACS-Community.

the class SourcesView method createViewWidgets.

private void createViewWidgets(final Composite parent) {
    _sash = new SashForm(parent, SWT.HORIZONTAL);
    _sash.setLayout(new FillLayout());
    /* Left pane */
    _sourcesComp = new Composite(_sash, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    _sourcesComp.setLayout(layout);
    _listGroup = new Group(_sourcesComp, SWT.SHADOW_ETCHED_IN);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    _listGroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    _listGroup.setLayout(gl);
    _listGroup.setText("Sources List");
    _sourcesList = new List(_listGroup, SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    _sourcesList.setLayoutData(gd);
    _sourcesButtonsComp = new Composite(_sourcesComp, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    _sourcesButtonsComp.setLayout(layout);
    _addSourceButton = new Button(_sourcesButtonsComp, SWT.None);
    _addSourceButton.setText("Add");
    _addSourceButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    _deleteSourceButton = new Button(_sourcesButtonsComp, SWT.None);
    _deleteSourceButton.setText("Delete");
    _deleteSourceButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE));
    /* Please change this in the future when more SOURCES will be available */
    _addSourceButton.setEnabled(false);
    _deleteSourceButton.setEnabled(false);
    _sourcesList.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            String source = _sourcesList.getSelection()[0];
            Control c = _compInitial.getChildren()[0];
            if (c instanceof Label) {
                c.dispose();
                _group.setVisible(true);
                _group.layout();
            }
            fillSource(source);
            _compInitial.layout();
        }
    });
    _addSourceButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            InputDialog dialog = new InputDialog(SourcesView.this.getViewSite().getShell(), "New source", "Enter the source name", null, new IInputValidator() {

                public String isValid(String newText) {
                    if (newText.trim().compareTo("") == 0)
                        return "The name is empty";
                    return null;
                }
            });
            dialog.setBlockOnOpen(true);
            dialog.open();
            int returnCode = dialog.getReturnCode();
            if (returnCode == InputDialog.OK) {
                Source newSource = new Source();
                newSource.setSourceId(dialog.getValue());
                try {
                    _sourceManager.addSource(newSource);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(SourcesView.this.getViewSite().getShell(), "Source already exist", "The source " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                refreshContents();
                if (_sourcesList.getItems().length != 0) {
                    int lenght = _sourcesList.getItems().length;
                    lenght -= 1;
                    _sourcesList.select(lenght);
                    _descriptionText.setText(_sourcesList.getItem(lenght).toString());
                }
            }
        }
    });
    _deleteSourceButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            boolean choice = MessageDialog.openQuestion(SourcesView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this Source");
            if (choice == true) {
                String[] tmp = _sourcesList.getSelection();
                if (tmp.length == 0) {
                    MessageBox box = new MessageBox(getViewSite().getShell(), SWT.OK | SWT.ICON_ERROR | SWT.APPLICATION_MODAL);
                    box.setText("Empty selection");
                    box.setMessage("There are no sources selected to be deleted");
                    box.open();
                    return;
                }
                String source = tmp[0];
                try {
                    _sourceManager.deleteSource(_sourceManager.getSource(source));
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(SourcesView.this.getViewSite().getShell(), "Cannot delete source", "The source cannot be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                }
                refreshContents();
                if (_sourcesList.getItems().length != 0) {
                    int lenght = _sourcesList.getItems().length;
                    lenght -= 1;
                    _sourcesList.select(lenght);
                    _sourceNameText.setText(_sourcesList.getItem(lenght).toString());
                }
            }
        }
    });
    /* Right pane */
    _compInitial = new Composite(_sash, SWT.NONE);
    _compInitial.setLayout(new GridLayout());
    new Label(_compInitial, SWT.NONE).setText("Select a source");
    layout = new GridLayout();
    layout.numColumns = 2;
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    _group = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    _group.setText("Source information");
    _group.setLayout(layout);
    _group.setLayoutData(gd);
    _sourceNameLabel = new Label(_group, SWT.NONE);
    _sourceNameLabel.setText("Source name");
    _sourceNameText = new Text(_group, SWT.BORDER);
    _descriptionLabel = new Label(_group, SWT.NONE);
    _descriptionLabel.setText("Description");
    _descriptionText = new Text(_group, SWT.BORDER);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    _sourceNameText.setLayoutData(gd);
    _descriptionText.setLayoutData(gd);
    _group.setVisible(false);
    _sash.setWeights(new int[] { 3, 5 });
    /* TODO: This is temporal, since there is currently only
		 * one source defined in the AS, and it's hardcoded */
    //setEnabled(false);
    _descriptionText.addListener(SWT.Modify, new Listener() {

        public void handleEvent(Event e) {
            updateSource();
        }
    });
    _errorMessageLabel = new Label(_group, SWT.NONE);
    _errorMessageLabel.setText("");
    _errorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _errorMessageLabel.setLayoutData(gd);
    /* Please change this in the future when more SOURCES will be available */
    _sourceNameText.setEnabled(false);
    _descriptionText.setEnabled(false);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) Source(cern.laser.business.data.Source) MessageBox(org.eclipse.swt.widgets.MessageBox) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(org.eclipse.swt.widgets.List) SelectionListener(org.eclipse.swt.events.SelectionListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 32 with Listener

use of org.eclipse.swt.widgets.Listener in project ACS by ACS-Community.

the class AlarmSystemView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    setTitleImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_ALARM_SYSTEM));
    Listener selectAlarmSystem = new Listener() {

        public void handleEvent(Event event) {
            if (((Button) event.widget).getSelection()) {
                if (_acsAS_radio.getSelection()) {
                    _alarmSystemManager.setConfigurationProperty("Implementation", "ACS");
                    enableViews(false);
                }
                if (_cernAS_radio.getSelection()) {
                    _alarmSystemManager.setConfigurationProperty("Implementation", "CERN");
                    enableViews(true);
                }
            }
        }

        ;
    };
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.makeColumnsEqualWidth = true;
    layout.marginTop = 20;
    layout.marginLeft = 20;
    _comp = new Group(parent, SWT.SHADOW_ETCHED_IN);
    _comp.setLayout(layout);
    _comp.setText("Alarm System Configuration");
    /* buttons that represent AS */
    _acsAS_radio = new Button(_comp, SWT.RADIO);
    _acsAS_radio.setText("ACS Alarm System");
    _acsAS_radio.addListener(SWT.Selection, selectAlarmSystem);
    _cernAS_radio = new Button(_comp, SWT.RADIO);
    _cernAS_radio.setText("CERN Alarm System");
    _cernAS_radio.addListener(SWT.Selection, selectAlarmSystem);
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Listener(org.eclipse.swt.widgets.Listener) Button(org.eclipse.swt.widgets.Button) Event(org.eclipse.swt.widgets.Event)

Example 33 with Listener

use of org.eclipse.swt.widgets.Listener in project cubrid-manager by CUBRID.

the class PstmtSQLDialog method createEmptyTable.

/**
	 * Create the empty parameter table
	 *
	 * @param parent Composite
	 * @param isMulti boolean
	 */
protected void createEmptyTable(Composite parent) {
    Group typeGroup = new Group(parent, SWT.SHADOW_ETCHED_IN);
    GridData groupGd = new GridData(GridData.FILL_HORIZONTAL);
    groupGd.heightHint = 70;
    typeGroup.setLayoutData(groupGd);
    typeGroup.setLayout(new GridLayout());
    typeGroup.setText(Messages.colParaType);
    parameterTypeTable = new Table(typeGroup, SWT.BORDER | SWT.H_SCROLL);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint = 45;
    parameterTypeTable.setLayoutData(gd);
    parameterTypeTable.setHeaderVisible(true);
    parameterTypeTable.setLinesVisible(false);
    parameterTypeTable.setDragDetect(false);
    TableColumn columnNO = new TableColumn(parameterTypeTable, SWT.CENTER);
    columnNO.setWidth(40);
    columnNO.setText("");
    tableEditor = new TableEditor(parameterTypeTable);
    tableEditor.horizontalAlignment = SWT.LEFT;
    tableEditor.grabHorizontal = true;
    parameterTypeTable.addListener(SWT.MouseUp, new Listener() {

        public void handleEvent(Event event) {
            if (event.button != 1) {
                return;
            }
            if (isChanging) {
                return;
            }
            Point pt = new Point(event.x, event.y);
            final TableItem item = parameterTypeTable.getItem(0);
            for (int i = 1; i < parameterTypeTable.getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    handleType(item, i);
                }
            }
        }
    });
    Group parameterGroup = new Group(parent, SWT.SHADOW_IN);
    parameterGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    parameterGroup.setLayout(new GridLayout(2, false));
    parameterGroup.setText(Messages.colParaValue);
    ToolBar toolBar = new ToolBar(parameterGroup, SWT.FLAT);
    ToolItem addRecordItem = new ToolItem(toolBar, SWT.PUSH);
    addRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_insert.png"));
    addRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addData();
        }
    });
    ToolItem delRecordItem = new ToolItem(toolBar, SWT.PUSH);
    delRecordItem.setImage(CommonUIPlugin.getImage("icons/action/table_record_delete.png"));
    delRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (parameterTable.getTable().getSelectionIndices().length == 0) {
                setErrorMessage(Messages.errDeleteMsg);
                return;
            }
            List<Integer> deleteIndex = new ArrayList<Integer>();
            for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                deleteIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
            }
            int lastSelectedIndex = 0;
            for (int i = 0; i < deleteIndex.size(); i++) {
                int seletectIndex = deleteIndex.get(i);
                int newIndex = seletectIndex - i;
                valueList.remove(newIndex);
                lastSelectedIndex = newIndex;
            }
            //reset the index in data
            for (int i = 0; i < valueList.size(); i++) {
                ParamValueObject paramValueObject = valueList.get(i);
                paramValueObject.getValue().set(0, String.valueOf(i + 1));
            }
            parameterTable.setInput(valueList);
            parameterTable.refresh();
            if (parameterTable.getTable().getItemCount() > 0) {
                parameterTable.getTable().setSelection(lastSelectedIndex < 1 ? 0 : lastSelectedIndex - 1);
                parameterTable.getTable().setFocus();
            }
            validate();
        }
    });
    parameterTable = new TableViewer(parameterGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    // press the tab key, it is moved next input area
    TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(parameterTable, new FocusCellOwnerDrawHighlighter(parameterTable));
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(parameterTable) {

        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION && ((MouseEvent) event.sourceEvent).button == 1) || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
        //				|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    };
    TableViewerEditor.create(parameterTable, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    //		new Table(parameterGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    parameterTable.getTable().setLayoutData(gridData);
    parameterTable.getTable().setHeaderVisible(true);
    parameterTable.getTable().setLinesVisible(true);
    parameterTable.setUseHashlookup(true);
    final TableViewerColumn columnNO2 = new TableViewerColumn(parameterTable, SWT.CENTER);
    columnNO2.getColumn().setWidth(40);
    columnNO2.getColumn().setText("");
    parameterTable.setContentProvider(new ParamValueContentProvider());
    parameterTable.setLabelProvider(new ParamValueLabelProvider(parameterTable.getTable()));
    parameterTable.getTable().addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {
            if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'c') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                StringBuffer clipboardDataString = new StringBuffer();
                List<Integer> replaceIndex = new ArrayList<Integer>();
                for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                    replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
                }
                for (int i = 0; i < replaceIndex.size(); i++) {
                    if (i != 0) {
                        clipboardDataString.append(EXCELDATASEPRATOR);
                    }
                    ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
                    for (int j = 1; j < parameterTypeTable.getColumnCount(); j++) {
                        if (j != 1) {
                            clipboardDataString.append(EXCELCOLUMNSEPRATOR);
                        }
                        String value = paramValueObject.getValue().get(j);
                        clipboardDataString.append(value);
                    }
                }
                TextTransfer textTransfer = TextTransfer.getInstance();
                Transfer[] transfers = new Transfer[] { textTransfer };
                Object[] data = new Object[] { clipboardDataString.toString() };
                cb.setContents(data, transfers);
                cb.dispose();
            } else if ((event.stateMask & SWT.CTRL) != 0 && event.keyCode == 'v') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                //					boolean supportFlag = false;
                //					TransferData[] transferDatas = cb.getAvailableTypes();
                //					for(int i=0; i<transferDatas.length; i++) {
                //						// Checks whether RTF format is available.
                //						if(RTFTransfer.getInstance().isSupportedType(transferDatas[i])) {
                //							supportFlag = true;
                //							break;
                //						}
                //					}
                //					if (!supportFlag) {
                //						setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
                //						return;
                //					}
                String plainText = (String) cb.getContents(TextTransfer.getInstance());
                List<ParamValueObject> list = generateParamValueObjectListFromClipboardString(plainText);
                if (list.size() == 0 || list.get(0).getValue().size() != parameterTypeTable.getColumnCount()) {
                    setErrorMessage(Messages.pstmtSQLUnsupportPasteType);
                    return;
                }
                //					String rtfText = (String)cb.getContents(RTFTransfer.getInstance());
                int startIndex = parameterTable.getTable().getSelectionIndex();
                //if the copy line bigger than the value list, add new ParamValueObject to the end
                if (parameterTable.getTable().getSelectionCount() <= 1) {
                    if (startIndex < 0 || startIndex > valueList.size()) {
                        for (ParamValueObject copyParamValueObject : list) {
                            valueList.add(copyParamValueObject);
                        }
                    } else {
                        for (ParamValueObject copyParamValueObject : list) {
                            if (startIndex > valueList.size() - 1) {
                                valueList.add(copyParamValueObject);
                            } else {
                                ParamValueObject paramValueObject = valueList.get(startIndex);
                                List<String> oldValue = paramValueObject.getValue();
                                for (int i = 1; i < oldValue.size(); i++) {
                                    List<String> newValue = copyParamValueObject.getValue();
                                    if (i > newValue.size() - 1) {
                                        break;
                                    }
                                    oldValue.set(i, newValue.get(i));
                                }
                            }
                            startIndex++;
                        }
                    }
                } else {
                    // replay the select line
                    List<Integer> replaceIndex = new ArrayList<Integer>();
                    for (int i = 0; i < parameterTable.getTable().getSelectionIndices().length; i++) {
                        replaceIndex.add(parameterTable.getTable().getSelectionIndices()[i]);
                    }
                    for (int i = 0; i < replaceIndex.size(); i++) {
                        ParamValueObject paramValueObject = valueList.get(replaceIndex.get(i));
                        List<String> oldValue = paramValueObject.getValue();
                        if (i > list.size()) {
                            break;
                        }
                        List<String> newValue = list.get(i).getValue();
                        for (int j = 1; j < oldValue.size(); j++) {
                            if (j > newValue.size()) {
                                break;
                            }
                            oldValue.set(j, newValue.get(j));
                        }
                    }
                }
                cb.dispose();
                refreshValueListIndex();
                parameterTable.refresh();
                validate();
            }
        }
    });
    // use to mark click point, the right click menu use this point
    parameterTable.getTable().addListener(SWT.MouseDown, new Listener() {

        public void handleEvent(Event event) {
            clickPoint = new Point(event.x, event.y);
        }
    });
    registerContextMenu();
    parameterTable.setInput(valueList);
}
Also used : Group(org.eclipse.swt.widgets.Group) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) TraverseListener(org.eclipse.swt.events.TraverseListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) TableItem(org.eclipse.swt.widgets.TableItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) FocusCellOwnerDrawHighlighter(org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ToolItem(org.eclipse.swt.widgets.ToolItem) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableEditor(org.eclipse.swt.custom.TableEditor) Point(org.eclipse.swt.graphics.Point) TableViewerFocusCellManager(org.eclipse.jface.viewers.TableViewerFocusCellManager) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Event(org.eclipse.swt.widgets.Event) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Clipboard(org.eclipse.swt.dnd.Clipboard) TableViewer(org.eclipse.jface.viewers.TableViewer) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 34 with Listener

use of org.eclipse.swt.widgets.Listener in project cubrid-manager by CUBRID.

the class RenameTableDialog method createDialogArea.

/**
	 * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 * @param parent The parent composite to contain the dialog area
	 * @return the dialog area control
	 */
protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    Label label1 = new Label(composite, SWT.LEFT);
    label1.setText(Messages.bind(Messages.renameNewTableName, tableOrView));
    GridData data = new GridData();
    data.widthHint = 120;
    data.horizontalSpan = 1;
    data.verticalSpan = 1;
    label1.setLayoutData(data);
    newTableText = new Text(composite, SWT.BORDER);
    data = new GridData();
    data.horizontalSpan = 2;
    data.verticalSpan = 1;
    data.grabExcessHorizontalSpace = true;
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    newTableText.setLayoutData(data);
    newTableText.setText(oldName);
    newTableText.selectAll();
    newTableText.setFocus();
    newTableText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setErrorMessage(null);
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            String newTable = newTableText.getText();
            if (isPhysical && !ValidateUtil.isValidIdentifier(newTable)) {
                setErrorMessage(Messages.bind(Messages.renameInvalidTableNameMSG, tableOrView, newTable));
                return;
            }
            if (-1 != existNameList.indexOf(newTable.toLowerCase(Locale.getDefault()))) {
                if (isTable) {
                    setErrorMessage(Messages.bind(Messages.errExistTable, newTable));
                } else {
                    setErrorMessage(Messages.bind(Messages.errExistView, newTable));
                }
                return;
            }
            getButton(IDialogConstants.OK_ID).setEnabled(true);
        }
    });
    newTableText.addListener(SWT.KeyDown, new Listener() {

        public void handleEvent(Event e) {
            if (e.type == SWT.KeyDown && e.character == SWT.CR) {
                /*For bug TOOLS-2698*/
                String newSchemaName = newTableText.getText().trim();
                if (StringUtil.isEqualNotIgnoreNull(oldName, newSchemaName)) {
                    buttonPressed(IDialogConstants.CANCEL_ID);
                } else {
                    buttonPressed(IDialogConstants.OK_ID);
                }
            }
        }
    });
    setTitle(Messages.bind(Messages.renameMSGTitle, tableOrView));
    setMessage(Messages.bind(Messages.renameDialogMSG, tableOrView));
    return parent;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Event(org.eclipse.swt.widgets.Event) Text(org.eclipse.swt.widgets.Text)

Example 35 with Listener

use of org.eclipse.swt.widgets.Listener in project cubrid-manager by CUBRID.

the class AddColumnDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    // new name
    Label label1 = new Label(composite, SWT.LEFT);
    label1.setText(Messages.lbAddColumnName);
    GridData data = new GridData();
    data.horizontalSpan = 1;
    data.verticalSpan = 1;
    label1.setLayoutData(data);
    newColumnText = new Text(composite, SWT.BORDER);
    data = new GridData();
    data.horizontalSpan = 2;
    data.verticalSpan = 1;
    data.grabExcessHorizontalSpace = true;
    data.verticalAlignment = GridData.FILL;
    data.horizontalAlignment = GridData.FILL;
    // data type
    Label labelType = new Label(composite, SWT.LEFT);
    labelType.setText(Messages.lbDataType);
    GridData data2 = new GridData();
    data2.horizontalSpan = 1;
    data2.verticalSpan = 1;
    labelType.setLayoutData(data2);
    dataTypeCombo = new Combo(composite, SWT.LEFT | SWT.READ_ONLY | SWT.BORDER);
    dataTypeCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, 100, -1));
    dataTypeCombo.setItems(this.listDataTypes());
    dataTypeCombo.setText("STRING");
    dataTypeValue = dataTypeCombo.getText();
    newColumnText.setLayoutData(data);
    newColumnText.setText(columnValue);
    newColumnText.selectAll();
    newColumnText.setFocus();
    newColumnText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            setErrorMessage(null);
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            String newcolumn = newColumnText.getText();
            if (!ValidateUtil.isValidIdentifier(newcolumn)) {
                setErrorMessage(Messages.bind(Messages.errInvalidColumnName, tableOrViewKey, newcolumn));
                return;
            }
            if (-1 != columnList.indexOf(newcolumn.toLowerCase(Locale.getDefault()))) {
                setErrorMessage(Messages.bind(Messages.errExistColumnName, newcolumn));
                return;
            }
            getButton(IDialogConstants.OK_ID).setEnabled(true);
        }
    });
    newColumnText.addListener(SWT.KeyDown, new Listener() {

        public void handleEvent(Event e) {
            if (e.type == SWT.KeyDown && e.character == SWT.CR) {
                /* For bug TOOLS-2698 */
                String newSchemaName = newColumnText.getText().trim();
                if (StringUtil.isEqualNotIgnoreNull(columnValue, newSchemaName)) {
                    buttonPressed(IDialogConstants.CANCEL_ID);
                } else {
                    buttonPressed(IDialogConstants.OK_ID);
                }
            }
        }
    });
    setTitle(Messages.bind(Messages.titleAddColumn, tableOrViewKey));
    setMessage(Messages.bind(Messages.titleAddColumn, tableOrViewKey));
    return parent;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Event(org.eclipse.swt.widgets.Event) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo)

Aggregations

Listener (org.eclipse.swt.widgets.Listener)876 Event (org.eclipse.swt.widgets.Event)841 SelectionEvent (org.eclipse.swt.events.SelectionEvent)538 Button (org.eclipse.swt.widgets.Button)480 Label (org.eclipse.swt.widgets.Label)452 Text (org.eclipse.swt.widgets.Text)392 ModifyListener (org.eclipse.swt.events.ModifyListener)385 Shell (org.eclipse.swt.widgets.Shell)385 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)382 ModifyEvent (org.eclipse.swt.events.ModifyEvent)376 FormData (org.eclipse.swt.layout.FormData)356 ShellEvent (org.eclipse.swt.events.ShellEvent)354 FormAttachment (org.eclipse.swt.layout.FormAttachment)353 FormLayout (org.eclipse.swt.layout.FormLayout)353 Display (org.eclipse.swt.widgets.Display)342 ShellAdapter (org.eclipse.swt.events.ShellAdapter)325 Composite (org.eclipse.swt.widgets.Composite)295 GridData (org.eclipse.swt.layout.GridData)229 GridLayout (org.eclipse.swt.layout.GridLayout)195 TextVar (org.pentaho.di.ui.core.widget.TextVar)184