Search in sources :

Example 6 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tdi-studio-se by Talend.

the class InsertNewColumnCommand method validSourceNodeName.

private String validSourceNodeName(final List<? extends AbstractNode> validationList, TreeNode sourceNode) {
    String sourceName = sourceNode.getName();
    boolean isValidate = MetadataToolHelper.isValidColumnName(sourceName);
    boolean fixing = false;
    if (!isValidate) {
        if (sourceName.contains(":")) {
            //$NON-NLS-1$
            if (sourceNode.eContainer() instanceof TreeNode) {
                TreeNode parent = (TreeNode) sourceNode.eContainer();
                for (TreeNode child : parent.getChildren()) {
                    if (child.getNodeType() == NodeType.NAME_SPACE) {
                        if (sourceName.startsWith(child.getName() + ":")) {
                            //$NON-NLS-1$
                            sourceName = sourceName.substring(child.getName().length() + 1, sourceName.length());
                            fixing = true;
                        }
                    }
                }
                if (!fixing) {
                    //$NON-NLS-1$
                    sourceName = sourceName.substring(sourceName.indexOf(":"), sourceName.length());
                    fixing = true;
                }
            }
        }
        if (!fixing || !MetadataToolHelper.isValidColumnName(sourceName)) {
            IInputValidator validataor = new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    return XmlMapUtil.isValidColumnName(validationList, newText);
                }
            };
            InputDialog dialog = new InputDialog(null, Messages.getString("InsertNewColumnCommand_createNew"), Messages.getString("InsertNewColumnCommand_message"), sourceName, //$NON-NLS-1$ //$NON-NLS-2$
            validataor);
            int open = dialog.open();
            if (open == Window.CANCEL) {
                return null;
            } else {
                sourceName = dialog.getValue();
            }
        }
    }
    return sourceName;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) OutputTreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.OutputTreeNode) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 7 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project ACS by ACS-Community.

the class AlarmsView method createViewWidgets.

private void createViewWidgets(Composite parent) {
    Listener hoverTree = new Listener() {

        public void handleEvent(Event event) {
            Point coords = new Point(event.x, event.y);
            TreeItem it = _tree.getItem(coords);
            String tooltip = "";
            if (it == null) {
                _tree.setToolTipText(tooltip);
                return;
            }
            NodeType type = (NodeType) it.getData();
            switch(type) {
                case FAULT_FAMILY:
                    {
                        tooltip = _alarmManager.getFaultFamily(it.getText()).getName();
                        break;
                    }
                case FAULT_CODE_DATA:
                    {
                        tooltip = _alarmManager.getFaultCode(it.getParentItem().getParentItem().getText(), new Integer(it.getText())).getProblemDescription();
                        break;
                    }
                case FAULT_MEMBER_DATA:
                    {
                        tooltip = _alarmManager.getFaultMember(it.getParentItem().getParentItem().getText(), it.getText()).getName();
                        break;
                    }
            }
            _tree.setToolTipText(tooltip);
        }
    };
    _deleteElement = new Listener() {

        public void handleEvent(Event event) {
            boolean choice = MessageDialog.openQuestion(AlarmsView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this element");
            if (choice == true) {
                TreeItem sel = null;
                if (_tree.getSelection() == null || _tree.getSelection().length == 0)
                    return;
                NodeType type = (NodeType) _tree.getSelection()[0].getData();
                if (type == NodeType.FAULT_CODE_LIST || type == NodeType.FAULT_MEMBER_LIST)
                    return;
                String alarm = _tree.getSelection()[0].getText();
                try {
                    if (type == NodeType.FAULT_FAMILY)
                        _alarmManager.deleteFaultFamily(_alarmManager.getFaultFamily(alarm));
                    else if (type == NodeType.FAULT_CODE_DATA) {
                        String ff = _tree.getSelection()[0].getParentItem().getParentItem().getText();
                        _alarmManager.deleteFaultCode(_alarmManager.getFaultFamily(ff), _alarmManager.getFaultCode(ff, new Integer(alarm).intValue()));
                    } else if (type == NodeType.FAULT_MEMBER_DATA) {
                        String ff = _tree.getSelection()[0].getParentItem().getParentItem().getText();
                        _alarmManager.deleteFaultMember(_alarmManager.getFaultFamily(ff), _alarmManager.getFaultMember(ff, alarm));
                    } else if (type == NodeType.FAULT_MEMBER_DEFAULT) {
                        String ff = _tree.getSelection()[0].getParentItem().getParentItem().getText();
                        _alarmManager.setFaultMemberDefault(_alarmManager.getFaultFamily(ff), null);
                    }
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                if (type != NodeType.FAULT_FAMILY) {
                    sel = _tree.getSelection()[0].getParentItem();
                    TreeItem tff = sel.getParentItem();
                    FaultFamily fft = _alarmManager.getFaultFamily(tff.getText());
                    if (fft.getFaultCodeCount() == 0 || (fft.getFaultMemberCount() == 0 && fft.getFaultMemberDefault() == null)) {
                        sel.setForeground(new Color(sel.getDisplay(), 255, 0, 0));
                        tff.setForeground(new Color(tff.getDisplay(), 255, 0, 0));
                    } else {
                        sel.setForeground(new Color(sel.getDisplay(), 0, 0, 0));
                        tff.setForeground(new Color(tff.getDisplay(), 0, 0, 0));
                    }
                    _tree.getSelection()[0].dispose();
                    _tree.setSelection(sel);
                    Event e = new Event();
                    _tree.notifyListeners(SWT.Selection, e);
                } else {
                    _tree.getSelection()[0].dispose();
                    if (_tree.getItemCount() > 0)
                        _tree.setSelection(_tree.getItems()[0]);
                    Event e = new Event();
                    _tree.notifyListeners(SWT.Selection, e);
                }
            }
        }
    };
    _addFaultMember = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            TreeItem tmp2 = null;
            while (tmp != null) {
                tmp2 = tmp;
                tmp = tmp.getParentItem();
            }
            String ff = tmp2.getText();
            InputDialog dialog = new InputDialog(AlarmsView.this.getViewSite().getShell(), "New Fault Member", "Enter the Fault Member 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) {
                FaultMember newFaultMember = new FaultMember();
                newFaultMember.setName(dialog.getValue());
                try {
                    _alarmManager.addFaultMember(_alarmManager.getFaultFamily(ff), newFaultMember);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                sortFaultFamilyList();
                selectElementFromTree(ff, dialog.getValue(), null);
            }
        }
    };
    _addFaultMemberDefault = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            TreeItem tmp2 = null;
            while (tmp != null) {
                tmp2 = tmp;
                tmp = tmp.getParentItem();
            }
            String ff = tmp2.getText();
            FaultMemberDefault newFaultMemberDefault = new FaultMemberDefault();
            try {
                _alarmManager.setFaultMemberDefault(_alarmManager.getFaultFamily(ff), newFaultMemberDefault);
            } catch (IllegalOperationException e) {
                ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Default Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                error.setBlockOnOpen(true);
                error.open();
                return;
            } catch (NullPointerException e) {
                ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Default Fault Member", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                error.setBlockOnOpen(true);
                error.open();
                return;
            }
            sortFaultFamilyList();
            selectElementFromTree(ff, "Default Member", null);
        }
    };
    _addFaultCode = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            TreeItem tmp2 = null;
            while (tmp != null) {
                tmp2 = tmp;
                tmp = tmp.getParentItem();
            }
            String ff = tmp2.getText();
            InputDialog dialog = new InputDialog(AlarmsView.this.getViewSite().getShell(), "New Fault Code", "Enter the Fault Code Value", null, new IInputValidator() {

                public String isValid(String newText) {
                    if (newText.trim().compareTo("") == 0)
                        return "The value is empty";
                    try {
                        new Integer(newText);
                    } catch (NumberFormatException e) {
                        return "The value is not a number";
                    }
                    return null;
                }
            });
            dialog.setBlockOnOpen(true);
            dialog.open();
            int returnCode = dialog.getReturnCode();
            if (returnCode == InputDialog.OK) {
                FaultCode newFaultCode = new FaultCode();
                newFaultCode.setValue(new Integer(dialog.getValue()).intValue());
                try {
                    _alarmManager.addFaultCode(_alarmManager.getFaultFamily(ff), newFaultCode);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Code", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Fault Code", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                sortFaultFamilyList();
                selectElementFromTree(ff, null, dialog.getValue());
            }
        }
    };
    _addFaultFamily = new Listener() {

        public void handleEvent(Event event) {
            InputDialog dialog = new InputDialog(AlarmsView.this.getViewSite().getShell(), "New Alarm", "Enter the Fault Family 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) {
                FaultFamily newAlarm = new FaultFamily();
                newAlarm.setName(dialog.getValue());
                try {
                    _alarmManager.addFaultFamily(newAlarm);
                } catch (IllegalOperationException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Alarm", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                } catch (NullPointerException e) {
                    ErrorDialog error = new ErrorDialog(AlarmsView.this.getViewSite().getShell(), "Cannot add the new Alarm", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
                    error.setBlockOnOpen(true);
                    error.open();
                    return;
                }
                sortFaultFamilyList();
                selectElementFromTree(dialog.getValue(), null, null);
            }
        }
    };
    _sash = new SashForm(parent, SWT.NONE);
    _sash.setLayout(new FillLayout());
    _alarmsComp = new Composite(_sash, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    _alarmsComp.setLayout(layout);
    _treeGroup = new Group(_alarmsComp, SWT.SHADOW_ETCHED_IN);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    _treeGroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 1;
    _treeGroup.setLayout(gl);
    _treeGroup.setText("Fault Family List");
    /* The tree used to list the FF, FM and FCs */
    _tree = new Tree(_treeGroup, SWT.VIRTUAL | SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    _tree.setLayoutData(gd);
    //Menu treePopUp = new Menu(parent, SWT.POP_UP);
    Menu treePopUp = new Menu(parent);
    _tree.setMenu(treePopUp);
    treePopUp.addListener(SWT.Show, new Listener() {

        public void handleEvent(Event e) {
            //Point point = new Point(e.x, e.y);
            //TreeItem sel = _tree.getItem(point);
            TreeItem[] sel = _tree.getSelection();
            Menu treePopUp = _tree.getMenu();
            MenuItem[] items = treePopUp.getItems();
            for (int i = 0; i < items.length; i++) items[i].dispose();
            MenuItem mitem;
            if (sel == null || sel.length == 0) {
                mitem = new MenuItem(treePopUp, SWT.PUSH);
                mitem.setText("Add Fault Family");
                mitem.addListener(SWT.Selection, _addFaultFamily);
                return;
            }
            NodeType type = (NodeType) sel[0].getData();
            switch(type) {
                case FAULT_FAMILY:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Family");
                    mitem.addListener(SWT.Selection, _addFaultFamily);
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Fault Family");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                case FAULT_CODE_LIST:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Code");
                    mitem.addListener(SWT.Selection, _addFaultCode);
                    break;
                case FAULT_CODE_DATA:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Code");
                    mitem.addListener(SWT.Selection, _addFaultCode);
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Fault Code");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                case FAULT_MEMBER_LIST:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Member");
                    mitem.addListener(SWT.Selection, _addFaultMember);
                    if (_alarmManager.getFaultFamily(sel[0].getParentItem().getText()).getFaultMemberDefault() == null) {
                        mitem = new MenuItem(treePopUp, SWT.PUSH);
                        mitem.setText("Add Default Fault Member");
                        mitem.addListener(SWT.Selection, _addFaultMemberDefault);
                    }
                    break;
                case FAULT_MEMBER_DATA:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Add Fault Member");
                    mitem.addListener(SWT.Selection, _addFaultMember);
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Fault Member");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                case FAULT_MEMBER_DEFAULT:
                    mitem = new MenuItem(treePopUp, SWT.PUSH);
                    mitem.setText("Delete Default Fault Member");
                    mitem.addListener(SWT.Selection, _deleteElement);
                    break;
                default:
                    for (int i = 0; i < items.length; i++) items[i].dispose();
                    break;
            }
        }
    });
    _tree.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            TreeItem[] tmp = ((Tree) e.widget).getSelection();
            if (tmp == null || tmp.length == 0) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                return;
            }
            TreeItem item = tmp[0];
            NodeType type = (NodeType) item.getData();
            /* Delete the label the first time we select something */
            Control c = _compInitial.getChildren()[0];
            if (c instanceof Label) {
                c.dispose();
                _compInitial.layout();
                c = _compInitial.getChildren()[0];
            }
            if (type == NodeType.FAULT_FAMILY) {
                _FFgroup.setVisible(true);
                ((GridData) _FFgroup.getLayoutData()).exclude = false;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                //_FFgroup.moveAbove(c);
                fillFFWidgets(item.getText());
            } else if (type == NodeType.FAULT_CODE_LIST) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(true);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = false;
                fillFCFMWidgets();
            } else if (type == NodeType.FAULT_CODE_DATA) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(true);
                ((GridData) _FCgroup.getLayoutData()).exclude = false;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                //_FCgroup.moveAbove(c);
                fillFCWidgets(Integer.parseInt(item.getText()), item.getParentItem().getParentItem().getText());
            } else if (type == NodeType.FAULT_MEMBER_LIST) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(true);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = false;
                fillFCFMWidgets();
            } else if (type == NodeType.FAULT_MEMBER_DATA) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(true);
                ((GridData) _FMgroup.getLayoutData()).exclude = false;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(false);
                ((GridData) _FMDgroup.getLayoutData()).exclude = true;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                //_FMgroup.moveAbove(c);
                fillFMWidgets(item.getText(), item.getParentItem().getParentItem().getText());
            } else if (type == NodeType.FAULT_MEMBER_DEFAULT) {
                _FFgroup.setVisible(false);
                ((GridData) _FFgroup.getLayoutData()).exclude = true;
                _FMgroup.setVisible(false);
                ((GridData) _FMgroup.getLayoutData()).exclude = true;
                _FCgroup.setVisible(false);
                ((GridData) _FCgroup.getLayoutData()).exclude = true;
                _FMDgroup.setVisible(true);
                ((GridData) _FMDgroup.getLayoutData()).exclude = false;
                _FCFMgroup.setVisible(false);
                ((GridData) _FCFMgroup.getLayoutData()).exclude = true;
                fillFMDWidgets(item.getParentItem().getParentItem().getText());
            }
            _compInitial.layout();
        }
    });
    _tree.addListener(SWT.MouseHover, hoverTree);
    _alarmsButtonsComp = new Composite(_alarmsComp, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    _alarmsButtonsComp.setLayout(layout);
    _addAlarmButton = new Button(_alarmsButtonsComp, SWT.None);
    _addAlarmButton.setText("Add");
    _addAlarmButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
    _deleteAlarmButton = new Button(_alarmsButtonsComp, SWT.None);
    _deleteAlarmButton.setText("Delete");
    _deleteAlarmButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE));
    _addAlarmButton.addListener(SWT.Selection, _addFaultFamily);
    _deleteAlarmButton.addListener(SWT.Selection, _deleteElement);
    /* Top widget of the right side */
    _compInitial = new Composite(_sash, SWT.SHADOW_ETCHED_IN);
    _compInitial.setLayout(new GridLayout());
    new Label(_compInitial, SWT.NONE).setText("Select an element");
    /* FF/FM/FC Details */
    createFFWidgets();
    createFCWidgets();
    createFMWidgets();
    createFMDWidgets();
    createFCFMWidgets();
    /* At the beginning we only show a label */
    _FFgroup.setVisible(false);
    _FCgroup.setVisible(false);
    _FMgroup.setVisible(false);
    _FMDgroup.setVisible(false);
    _FCFMgroup.setVisible(false);
    _sash.setWeights(new int[] { 3, 5 });
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) TreeItem(org.eclipse.swt.widgets.TreeItem) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) Menu(org.eclipse.swt.widgets.Menu) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) FaultMember(alma.acs.alarmsystem.generated.FaultMember) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) FillLayout(org.eclipse.swt.layout.FillLayout) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) SashForm(org.eclipse.swt.custom.SashForm) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 8 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator 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 9 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project cubrid-manager by CUBRID.

the class ImportTypePage method createControl.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FormLayout());
    setControl(container);
    Composite leftComposite = new Composite(container, SWT.NONE);
    FormData leftData = new FormData();
    leftData.top = new FormAttachment(0, 5);
    leftData.bottom = new FormAttachment(100, 0);
    leftData.left = new FormAttachment(0, 5);
    leftData.right = new FormAttachment(50, 0);
    GridLayout leftLayout = new GridLayout();
    leftLayout.verticalSpacing = 0;
    leftComposite.setLayout(leftLayout);
    leftComposite.setLayoutData(leftData);
    Composite rightComposite = new Composite(container, SWT.NONE);
    FormData rightData = new FormData();
    rightData.top = new FormAttachment(0, 5);
    rightData.bottom = new FormAttachment(100, 0);
    rightData.left = new FormAttachment(50, 0);
    rightData.right = new FormAttachment(100, -5);
    GridLayout rightLayout = new GridLayout();
    rightLayout.verticalSpacing = 0;
    rightComposite.setLayout(rightLayout);
    rightComposite.setLayoutData(rightData);
    sqlButton = new Button(leftComposite, SWT.RADIO);
    sqlButton.setText(Messages.btnImportSQL);
    sqlButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    sqlButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            excelButton.setSelection(!sqlButton.getSelection());
            txtButton.setSelection(!sqlButton.getSelection());
            historyButton.setSelection(!sqlButton.getSelection());
            historyCombo.setEnabled(false);
            deleteButton.setEnabled(false);
            renameButton.setEnabled(false);
            validate();
        }
    });
    Group sqlLabelGroup = new Group(leftComposite, SWT.None);
    sqlLabelGroup.setLayoutData(CommonUITool.createGridData(1, 1, 370, 80));
    sqlLabelGroup.setLayout(new FillLayout());
    Label sqlLabel = new Label(sqlLabelGroup, SWT.WRAP);
    sqlLabel.setText(Messages.lblImportSQL);
    Label separator1Label = new Label(leftComposite, SWT.None);
    separator1Label.setLayoutData(CommonUITool.createGridData(1, 1, 0, 15));
    {
        Label separator4Label = new Label(leftComposite, SWT.None);
        separator4Label.setLayoutData(CommonUITool.createGridData(1, 1, 0, 15));
        excelButton = new Button(leftComposite, SWT.RADIO);
        excelButton.setText(Messages.btnImportExcel);
        excelButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        excelButton.addSelectionListener(new SelectionListener() {

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

            public void widgetSelected(SelectionEvent e) {
                sqlButton.setSelection(!excelButton.getSelection());
                txtButton.setSelection(!excelButton.getSelection());
                historyButton.setSelection(!excelButton.getSelection());
                historyCombo.setEnabled(false);
                deleteButton.setEnabled(false);
                renameButton.setEnabled(false);
                validate();
            }
        });
        Group excelLabelGroup = new Group(leftComposite, SWT.None);
        excelLabelGroup.setLayoutData(CommonUITool.createGridData(1, 1, 370, 80));
        excelLabelGroup.setLayout(new FillLayout());
        Label excelLabel = new Label(excelLabelGroup, SWT.WRAP);
        excelLabel.setText(Messages.lblImportExcel);
        Label separator2Label = new Label(leftComposite, SWT.None);
        separator2Label.setLayoutData(CommonUITool.createGridData(1, 1, 0, 15));
    }
    // Txt
    {
        txtButton = new Button(rightComposite, SWT.RADIO);
        txtButton.setText(Messages.btnImportTxt);
        txtButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        txtButton.addSelectionListener(new SelectionListener() {

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

            public void widgetSelected(SelectionEvent e) {
                sqlButton.setSelection(!txtButton.getSelection());
                excelButton.setSelection(!txtButton.getSelection());
                historyButton.setSelection(!txtButton.getSelection());
                historyCombo.setEnabled(false);
                deleteButton.setEnabled(false);
                renameButton.setEnabled(false);
                validate();
            }
        });
        Group txtLabelGroup = new Group(rightComposite, SWT.None);
        txtLabelGroup.setLayoutData(CommonUITool.createGridData(1, 1, 370, 80));
        txtLabelGroup.setLayout(new FillLayout());
        Label txtLabel = new Label(txtLabelGroup, SWT.WRAP);
        txtLabel.setText(Messages.lblImportTxt);
        Label separator3Label = new Label(rightComposite, SWT.None);
        separator3Label.setLayoutData(CommonUITool.createGridData(1, 1, 0, 15));
    }
    // History Button
    {
        Label separator4Label = new Label(rightComposite, SWT.None);
        separator4Label.setLayoutData(CommonUITool.createGridData(1, 1, 0, 15));
        historyButton = new Button(rightComposite, SWT.RADIO);
        historyButton.setText(Messages.btnImportHistory);
        historyButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        historyButton.addSelectionListener(new SelectionListener() {

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

            public void widgetSelected(SelectionEvent e) {
                sqlButton.setSelection(!historyButton.getSelection());
                excelButton.setSelection(!historyButton.getSelection());
                txtButton.setSelection(!historyButton.getSelection());
                historyCombo.setEnabled(historyButton.getSelection());
                if (historyButton.getSelection()) {
                    loadHistory();
                }
                validate();
            }
        });
        Group historyLabelGroup = new Group(rightComposite, SWT.None);
        historyLabelGroup.setLayoutData(CommonUITool.createGridData(1, 1, 370, 80));
        historyLabelGroup.setLayout(new FillLayout());
        Label historyLabel = new Label(historyLabelGroup, SWT.WRAP);
        historyLabel.setText(Messages.lblImportHistory);
        Composite historyComposite = new Composite(rightComposite, SWT.None);
        historyComposite.setLayout(new GridLayout(3, false));
        historyComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
        historyCombo = new Combo(historyComposite, SWT.READ_ONLY);
        historyCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
        historyCombo.setEnabled(false);
        historyCombo.addSelectionListener(new SelectionListener() {

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

            public void widgetDefaultSelected(SelectionEvent e) {
                validate();
            }
        });
        loadHistory();
        final ImportConfigManager configManager = ImportConfigManager.getInstance();
        renameButton = new Button(historyComposite, SWT.None);
        renameButton.setText(Messages.btnRenameHistory);
        renameButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        renameButton.setEnabled(false);
        renameButton.addSelectionListener(new SelectionListener() {

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

            public void widgetSelected(SelectionEvent e) {
                String historyName = historyCombo.getText();
                if (historyName == null || historyName.trim().length() == 0) {
                    return;
                }
                ImportConfig model = configManager.getConfig(historyName);
                if (model == null) {
                    return;
                }
                InputDialog dialog = new InputDialog(getShell(), Messages.titleRenameDialog, Messages.descRenameDialog, historyName, new IInputValidator() {

                    public String isValid(String newText) {
                        if (newText == null || newText.trim().length() == 0) {
                            return Messages.msgRenamePleaseInputNewName;
                        }
                        if (configManager.getConfig(newText) != null) {
                            return Messages.msgRenameAlreadyExists;
                        }
                        return null;
                    }
                });
                if (dialog.open() == IDialogConstants.OK_ID) {
                    String newName = dialog.getValue();
                    model.setName(newName);
                    configManager.saveConfigs();
                    historyCombo.remove(historyName);
                    historyCombo.add(newName);
                    historyCombo.setText(newName);
                }
            }
        });
        deleteButton = new Button(historyComposite, SWT.None);
        deleteButton.setText(Messages.btnDeleteHistory);
        deleteButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        deleteButton.setEnabled(false);
        deleteButton.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                if (!CommonUITool.openConfirmBox(Messages.confirmDeleteImportHistory)) {
                    return;
                }
                boolean result = ImportConfigManager.getInstance().removeConfig(historyCombo.getText());
                if (result) {
                    historyCombo.remove(historyCombo.getText());
                    validate();
                }
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                widgetDefaultSelected(e);
            }
        });
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Group(org.eclipse.swt.widgets.Group) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) FillLayout(org.eclipse.swt.layout.FillLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) SelectionListener(org.eclipse.swt.events.SelectionListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 10 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project cubrid-manager by CUBRID.

the class ExportTypePage method createControl.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FormLayout());
    setTitle(Messages.titleExportStep1);
    setDescription(Messages.exportWizardTypeDescription);
    setControl(container);
    Composite leftComposite = new Composite(container, SWT.NONE);
    FormData leftData = new FormData();
    leftData.top = new FormAttachment(0, 5);
    leftData.bottom = new FormAttachment(100, 0);
    leftData.left = new FormAttachment(0, 5);
    leftData.right = new FormAttachment(50, 0);
    GridLayout leftLayout = new GridLayout();
    leftLayout.verticalSpacing = 0;
    leftComposite.setLayout(leftLayout);
    leftComposite.setLayoutData(leftData);
    Composite rightComposite = new Composite(container, SWT.NONE);
    FormData rightData = new FormData();
    rightData.top = new FormAttachment(0, 5);
    rightData.bottom = new FormAttachment(100, 0);
    rightData.left = new FormAttachment(50, 0);
    rightData.right = new FormAttachment(100, -5);
    GridLayout rightLayout = new GridLayout();
    rightLayout.verticalSpacing = 0;
    rightComposite.setLayout(rightLayout);
    rightComposite.setLayoutData(rightData);
    fileButton = new Button(leftComposite, SWT.RADIO);
    fileButton.setText(Messages.exportWizardType1);
    fileButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    fileButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            historyButton.setSelection(!fileButton.getSelection());
            loadDBButton.setSelection(!fileButton.getSelection());
            changeHistoryCompStatus();
        }
    });
    Group fileLabelGroup = new Group(leftComposite, SWT.None);
    fileLabelGroup.setLayoutData(CommonUITool.createGridData(1, 1, 370, 100));
    fileLabelGroup.setLayout(new FillLayout());
    Label fileLabel = new Label(fileLabelGroup, SWT.WRAP);
    fileLabel.setText(Messages.exportWizardTypeDescription1);
    Label separator1Label = new Label(leftComposite, SWT.None);
    separator1Label.setLayoutData(CommonUITool.createGridData(1, 1, 0, 20));
    historyButton = new Button(leftComposite, SWT.RADIO);
    historyButton.setText(Messages.exportWizardType3);
    historyButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    historyButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            fileButton.setSelection(!historyButton.getSelection());
            loadDBButton.setSelection(!historyButton.getSelection());
            changeHistoryCompStatus();
            setPageComplete(true);
        }
    });
    Group historyLabelGroup = new Group(leftComposite, SWT.None);
    historyLabelGroup.setLayoutData(CommonUITool.createGridData(1, 1, 370, 100));
    historyLabelGroup.setLayout(new FillLayout());
    Label historyLabel = new Label(historyLabelGroup, SWT.WRAP);
    historyLabel.setText(Messages.exportWizardTypeDescription3);
    Composite historyComposite = new Composite(leftComposite, SWT.None);
    historyComposite.setLayout(new GridLayout(3, false));
    historyComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    historyCombo = new Combo(historyComposite, SWT.READ_ONLY);
    historyCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    historyCombo.setEnabled(false);
    historyCombo.addListener(SWT.Modify, new Listener() {

        public void handleEvent(Event event) {
            ExportConfig historyExportConfigModel = ExportConfigManager.getInstance().getConfig(historyCombo.getText());
            if (historyExportConfigModel != null) {
                ExportConfig exportConfigModel = cloneExportConfigModel(historyExportConfigModel);
                getExportDataWizardWizard().setConfigModel(exportConfigModel);
            }
            firePageStatusChanged(new StatusInfo(IStatus.INFO, ""));
            setPageComplete(true);
        }
    });
    final ExportConfigManager configManager = ExportConfigManager.getInstance();
    List<ExportConfig> configList = configManager.getAllConfigs();
    for (ExportConfig model : configList) {
        historyCombo.add(model.getName());
    }
    renameButton = new Button(historyComposite, SWT.None);
    renameButton.setText(Messages.btnRenameHistory);
    renameButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    renameButton.setEnabled(false);
    renameButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            String historyName = historyCombo.getText();
            if (historyName == null || historyName.trim().length() == 0) {
                return;
            }
            ExportConfig model = configManager.getConfig(historyName);
            if (model == null) {
                return;
            }
            InputDialog dialog = new InputDialog(getShell(), Messages.titleExportRenameDialog, Messages.descExportRenameDialog, historyName, new IInputValidator() {

                public String isValid(String newText) {
                    if (newText == null || newText.trim().length() == 0) {
                        return Messages.msgExportRenamePleaseInputNewName;
                    }
                    if (configManager.getConfig(newText) != null) {
                        return Messages.msgExportRenameAlreadyExists;
                    }
                    return null;
                }
            });
            if (dialog.open() == IDialogConstants.OK_ID) {
                String newName = dialog.getValue();
                model.setName(newName);
                configManager.saveConfigs();
                historyCombo.remove(historyName);
                historyCombo.add(newName);
                historyCombo.setText(newName);
            }
        }
    });
    deleteButton = new Button(historyComposite, SWT.None);
    deleteButton.setText(Messages.btnDeleteHistory);
    deleteButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            if (!CommonUITool.openConfirmBox(Messages.confirmDeleteExportHistory)) {
                return;
            }
            String historyName = historyCombo.getText();
            if (historyName == null || historyName.trim().length() == 0) {
                return;
            }
            configManager.removeConfig(configManager.getConfig(historyName));
            configManager.saveConfigs();
            historyCombo.remove(historyName);
        }
    });
    loadDBButton = new Button(rightComposite, SWT.RADIO);
    loadDBButton.setText(Messages.exportWizardType2);
    loadDBButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    loadDBButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            fileButton.setSelection(!loadDBButton.getSelection());
            historyButton.setSelection(!loadDBButton.getSelection());
            changeHistoryCompStatus();
            historyButton.setSelection(false);
            fileButton.setSelection(false);
        }
    });
    Group loadDBLabelGroup = new Group(rightComposite, SWT.None);
    loadDBLabelGroup.setLayoutData(CommonUITool.createGridData(1, 1, 370, 100));
    loadDBLabelGroup.setLayout(new FillLayout());
    Label loadDBLabel = new Label(loadDBLabelGroup, SWT.WRAP);
    loadDBLabel.setText(Messages.exportWizardTypeDescription2);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) 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) Combo(org.eclipse.swt.widgets.Combo) FillLayout(org.eclipse.swt.layout.FillLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) StatusInfo(com.cubrid.common.ui.spi.StatusInfo) ExportConfig(com.cubrid.common.ui.cubrid.table.progress.ExportConfig) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Event(org.eclipse.swt.widgets.Event) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) PageChangingEvent(org.eclipse.jface.dialogs.PageChangingEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FormAttachment(org.eclipse.swt.layout.FormAttachment) SelectionListener(org.eclipse.swt.events.SelectionListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)16 InputDialog (org.eclipse.jface.dialogs.InputDialog)12 IStatus (org.eclipse.core.runtime.IStatus)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 FillLayout (org.eclipse.swt.layout.FillLayout)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Button (org.eclipse.swt.widgets.Button)5 Composite (org.eclipse.swt.widgets.Composite)5 Event (org.eclipse.swt.widgets.Event)5 Group (org.eclipse.swt.widgets.Group)5 Label (org.eclipse.swt.widgets.Label)5 ArrayList (java.util.ArrayList)4 Listener (org.eclipse.swt.widgets.Listener)4 IllegalOperationException (cl.utfsm.acs.acg.core.IllegalOperationException)3 Status (org.eclipse.core.runtime.Status)3 ErrorDialog (org.eclipse.jface.dialogs.ErrorDialog)3 SashForm (org.eclipse.swt.custom.SashForm)3 List (java.util.List)2 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)2