Search in sources :

Example 6 with ICellEditorValidator

use of org.eclipse.jface.viewers.ICellEditorValidator in project cubrid-manager by CUBRID.

the class MultiDBQueryComposite method initialize.

/**
	 * Create the SQL history composite
	 */
public void initialize() {
    Composite toolBarComposite = new Composite(this, SWT.NONE);
    GridLayout gridLayout = new GridLayout(2, false);
    gridLayout.verticalSpacing = 0;
    gridLayout.horizontalSpacing = 10;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    toolBarComposite.setLayout(gridLayout);
    toolBarComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ToolBar toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
    ToolItem refreshToolItem = new ToolItem(toolBar, SWT.PUSH);
    refreshToolItem.setText(Messages.lblItemRefreshMulti);
    refreshToolItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_refresh.png"));
    refreshToolItem.setToolTipText(Messages.refresh);
    refreshToolItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            //refresh may set tree to group type or not
            //so mark the select db then set it to checked after set input
            //				Object[] checkedObject = ctv.getCheckedElements();
            setInput();
        //				for (Object o : checkedObject) {
        //					if (o instanceof CubridDatabase) {
        //						ctv.setChecked(o, true);
        //					}
        //				}
        //				refresh(editor.getSelectedDatabase());
        }
    });
    runItem = new ToolItem(toolBar, SWT.PUSH);
    runItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_run.png"));
    runItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_run_disabled.png"));
    runItem.setText(Messages.lblItemRunMulti);
    runItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            editor.runMultiQuery();
        }
    });
    Label lblNotice = new Label(toolBarComposite, SWT.None);
    lblNotice.setText(Messages.qedit_multiDBQueryComp_noticeToolbarMsg);
    lblNotice.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false));
    // create the query result tab folder
    multiDBQueryCompTabFolder = new CTabFolder(this, SWT.BOTTOM);
    multiDBQueryCompTabFolder.setSimple(false);
    multiDBQueryCompTabFolder.setUnselectedImageVisible(true);
    multiDBQueryCompTabFolder.setUnselectedCloseVisible(true);
    multiDBQueryCompTabFolder.setSelectionBackground(CombinedQueryEditorComposite.BACK_COLOR);
    multiDBQueryCompTabFolder.setSelectionForeground(ResourceManager.getColor(SWT.COLOR_BLACK));
    multiDBQueryCompTabFolder.setLayout(new GridLayout(1, true));
    multiDBQueryCompTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
    //TabContextMenuManager tabContextMenuManager = new TabContextMenuManager(multiDBQueryCompTabFolder);
    //tabContextMenuManager.createContextMenu();
    multiDBQueryCompTabItem = new CTabItem(resultTabFolder, SWT.NONE);
    multiDBQueryCompTabItem.setText(Messages.qedit_multiDBQueryComp_folder);
    multiDBQueryCompTabItem.setControl(this);
    multiDBQueryCompTabItem.setShowClose(false);
    SashForm bottomSash = new SashForm(multiDBQueryCompTabFolder, SWT.VERTICAL);
    bottomSash.SASH_WIDTH = SASH_WIDTH;
    bottomSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    SashForm tailSash = new SashForm(bottomSash, SWT.HORIZONTAL);
    tailSash.SASH_WIDTH = SASH_WIDTH;
    tailSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    Composite treeComp = new Composite(tailSash, SWT.NONE);
    {
        treeComp.setLayoutData(new GridData(GridData.FILL_BOTH));
        treeComp.setLayout(new GridLayout());
    }
    ctv = new ContainerCheckedTreeViewer(treeComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    ctv.getControl().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    ctv.setContentProvider(new MultiDBQueryTreeContentProvider());
    ctv.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            if (lastSelectedTime != 0 && lastSelectedTime > System.currentTimeMillis()) {
                ctv.setChecked(event.getElement(), true);
                return;
            }
            ctv.setChecked(event.getElement(), false);
            lastSelectedTime = System.currentTimeMillis() + 100;
            if (getQueryDatabaseList().size() > 0 && editor.getAllQueries().trim().length() != 0) {
                editor.setMultiQueryRunItemStatus(true);
            } else if (getQueryDatabaseList().size() == 0) {
                editor.setMultiQueryRunItemStatus(false);
            }
            //if (!event.getChecked()) {
            selectedNodes.remove(event.getElement());
            if (event.getElement() instanceof CubridDatabase) {
                CubridDatabase database = (CubridDatabase) event.getElement();
                if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                    //ctv.setChecked(event.getElement(), false);
                    selectedNodes.remove(database);
                } else {
                    if (database.getData(INDEXKEY) == null) {
                        database.setData(INDEXKEY, String.valueOf(databaseIndex++));
                    }
                }
            } else if (event.getElement() instanceof CubridServer) {
                CubridServer serverNode = (CubridServer) event.getElement();
                for (ICubridNode dbFolderNode : serverNode.getChildren()) {
                    for (ICubridNode dbNode : dbFolderNode.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                //ctv.setChecked(dbNode, false);
                                selectedNodes.remove(database);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, true);
                            }
                        }
                    }
                    //only has one db folder  so first time break it
                    break;
                }
            } else if (event.getElement() instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) event.getElement();
                if (node.getType().equals(NodeType.DATABASE_FOLDER)) {
                    for (ICubridNode dbNode : node.getChildren()) {
                        if (dbNode instanceof CubridDatabase) {
                            CubridDatabase database = (CubridDatabase) dbNode;
                            if (database.getRunningType() == DbRunningType.STANDALONE || !database.isLogined()) {
                                ctv.setChecked(dbNode, false);
                            } else if (ctv.getChecked(dbNode)) {
                                ctv.setChecked(dbNode, true);
                                if (dbNode.getData(INDEXKEY) == null) {
                                    dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
                                }
                            } else {
                                ctv.setChecked(dbNode, false);
                            }
                        }
                    }
                }
            //					else if (node.getType().equals(NodeType.GROUP)) {
            //						for (ICubridNode childNode : node.getChildren()) {
            //							//CQB tree
            //							if(childNode instanceof CubridDatabase) {
            //								CubridDatabase database = (CubridDatabase) childNode;
            //								if (database.getRunningType() == DbRunningType.STANDALONE
            //										|| !database.isLogined()) {
            //									if (childNode.getData(INDEXKEY) == null) {
            //										childNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //									}
            //								}
            //								continue;
            //							}
            //							//CM tree
            //							for (ICubridNode dbFolderNode : childNode.getChildren()) {
            //								for (ICubridNode dbNode : dbFolderNode.getChildren()) {
            //									if(dbNode instanceof CubridDatabase) {
            //										CubridDatabase database = (CubridDatabase) dbNode;
            //										if (database.getRunningType() == DbRunningType.STANDALONE
            //												|| !database.isLogined()) {
            //											ctv.setChecked(dbNode, false);
            //										} else if (ctv.getChecked(dbNode)) {
            //											ctv.setChecked(dbNode, true);
            //											if (dbNode.getData(INDEXKEY) == null) {
            //												dbNode.setData(INDEXKEY, String.valueOf(databaseIndex++));
            //											}
            //										} else {
            //											ctv.setChecked(dbNode, false);
            //										}
            //									}
            //								}
            //							}
            //							//only has one db folder  so first time break it
            //							break;
            //						}
            //					}
            }
            ctv.refresh();
        }
    });
    ctv.getTree().addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent event) {
            //mac can't drag and drop,so support copy and paste db node
            if (((event.stateMask & SWT.CTRL) != 0) || ((event.stateMask & SWT.COMMAND) != 0) && event.keyCode == 'v') {
                final Clipboard cb = new Clipboard(getShell().getDisplay());
                String plainText = (String) cb.getContents(TextTransfer.getInstance());
                String[] databaseNameArray = plainText.split(",");
                selectedNodes.addAll(getDatabaseNode(databaseNameArray));
                setInput();
            }
        }
    });
    //		ctv.addDoubleClickListener(LayoutManager.getInstance());
    //		ctv.addTreeListener(new ITreeViewerListener() {
    //			public void treeCollapsed(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //
    //			public void treeExpanded(TreeExpansionEvent event) {
    //				CommonTool.clearExpandedElements(ctv);
    //			}
    //		});
    final Tree tableTree = ctv.getTree();
    tableTree.setHeaderVisible(true);
    tableTree.setLinesVisible(true);
    final TreeViewerColumn dbCol = new TreeViewerColumn(ctv, SWT.NONE);
    dbCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    dbCol.getColumn().setWidth(250);
    dbCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_dbCol);
    final TreeViewerColumn indexCol = new TreeViewerColumn(ctv, SWT.NONE);
    indexCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    indexCol.getColumn().setWidth(50);
    indexCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_indexCol);
    indexCol.setEditingSupport(new EditingSupport(ctv) {

        TextCellEditor textCellEditor;

        protected boolean canEdit(Object element) {
            if (element instanceof ICubridNode) {
                ICubridNode node = (ICubridNode) element;
                if (node.getType() == NodeType.DATABASE) {
                    CubridDatabase database = (CubridDatabase) element;
                    if ((database.getRunningType() == DbRunningType.CS && database.isLogined())) {
                        return true;
                    }
                }
            }
            return false;
        }

        protected CellEditor getCellEditor(Object element) {
            if (textCellEditor == null) {
                textCellEditor = new TextCellEditor(ctv.getTree());
                textCellEditor.setValidator(new IndexCellEditorValidator());
                textCellEditor.addListener(new ICellEditorListener() {

                    public void applyEditorValue() {
                    }

                    public void cancelEditor() {
                    }

                    public void editorValueChanged(boolean oldValidState, boolean newValidState) {
                    }
                });
            }
            return textCellEditor;
        }

        protected Object getValue(Object element) {
            final ICubridNode node = (ICubridNode) element;
            String index = (String) node.getData(INDEXKEY);
            if (index == null) {
                return "";
            } else {
                return index;
            }
        }

        protected void setValue(Object element, Object value) {
            if (value == null) {
                return;
            }
            try {
                Integer.valueOf((String) value);
            } catch (Exception e) {
                return;
            }
            final ICubridNode node = (ICubridNode) element;
            node.setData(INDEXKEY, value);
            //				setAllParentExpandOrCollapse(node.getParent(), true);
            ctv.refresh();
        }

        /**
			 * MyCellEditorValidator
			 *
			 * @author fulei
			 *
			 */
        class IndexCellEditorValidator implements ICellEditorValidator {

            /**
				 * isValid
				 *
				 * @param value Object
				 * @return String
				 */
            public String isValid(Object value) {
                try {
                    Integer.valueOf((String) value);
                } catch (Exception e) {
                    CommonUITool.openErrorBox(Messages.qedit_multiDBQueryComp_tree_indexErr);
                    return Messages.qedit_multiDBQueryComp_tree_indexErr;
                }
                return null;
            }
        }
    });
    final TreeViewerColumn commentCol = new TreeViewerColumn(ctv, SWT.NONE);
    commentCol.setLabelProvider(new MultiDBQueryTreeColumnLabelProvider());
    commentCol.getColumn().setWidth(200);
    commentCol.getColumn().setText(Messages.qedit_multiDBQueryComp_tree_commentCol);
    CTabItem tabItem = new CTabItem(multiDBQueryCompTabFolder, SWT.NONE);
    tabItem.setText(Messages.qedit_multiDBQueryComp_tabItem);
    tabItem.setControl(bottomSash);
    tabItem.setShowClose(false);
    setInput();
    //		HostNodePersistManager.getInstance().getAllServer();
    multiDBQueryCompTabFolder.setSelection(tabItem);
    dragController = new MultiDBQueryDNDController(this, ctv);
    dragController.registerDropTarget();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) EditingSupport(org.eclipse.jface.viewers.EditingSupport) CTabItem(org.eclipse.swt.custom.CTabItem) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) SashForm(org.eclipse.swt.custom.SashForm) ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) Clipboard(org.eclipse.swt.dnd.Clipboard) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 7 with ICellEditorValidator

use of org.eclipse.jface.viewers.ICellEditorValidator in project jbosstools-hibernate by jbosstools.

the class ConsoleConfigurationPropertySource method createProjectDescriptor.

private IPropertyDescriptor createProjectDescriptor() {
    ComboBoxPropertyDescriptor projectDescriptor = new ComboBoxPropertyDescriptor(// $NON-NLS-1$
    "project", HibernateConsoleMessages.ConsoleConfigurationPropertySource_project, getSortedProjectNames());
    projectDescriptor.setValidator(new ICellEditorValidator() {

        public String isValid(Object value) {
            if (value instanceof Integer) {
                if (((Integer) value).intValue() < 0) {
                    try {
                        ILaunchConfiguration lc = HibernateConsolePlugin.getDefault().findLaunchConfig(cfg.getName());
                        if (lc != null) {
                            String projectName = lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
                            if (projectName != null) {
                                return NLS.bind(HibernateConsoleMessages.ConsoleConfigurationMainTab_the_java_project_does_not_exist, projectName);
                            }
                        } else {
                            // $NON-NLS-1$//$NON-NLS-2$
                            HibernateConsolePlugin.getDefault().log("Can't find Console Configuration \"" + cfg.getName() + "\"");
                        }
                    } catch (CoreException e) {
                        HibernateConsolePlugin.getDefault().log(e);
                    }
                }
            }
            return null;
        }
    });
    return projectDescriptor;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) ComboBoxPropertyDescriptor(org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor)

Example 8 with ICellEditorValidator

use of org.eclipse.jface.viewers.ICellEditorValidator in project statecharts by Yakindu.

the class RealEditingSupport method getCellEditor.

@Override
public CellEditor getCellEditor(Object element) {
    TextCellEditor textCellEditor = new TextCellEditor((Composite) getViewer().getControl());
    textCellEditor.setValidator(new ICellEditorValidator() {

        public String isValid(Object value) {
            String stringValue = (String) value;
            try {
                Double.parseDouble(stringValue);
            } catch (NumberFormatException e) {
                return "No valid real value!";
            }
            return null;
        }
    });
    return textCellEditor;
}
Also used : ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 9 with ICellEditorValidator

use of org.eclipse.jface.viewers.ICellEditorValidator in project statecharts by Yakindu.

the class IntegerEditingSupport method getCellEditor.

@Override
public CellEditor getCellEditor(Object element) {
    TextCellEditor textCellEditor = new TextCellEditor((Composite) getViewer().getControl());
    textCellEditor.setValidator(new ICellEditorValidator() {

        public String isValid(Object value) {
            try {
                Long.parseLong((String) value);
            } catch (NumberFormatException e) {
                return "No valid integer value!";
            }
            return null;
        }
    });
    return textCellEditor;
}
Also used : ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 10 with ICellEditorValidator

use of org.eclipse.jface.viewers.ICellEditorValidator in project tdi-studio-se by Talend.

the class DataBusinessItemNameEditPart method getEditTextValidator.

/**
     * @generated
     */
public ICellEditorValidator getEditTextValidator() {
    return new ICellEditorValidator() {

        public String isValid(final Object value) {
            if (value instanceof String) {
                final EObject element = getParserElement();
                final IParser parser = getParser();
                try {
                    IParserEditStatus valid = (IParserEditStatus) getEditingDomain().runExclusive(new RunnableWithResult.Impl() {

                        public void run() {
                            setResult(parser.isValidEditString(new EObjectAdapter(element), (String) value));
                        }
                    });
                    return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
                } catch (InterruptedException ie) {
                    // ie.printStackTrace();
                    ExceptionHandler.process(ie);
                }
            }
            // shouldn't get here
            return null;
        }
    };
}
Also used : ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) IParserEditStatus(org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus) EObjectAdapter(org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter) IParser(org.eclipse.gmf.runtime.common.ui.services.parser.IParser)

Aggregations

ICellEditorValidator (org.eclipse.jface.viewers.ICellEditorValidator)20 EObject (org.eclipse.emf.ecore.EObject)14 IParser (org.eclipse.gmf.runtime.common.ui.services.parser.IParser)14 IParserEditStatus (org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus)14 EObjectAdapter (org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter)14 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)4 CellEditor (org.eclipse.jface.viewers.CellEditor)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 EditingSupport (org.eclipse.jface.viewers.EditingSupport)2 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)2 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Font (org.eclipse.swt.graphics.Font)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Tree (org.eclipse.swt.widgets.Tree)2 ColumnSpec (com.centurylink.mdw.plugin.designer.properties.editor.ColumnSpec)1 MappingEditor (com.centurylink.mdw.plugin.designer.properties.editor.MappingEditor)1