Search in sources :

Example 76 with TableItem

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

the class AlarmsView method sortCategoryList.

public void sortCategoryList(String name) {
    _ffCategoryList.removeAll();
    List<Category> catList = _categoryManager.getAllCategories();
    List<String> sortedCatList = new ArrayList<String>();
    for (Category cat : catList) sortedCatList.add(cat.getPath().toLowerCase());
    Collections.sort(sortedCatList);
    for (String sc : sortedCatList) {
        Category cat = null;
        for (Category c : catList) if (c.getPath().toLowerCase().compareTo(sc) == 0)
            cat = c;
        if (cat == null)
            return;
        if (cat.getAlarms() == null) {
            TableItem t = new TableItem(_ffCategoryList, SWT.None);
            t.setText(cat.getPath());
            if (cat.getIsDefault()) {
                FontData fd = t.getFont().getFontData()[0];
                fd.setStyle(SWT.BOLD);
                t.setFont(new Font(_shell.getDisplay(), fd));
            }
        } else {
            String[] ffs = cat.getAlarms().getFaultFamily();
            TableItem t = new TableItem(_ffCategoryList, SWT.None);
            t.setText(cat.getPath());
            if (cat.getIsDefault()) {
                FontData fd = t.getFont().getFontData()[0];
                fd.setStyle(SWT.BOLD);
                t.setFont(new Font(_shell.getDisplay(), fd));
            }
            for (int i = 0; i < ffs.length; i++) {
                if (ffs[i].compareTo(name) == 0)
                    t.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            }
        }
    }
}
Also used : Category(alma.acs.alarmsystem.generated.Category) TableItem(org.eclipse.swt.widgets.TableItem) FontData(org.eclipse.swt.graphics.FontData) ArrayList(java.util.ArrayList) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Example 77 with TableItem

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

the class AlarmsView method createFFWidgets.

private void createFFWidgets() {
    _updateFaultFamily = new Listener() {

        public void handleEvent(Event event) {
            TreeItem tmp = _tree.getSelection()[0];
            String ff = tmp.getText();
            FaultFamily fft = new FaultFamily();
            //TODO: Error icon or something similar
            if (_ffNameText.getText().isEmpty()) {
                _ffErrorMessageLabel.setText("FaultFamily Name Missing!");
                return;
            }
            if (_ffNameText.getText().contains(" ")) {
                _ffErrorMessageLabel.setText("Invalid FaultFamily Name. No spaces allowed.");
                return;
            }
            fft.setName(_ffNameText.getText());
            if (!_ffHelpURLText.getText().isEmpty()) {
                URI hurl;
                try {
                    hurl = new URI(_ffHelpURLText.getText());
                } catch (MalformedURIException e1) {
                    _ffErrorMessageLabel.setText("Malformed URL!");
                    return;
                }
                fft.setHelpUrl(hurl.toString());
            }
            fft.setAlarmSource(_ffSourceCombo.getText());
            Contact ct = new Contact();
            if (_ffContactNameText.getText().isEmpty()) {
                _ffErrorMessageLabel.setText("Contact Name Missing!");
                return;
            }
            ct.setName(_ffContactNameText.getText());
            if (!_ffContactMailText.getText().isEmpty())
                ct.setEmail(_ffContactMailText.getText());
            if (!_ffContactGSMText.getText().isEmpty())
                ct.setGsm(_ffContactGSMText.getText());
            fft.setContact(ct);
            _ffErrorMessageLabel.setText("");
            try {
                _alarmManager.updateFaultFamily(_alarmManager.getFaultFamily(ff), fft);
                tmp.setText(_ffNameText.getText());
                IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
                IViewReference[] views = _window.getActivePage().getViewReferences();
                IMyViewPart view = ((IMyViewPart) views[2].getView(false));
                view.fillWidgets();
                if (ff.compareTo(fft.getName()) != 0) {
                    sortFaultFamilyList();
                    selectElementFromTree(fft.getName(), null, null);
                }
            } catch (IllegalOperationException e) {
                _ffErrorMessageLabel.setText(e.getMessage());
            } catch (NullPointerException e) {
                e.printStackTrace();
                _ffErrorMessageLabel.setText(e.getMessage());
            }
        }
    };
    _addCategory = new Listener() {

        public void handleEvent(Event event) {
            if (event.type == SWT.KeyUp)
                if (!(event.keyCode == SWT.CR || event.keyCode == ' '))
                    return;
            if (event.type == SWT.MouseDoubleClick) {
                Point pt = new Point(event.x, event.y);
                if (_ffCategoryList.getItem(pt) == null)
                    return;
            }
            TreeItem[] tmp1 = _tree.getSelection();
            if (tmp1 == null || tmp1.length == 0)
                return;
            String ff = tmp1[0].getText();
            TableItem[] tmp2 = _ffCategoryList.getSelection();
            if (tmp2 == null || tmp2.length == 0)
                return;
            TableItem item = tmp2[0];
            Category c = _categoryManager.getCategoryByPath(item.getText());
            try {
                String[] ffs = c.getAlarms().getFaultFamily();
                for (int i = 0; i < ffs.length; i++) {
                    if (ff.compareTo(ffs[i]) == 0) {
                        c.getAlarms().removeFaultFamily(ff);
                        item.setImage((org.eclipse.swt.graphics.Image) null);
                        IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
                        IViewReference[] views = _window.getActivePage().getViewReferences();
                        IMyViewPart view = ((IMyViewPart) views[2].getView(false));
                        view.fillWidgets();
                        return;
                    }
                }
                c.getAlarms().addFaultFamily(ff);
                item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            } catch (NullPointerException e) {
                item.setImage((org.eclipse.swt.graphics.Image) null);
                Alarms alarms = new Alarms();
                alarms.addFaultFamily(ff.toString());
                alarms.setFaultFamily(0, ff.toString());
                c.setAlarms(alarms);
                item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
            }
            IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
            IViewReference[] views = _window.getActivePage().getViewReferences();
            IMyViewPart view = ((IMyViewPart) views[2].getView(false));
            view.fillWidgets();
        }
    };
    _FFgroup = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
    _FFgroup.setText("Fault Family details");
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    _FFgroup.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 2;
    _FFgroup.setLayout(gl);
    _ffNameLabel = new Label(_FFgroup, SWT.NONE);
    _ffNameLabel.setText("Fault Family name");
    _ffNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffNameText.setLayoutData(gd);
    _ffNameText.addListener(SWT.Modify, _updateFaultFamily);
    _ffHelpURLLabel = new Label(_FFgroup, SWT.NONE);
    _ffHelpURLLabel.setText("Help URL");
    _ffHelpURLText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffHelpURLText.setLayoutData(gd);
    _ffHelpURLText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactNameLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactNameLabel.setText("Contact name");
    _ffContactNameText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactNameText.setLayoutData(gd);
    _ffContactNameText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactMailLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactMailLabel.setText("Contact e-mail");
    _ffContactMailText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactMailText.setLayoutData(gd);
    _ffContactMailText.addListener(SWT.Modify, _updateFaultFamily);
    _ffContactGSMLabel = new Label(_FFgroup, SWT.NONE);
    _ffContactGSMLabel.setText("Contact GSM");
    _ffContactGSMText = new Text(_FFgroup, SWT.SINGLE | SWT.BORDER);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffContactGSMText.setLayoutData(gd);
    _ffContactGSMText.addListener(SWT.Modify, _updateFaultFamily);
    _ffSourceLabel = new Label(_FFgroup, SWT.NONE);
    _ffSourceLabel.setText("Source");
    _ffSourceCombo = new Combo(_FFgroup, SWT.DROP_DOWN | SWT.READ_ONLY);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    _ffSourceCombo.setLayoutData(gd);
    _ffSourceCombo.setEnabled(false);
    _ffSourceCombo.addListener(SWT.Modify, _updateFaultFamily);
    _ffCategoryLabel = new Label(_FFgroup, SWT.NONE);
    _ffCategoryLabel.setText("Categories:");
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _ffCategoryLabel.setLayoutData(gd);
    _ffCategoryList = new Table(_FFgroup, SWT.BORDER);
    gd = new GridData();
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    _ffCategoryList.setLayoutData(gd);
    _ffCategoryList.addListener(SWT.KeyUp, _addCategory);
    _ffCategoryList.addListener(SWT.MouseDoubleClick, _addCategory);
    Menu categoryPopUp = new Menu(_ffCategoryList);
    _ffCategoryList.setMenu(categoryPopUp);
    categoryPopUp.addListener(SWT.Show, new Listener() {

        public void handleEvent(Event e) {
            TableItem[] sel = _ffCategoryList.getSelection();
            Menu categoryPopUp = _ffCategoryList.getMenu();
            MenuItem[] items = categoryPopUp.getItems();
            for (int i = 0; i < items.length; i++) items[i].dispose();
            if (sel == null || sel.length == 0)
                return;
            MenuItem mitem;
            mitem = new MenuItem(categoryPopUp, SWT.PUSH);
            if (sel[0].getImage() == null) {
                mitem.setText("Add to Category");
                mitem.addListener(SWT.Selection, _addCategory);
            } else {
                mitem.setText("Remove from Category");
                mitem.addListener(SWT.Selection, _addCategory);
            }
        }
    });
    _ffErrorMessageLabel = new Label(_FFgroup, SWT.NONE);
    _ffErrorMessageLabel.setText("");
    _ffErrorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    _ffErrorMessageLabel.setLayoutData(gd);
}
Also used : Group(org.eclipse.swt.widgets.Group) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) MalformedURIException(org.apache.xerces.util.URI.MalformedURIException) Category(alma.acs.alarmsystem.generated.Category) TreeItem(org.eclipse.swt.widgets.TreeItem) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) URI(org.apache.xerces.util.URI) GridLayout(org.eclipse.swt.layout.GridLayout) Menu(org.eclipse.swt.widgets.Menu) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Table(org.eclipse.swt.widgets.Table) Alarms(alma.acs.alarmsystem.generated.Alarms) Text(org.eclipse.swt.widgets.Text) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IllegalOperationException(cl.utfsm.acs.acg.core.IllegalOperationException) Contact(alma.acs.alarmsystem.generated.Contact) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 78 with TableItem

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

the class PstmtOneDataDialog method validate.

/**
	 * validate the data
	 * 
	 * @return boolean
	 */
protected boolean validate() {
    setErrorMessage(null);
    getButton(IDialogConstants.OK_ID).setEnabled(false);
    if (!validSql()) {
        setErrorMessage(Messages.errInvalidSql);
        return false;
    }
    getButton(IDialogConstants.OK_ID).setEnabled(false);
    for (int i = 0; i < parameterTable.getItemCount(); i++) {
        TableItem item = parameterTable.getItem(i);
        String value = item.getText(2);
        if (!validate(value, item)) {
            return false;
        }
    }
    getButton(IDialogConstants.OK_ID).setEnabled(true);
    return true;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem)

Example 79 with TableItem

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

the class PstmtSQLDialog method registerContextMenu.

private void registerContextMenu() {
    parameterTable.getTable().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(parameterTable.getTable());
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(parameterTable.getTable());
    parameterTable.getTable().setMenu(contextMenu);
    Menu menu = new Menu(getShell(), SWT.POP_UP);
    final MenuItem itemShowMuchValue = new MenuItem(menu, SWT.PUSH);
    itemShowMuchValue.setText(Messages.pstmtSQLMuchItem);
    itemShowMuchValue.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked
            Point pt = clickPoint;
            int selectIndex = parameterTable.getTable().getSelectionIndex();
            final TableItem item = parameterTable.getTable().getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 1; i < parameterTable.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    String type = parameterTypeTable.getItem(0).getText(i);
                    SetPstmtValueDialog dialog = new SetPstmtValueDialog(getShell(), item, database, i, type);
                    if (IDialogConstants.OK_ID == dialog.open()) {
                        charSet = (String) item.getData(SetPstmtValueDialog.FILE_CHARSET);
                        valueList.get(selectIndex).getValue().set(i, item.getText(i));
                        packTable();
                        addTableItemToLast(selectIndex, item);
                    }
                    validate();
                }
            }
        }
    });
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked
            Point pt = clickPoint;
            int selectIndex = parameterTable.getTable().getSelectionIndex();
            if (selectIndex < 0) {
                itemShowMuchValue.setEnabled(false);
                return;
            }
            final TableItem item = parameterTable.getTable().getItem(selectIndex);
            if (item == null) {
                itemShowMuchValue.setEnabled(false);
                return;
            }
            for (int i = 1; i < parameterTable.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    String type = parameterTypeTable.getItem(0).getText(i);
                    //if type is nut much value type ,set the menu disable
                    if (DBAttrTypeFormatter.isMuchValueType(type)) {
                        itemShowMuchValue.setEnabled(true);
                    } else {
                        itemShowMuchValue.setEnabled(false);
                    }
                }
            }
        }
    });
    parameterTable.getTable().setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 80 with TableItem

use of org.eclipse.swt.widgets.TableItem 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)

Aggregations

TableItem (org.eclipse.swt.widgets.TableItem)475 Point (org.eclipse.swt.graphics.Point)136 Table (org.eclipse.swt.widgets.Table)125 TableColumn (org.eclipse.swt.widgets.TableColumn)79 SelectionEvent (org.eclipse.swt.events.SelectionEvent)73 GridData (org.eclipse.swt.layout.GridData)70 GridLayout (org.eclipse.swt.layout.GridLayout)61 Composite (org.eclipse.swt.widgets.Composite)56 ArrayList (java.util.ArrayList)55 Image (org.eclipse.swt.graphics.Image)55 Button (org.eclipse.swt.widgets.Button)53 Rectangle (org.eclipse.swt.graphics.Rectangle)52 Label (org.eclipse.swt.widgets.Label)51 Shell (org.eclipse.swt.widgets.Shell)49 Color (org.eclipse.swt.graphics.Color)48 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)43 Text (org.eclipse.swt.widgets.Text)42 FillLayout (org.eclipse.swt.layout.FillLayout)40 Test (org.junit.Test)39 SelectionListener (org.eclipse.swt.events.SelectionListener)36