Search in sources :

Example 11 with ToolBarManager

use of org.eclipse.jface.action.ToolBarManager in project yamcs-studio by yamcs.

the class DrillDownComposite method createNavigationButtons.

/**
 * Creates the navigation buttons for this viewer.
 */
private void createNavigationButtons() {
    GridData gid;
    GridLayout layout;
    // Define layout.
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    setLayout(layout);
    // Create a toolbar.
    _toolBarMgr = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = _toolBarMgr.createControl(this);
    gid = new GridData();
    gid.horizontalAlignment = GridData.FILL;
    gid.verticalAlignment = GridData.BEGINNING;
    toolBar.setLayoutData(gid);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ToolBarManager(org.eclipse.jface.action.ToolBarManager)

Example 12 with ToolBarManager

use of org.eclipse.jface.action.ToolBarManager in project yamcs-studio by yamcs.

the class DrillDownComposite method createNavigationButtons.

/**
 * Creates the navigation buttons for this viewer.
 */
private void createNavigationButtons() {
    GridData gid;
    GridLayout layout;
    // Define layout.
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    setLayout(layout);
    // Create a toolbar.
    _toolBarMgr = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = _toolBarMgr.createControl(this);
    gid = new GridData();
    gid.horizontalAlignment = GridData.FILL;
    gid.verticalAlignment = GridData.BEGINNING;
    toolBar.setLayoutData(gid);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ToolBarManager(org.eclipse.jface.action.ToolBarManager)

Example 13 with ToolBarManager

use of org.eclipse.jface.action.ToolBarManager in project yamcs-studio by yamcs.

the class RuleDataEditDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite parent_Composite = (Composite) super.createDialogArea(parent);
    // Parent composite has GridLayout with 1 columns.
    // Create embedded composite w/ 2 columns
    final Composite mainComposite = new Composite(parent_Composite, SWT.None);
    mainComposite.setLayout(new GridLayout(2, false));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 500;
    mainComposite.setLayoutData(gridData);
    final Composite topComposite = new Composite(mainComposite, SWT.None);
    topComposite.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.horizontalSpan = 2;
    topComposite.setLayoutData(gd);
    createLabel(topComposite, "Rule Name: ");
    nameText = new Text(topComposite, SWT.BORDER);
    nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    nameText.setText(ruleData.getName());
    nameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            ruleData.setName(nameText.getText());
        }
    });
    createLabel(topComposite, "Property: ");
    propCombo = new Combo(topComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    propCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    String[] comboItems = new String[propIDList.size()];
    int i = 0;
    for (String id : propIDList) {
        comboItems[i++] = ruleData.getWidgetModel().getProperty(id).getDescription() + " (" + id + // $NON-NLS-1$ //$NON-NLS-2$
        ")";
    }
    propCombo.setItems(comboItems);
    propCombo.select(propIDList.indexOf(ruleData.getPropId()));
    propCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (propIDList.get(propCombo.getSelectionIndex()).equals(AbstractPVWidgetModel.PROP_PVVALUE)) {
                MessageDialog.openWarning(propCombo.getShell(), "Warning", "Note: Changing pv_value property with rule or " + "script will not write value to the PV. " + "It only change the graphical value on the widget! " + "If you need to write a PV, please call PV.setValue() from script.");
            }
            ruleData.setPropId(propIDList.get(propCombo.getSelectionIndex()));
            if (ruleData.getProperty().getPropertyDescriptor() == null || ruleData.getProperty().onlyAcceptExpressionInRule()) {
                ruleData.setOutputExpValue(true);
                outPutExpButton.setSelection(true);
                outPutExpButton.setEnabled(false);
                for (Expression exp : expressionList) // $NON-NLS-1$
                exp.setValue("");
                valueColumn.getColumn().setText("Output Expression");
            } else
                outPutExpButton.setEnabled(true);
            if (!ruleData.isOutputExpValue()) {
                for (Expression exp : expressionList) exp.setValue(ruleData.isOutputExpValue() ? "" : // $NON-NLS-1$
                ruleData.getProperty().getDefaultValue());
            }
            expressionViewer.refresh();
        }
    });
    outPutExpButton = new Button(topComposite, SWT.CHECK);
    gd = new GridData();
    gd.horizontalSpan = 2;
    outPutExpButton.setLayoutData(gd);
    outPutExpButton.setText("Output Expression");
    if (ruleData.getProperty().getPropertyDescriptor() == null || ruleData.getProperty().onlyAcceptExpressionInRule()) {
        ruleData.setOutputExpValue(true);
        outPutExpButton.setEnabled(false);
    }
    outPutExpButton.setSelection(ruleData.isOutputExpValue());
    outPutExpButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ruleData.setOutputExpValue(outPutExpButton.getSelection());
            for (Expression exp : expressionList) exp.setValue(ruleData.isOutputExpValue() ? "" : // $NON-NLS-1$
            ruleData.getProperty().getDefaultValue());
            valueColumn.getColumn().setText(ruleData.isOutputExpValue() ? "Output Expression" : "Output Value");
            expressionViewer.refresh();
        }
    });
    // Left Panel: List of scripts
    final Composite leftComposite = new Composite(mainComposite, SWT.NONE);
    leftComposite.setLayout(new GridLayout(1, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 350;
    leftComposite.setLayoutData(gd);
    createLabel(leftComposite, "Expressions");
    Composite toolBarComposite = new Composite(leftComposite, SWT.BORDER);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    gridLayout.marginBottom = 0;
    gridLayout.marginTop = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    toolBarComposite.setLayout(gridLayout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    toolBarComposite.setLayoutData(gd);
    ToolBarManager toolbarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolbarManager.createControl(toolBarComposite);
    GridData grid = new GridData();
    grid.horizontalAlignment = GridData.FILL;
    grid.verticalAlignment = GridData.BEGINNING;
    toolBar.setLayoutData(grid);
    createActions();
    toolbarManager.add(addAction);
    toolbarManager.add(copyAction);
    toolbarManager.add(removeAction);
    toolbarManager.add(moveUpAction);
    toolbarManager.add(moveDownAction);
    toolbarManager.update(true);
    expressionViewer = createExpressionsTableViewer(toolBarComposite);
    expressionViewer.setInput(expressionList);
    expressionViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            refreshActionBarOnSelection();
        }
    });
    // Right panel: Input PVs for selected script
    final Composite rightComposite = new Composite(mainComposite, SWT.NONE);
    gridLayout = new GridLayout(1, false);
    rightComposite.setLayout(gridLayout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    // Account for the StringTableEditor's minimum size
    gd.minimumWidth = 250;
    rightComposite.setLayoutData(gd);
    this.createLabel(rightComposite, "Input PVs");
    pvsEditor = new PVTupleTableEditor(rightComposite, ruleData.getPVList(), SWT.BORDER);
    pvsEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    if (expressionList.size() > 0)
        setExpressionViewerSelection(expressionList.get(0));
    final Composite bottomComposite = new Composite(mainComposite, SWT.None);
    bottomComposite.setLayout(new GridLayout(1, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.horizontalSpan = 2;
    bottomComposite.setLayoutData(gd);
    Button generateScriptButton = new Button(bottomComposite, SWT.PUSH);
    generateScriptButton.setText("See Generated Script");
    gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
    generateScriptButton.setLayoutData(gd);
    final Text scriptText = new Text(bottomComposite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    scriptText.setLayoutData(gd);
    generateScriptButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            scriptText.setText(ruleData.generateScript());
        }
    });
    return parent_Composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ToolBarManager(org.eclipse.jface.action.ToolBarManager) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Expression(org.csstudio.opibuilder.script.Expression) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolBar(org.eclipse.swt.widgets.ToolBar)

Example 14 with ToolBarManager

use of org.eclipse.jface.action.ToolBarManager in project yamcs-studio by yamcs.

the class ColorMapEditDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite parent_Composite = (Composite) super.createDialogArea(parent);
    final Composite mainComposite = new Composite(parent_Composite, SWT.None);
    mainComposite.setLayout(new GridLayout(2, false));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.heightHint = 300;
    mainComposite.setLayoutData(gridData);
    final Composite leftComposite = new Composite(mainComposite, SWT.None);
    leftComposite.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 250;
    leftComposite.setLayoutData(gd);
    createLabel(leftComposite, "Color Map:");
    Composite toolBarComposite = new Composite(leftComposite, SWT.BORDER);
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginLeft = 0;
    gridLayout.marginRight = 0;
    gridLayout.marginBottom = 0;
    gridLayout.marginTop = 0;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    toolBarComposite.setLayout(gridLayout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    toolBarComposite.setLayoutData(gd);
    ToolBarManager toolbarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolbarManager.createControl(toolBarComposite);
    GridData grid = new GridData();
    grid.horizontalAlignment = GridData.FILL;
    grid.verticalAlignment = GridData.BEGINNING;
    toolBar.setLayoutData(grid);
    createActions();
    toolbarManager.add(addAction);
    toolbarManager.add(copyAction);
    toolbarManager.add(removeAction);
    toolbarManager.add(moveUpAction);
    toolbarManager.add(moveDownAction);
    toolbarManager.update(true);
    colorListViewer = createColorListViewer(toolBarComposite);
    colorListViewer.setInput(colorList);
    Composite rightComposite = new Composite(mainComposite, SWT.NONE);
    rightComposite.setLayout(new GridLayout(1, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 340;
    rightComposite.setLayoutData(gd);
    this.createLabel(rightComposite, "Use predefined color map:");
    preDefinedMapCombo = new Combo(rightComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    preDefinedMapCombo.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false));
    preDefinedMapCombo.setItems(PredefinedColorMap.getStringValues());
    int i = 0;
    for (PredefinedColorMap colorMap : PredefinedColorMap.values()) {
        if (predefinedColorMap == colorMap)
            break;
        else
            i++;
    }
    preDefinedMapCombo.select(i);
    final Button InterpolateCheckBox = new Button(rightComposite, SWT.CHECK);
    InterpolateCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false));
    InterpolateCheckBox.setSelection(interpolate);
    InterpolateCheckBox.setText("Interpolate");
    final Button autoScaleCheckBox = new Button(rightComposite, SWT.CHECK);
    autoScaleCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false));
    autoScaleCheckBox.setSelection(autoScale);
    autoScaleCheckBox.setText("Auto Scale");
    autoScaleCheckBox.setToolTipText("Scale the color map values to the range of" + " (" + min + ", " + max + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ").");
    Group group = new Group(rightComposite, SWT.None);
    group.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
    group.setLayout(new GridLayout(2, false));
    // $NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-3$
    group.setText("Output" + " (" + min + "~" + max + ")");
    colorMapLabel = new Label(group, SWT.None);
    colorMapLabel.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
    refreshGUI();
    preDefinedMapCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            predefinedColorMap = PredefinedColorMap.values()[preDefinedMapCombo.getSelectionIndex()];
            if (preDefinedMapCombo.getSelectionIndex() != 0) {
                LinkedHashMap<Double, RGB> map = PredefinedColorMap.values()[preDefinedMapCombo.getSelectionIndex()].getMap();
                colorList.clear();
                for (Entry<Double, RGB> entry : map.entrySet()) colorList.add(new ColorTuple(entry.getKey(), entry.getValue()));
                colorListViewer.refresh();
            }
            refreshGUI();
        }
    });
    InterpolateCheckBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            interpolate = InterpolateCheckBox.getSelection();
            refreshGUI();
        }
    });
    autoScaleCheckBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            autoScale = autoScaleCheckBox.getSelection();
            refreshGUI();
        }
    });
    return parent_Composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ToolBarManager(org.eclipse.jface.action.ToolBarManager) LinkedHashMap(java.util.LinkedHashMap) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Entry(java.util.Map.Entry) ColorTuple(org.csstudio.swt.widgets.datadefinition.ColorTuple) Button(org.eclipse.swt.widgets.Button) PredefinedColorMap(org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 15 with ToolBarManager

use of org.eclipse.jface.action.ToolBarManager in project cubrid-manager by CUBRID.

the class QueryResultComposite method makeResult.

/**
	 * make the result contents.
	 * 
	 * @param result QueryExecuter
	 */
private void makeResult(final QueryExecuter result, CTabFolder parentFolder) {
    editor.getCombinedQueryComposite().getRecentlyUsedSQLComposite().refreshRecentlyUsedSQLList();
    //final CTabFolder queryResultTabFolder = ((QueryResultComposite)queryResultTabItem.getControl()).queryResultTabFolder;
    ViewForm viewForm = new ViewForm(parentFolder, SWT.NONE);
    // create the bottom sash
    final SashForm tableLogSash = new SashForm(viewForm, SWT.VERTICAL);
    tableLogSash.SASH_WIDTH = SASH_WIDTH;
    tableLogSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    final Composite resultContainer = new Composite(tableLogSash, SWT.None);
    resultContainer.setLayout(new FormLayout());
    final Table resultTable = new Table(resultContainer, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
    setDropTraget(resultTable);
    resultTable.setHeaderVisible(true);
    resultTable.setLinesVisible(true);
    resultTable.setBackground(BACKGROUND_NORMAL);
    CommonUITool.hackForYosemite(resultTable);
    // display data compare label for multiple queries
    if (this.multiResultsCompare == true) {
        Composite compareButtonComposite = new Composite(resultContainer, SWT.None);
        compareButtonComposite.setLayout(new FillLayout());
        displayDataCompareLabel(compareButtonComposite, resultTable);
        FormData tableData = new FormData();
        tableData.top = new FormAttachment(0, 0);
        tableData.bottom = new FormAttachment(100, -28);
        tableData.left = new FormAttachment(0, 0);
        tableData.right = new FormAttachment(100, 0);
        resultTable.setLayoutData(tableData);
        FormData compareData = new FormData();
        compareData.top = new FormAttachment(100, -28);
        compareData.bottom = new FormAttachment(100, 0);
        compareData.left = new FormAttachment(0, 0);
        compareData.right = new FormAttachment(100, 0);
        compareButtonComposite.setLayoutData(compareData);
    } else {
        FormData tableData = new FormData();
        tableData.top = new FormAttachment(0, 0);
        tableData.bottom = new FormAttachment(100, 0);
        tableData.left = new FormAttachment(0, 0);
        tableData.right = new FormAttachment(100, 0);
        resultTable.setLayoutData(tableData);
    }
    final SashForm logSash = new SashForm(tableLogSash, SWT.HORIZONTAL);
    logSash.SASH_WIDTH = SASH_WIDTH;
    logSash.setBackground(CombinedQueryEditorComposite.BACK_COLOR);
    logSash.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    StyledText messagesArea = new StyledText(logSash, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP);
    CommonUITool.registerCopyPasteContextMenu(messagesArea, false, false);
    tableLogSash.setWeights(new int[] { 8, 2 });
    messagesArea.setToolTipText(Messages.tooltipHowToExpandLogPane);
    messagesArea.addFocusListener(new FocusListener() {

        public void focusLost(FocusEvent e) {
            tableLogSash.setWeights(new int[] { 8, 2 });
        }

        public void focusGained(FocusEvent e) {
            tableLogSash.setWeights(new int[] { 2, 8 });
        }
    });
    TableCursor cursor = new TableCursor(resultTable, SWT.NONE);
    TableSelectSupport tableSelectSupport = new TableSelectSupport(resultTable, cursor);
    if (this.multiResultsCompare == true) {
        result.setMultiResultsCompare(true);
        result.setBaseQueryExecuter(this.baseQueryExecuter);
    }
    result.makeResult(tableSelectSupport, messagesArea, isMutliQuery);
    // Auto set column size, maximum is 300px,minimum is 50px
    for (int i = 1; i < resultTable.getColumnCount(); i++) {
        resultTable.getColumns()[i].pack();
        if (resultTable.getColumns()[i].getWidth() > 300) {
            resultTable.getColumns()[i].setWidth(300);
        }
        if (resultTable.getColumns()[i].getWidth() < 50) {
            resultTable.getColumns()[i].setWidth(50);
        }
    }
    // fill the view form action on top right corner
    ToolBar topRightToolBar = new ToolBar(viewForm, SWT.FLAT);
    ToolBarManager toolBarManager = new ToolBarManager(topRightToolBar);
    result.makeActions(toolBarManager, resultTable);
    // fill the view form action on top right corner
    ToolBar topLeftToolBar = new ToolBar(viewForm, SWT.FLAT);
    swRecordItem = new ToolItem(topLeftToolBar, SWT.CHECK);
    result.swRecordItem = swRecordItem;
    swRecordItem.setToolTipText(Messages.getOidOn);
    swRecordItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_update.png"));
    swRecordItem.setEnabled(true);
    swRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (editor.isCollectExecStats()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errNotEditableOnStat);
                return;
            }
            if (!result.isContainPrimayKey()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errNoPrimaryKey);
                return;
            }
            if (!result.isSingleTableQuery()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errNotInOneTable);
                return;
            }
            if (!checkConnection()) {
                result.swRecordItem.setSelection(false);
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            result.tblResult.forceFocus();
            if (result.swRecordItem.getSelection()) {
                result.swRecordItem.setToolTipText(Messages.getOidOn);
                result.setEditMode(true);
                result.insertRecordItem.setEnabled(true);
                if (result.tblResult.getSelectionCount() > 0) {
                    result.delRecordItem.setEnabled(true);
                }
            } else {
                if (result.isModifiedResult()) {
                    result.swRecordItem.setSelection(true);
                    CommonUITool.openErrorBox(getShell(), Messages.errHasNoCommit);
                    return;
                }
                result.swRecordItem.setToolTipText(Messages.getOidOff);
                result.setEditMode(false);
                result.insertRecordItem.setEnabled(false);
                result.delRecordItem.setEnabled(false);
            }
        }
    });
    //added by kevin, for insert record
    insertRecordItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.insertRecordItem = insertRecordItem;
    insertRecordItem.setToolTipText(com.cubrid.common.ui.cubrid.table.Messages.insertInstanceMsgTitle);
    insertRecordItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_insert.png"));
    insertRecordItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_insert_disabled.png"));
    insertRecordItem.setEnabled(false);
    insertRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!result.getEditable()) {
                CommonUITool.openErrorBox(getShell(), Messages.errNotEditable);
                return;
            }
            if (!checkConnection()) {
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            result.insertSaveItem.setEnabled(result.getEditable());
            result.rollbackModifiedItem.setEnabled(result.getEditable());
            result.addNewItem();
        }
    });
    delRecordItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.delRecordItem = delRecordItem;
    delRecordItem.setToolTipText(Messages.delete);
    delRecordItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_delete.png"));
    delRecordItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/table_record_delete_disabled.png"));
    delRecordItem.setEnabled(false);
    delRecordItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!result.getEditable()) {
                CommonUITool.openErrorBox(getShell(), Messages.errNotEditable);
                return;
            }
            if (!checkConnection()) {
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            result.tblResult.forceFocus();
            result.deleteRecord(result.tblResult, null);
        }
    });
    insertSaveItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.insertSaveItem = insertSaveItem;
    insertSaveItem.setToolTipText(Messages.insertCommit);
    insertSaveItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_commit.png"));
    insertSaveItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_commit_disabled.png"));
    insertSaveItem.setEnabled(false);
    insertSaveItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!checkConnection()) {
                CommonUITool.openErrorBox(getShell(), Messages.errMsgExecuteInResult);
                return;
            }
            if (result.getQueryEditor().isActive()) {
                CommonUITool.openWarningBox(Messages.msgActiveTran);
                return;
            }
            if (!CommonUITool.openConfirmBox(getShell(), (Messages.msgCommitEdited))) {
                return;
            }
            try {
                if (result.saveInsertedUpdatedDeletedRecords()) {
                    insertSaveItem.setEnabled(false);
                    result.rollbackModifiedItem.setEnabled(false);
                    result.swRecordItem.setSelection(false);
                }
                result.swRecordItem.setSelection(false);
                result.insertRecordItem.setEnabled(false);
                result.delRecordItem.setEnabled(false);
                result.setEditMode(false);
            } catch (ParamSetException e) {
                if (e.getParameter() != null && !StringUtil.isEmpty(e.getParameter().getDataType())) {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errTextTypeNotMatch, e.getParameter().getDataType()) + StringUtil.NEWLINE + e.getLocalizedMessage());
                } else {
                    CommonUITool.openErrorBox(getShell(), e.getLocalizedMessage());
                }
            } catch (SQLException e) {
                e.printStackTrace();
                CommonUITool.openErrorBox(getShell(), e.getErrorCode() + StringUtil.NEWLINE + e.getMessage());
                /*Can't edit any data if necessary*/
                //					result.setEditMode(false);
                //				    delRecordItem.setEnabled(false);
                //					insertRecordItem.setEnabled(false);
                //					insertSaveItem.setEnabled(false) ;
                //					swRecordItem.setEnabled(false);
                //					rollbackModifiedItem.setEnabled(false);
                result.getTblResult().setBackground(BACKGROUND_DIRTY);
            }
        }
    });
    rollbackModifiedItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    result.rollbackModifiedItem = rollbackModifiedItem;
    rollbackModifiedItem.setToolTipText(Messages.insertRollback);
    rollbackModifiedItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/query_rollback.png"));
    rollbackModifiedItem.setDisabledImage(CommonUIPlugin.getImage("icons/queryeditor/query_rollback_disabled.png"));
    rollbackModifiedItem.setEnabled(false);
    rollbackModifiedItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (!CommonUITool.openConfirmBox(getShell(), (Messages.msgRollbackEdited))) {
                return;
            }
            result.tblResult.forceFocus();
            insertSaveItem.setEnabled(false);
            rollbackModifiedItem.setEnabled(false);
            result.clearModifiedLog();
            QueryInfo queryInfo = result.getQueryInfo();
            queryInfo.setCurrentPage(queryInfo.getCurrentPage());
            result.makeItem();
            result.updateActions();
            result.swRecordItem.setSelection(false);
            result.insertRecordItem.setEnabled(false);
            result.delRecordItem.setEnabled(false);
            result.setEditMode(false);
            result.tblResult.setBackground(BACKGROUND_NORMAL);
        }
    });
    if (!isMutliQuery) {
        new ToolItem(topLeftToolBar, SWT.SEPARATOR);
        copyInsertSqlFromRecordsItem = new ToolItem(topLeftToolBar, SWT.PUSH);
        copyInsertSqlFromRecordsItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_insert.png"));
        copyInsertSqlFromRecordsItem.setToolTipText(Messages.makeInsertFromSelectedRecord);
        copyInsertSqlFromRecordsItem.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                if (editor == null) {
                    return;
                }
                String text = editor.getQueryExecuter().makeInsertQueryWithSelectedRecords();
                if (StringUtil.isEmpty(text)) {
                    CommonUITool.openErrorBox(getShell(), Messages.canNotMakeQueryBecauseNoSelected);
                    return;
                }
                CommonUITool.copyContentToClipboard(text);
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        copyUpdateSqlFromRecordsItem = new ToolItem(topLeftToolBar, SWT.PUSH);
        copyUpdateSqlFromRecordsItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/record_to_update.png"));
        copyUpdateSqlFromRecordsItem.setToolTipText(Messages.makeUpdateFromSelectedRecord);
        copyUpdateSqlFromRecordsItem.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                if (editor == null) {
                    return;
                }
                String text = editor.getQueryExecuter().makeUpdateQueryWithSelectedRecords();
                if (StringUtil.isEmpty(text)) {
                    CommonUITool.openErrorBox(getShell(), Messages.canNotMakeQueryBecauseNoSelected);
                    return;
                }
                CommonUITool.copyContentToClipboard(text);
            }

            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
    }
    new ToolItem(topLeftToolBar, SWT.SEPARATOR);
    final ToolItem exportDataItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    exportDataItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/table_data_export.png"));
    exportDataItem.setToolTipText(Messages.msgExportAllQueryResults);
    exportDataItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            CTabItem[] items = queryResultTabFolder.getItems();
            if (items == null || items.length == 0) {
                return;
            }
            List<QueryExecuter> qeList = new ArrayList<QueryExecuter>();
            for (CTabItem item : items) {
                if (!(item.getData() instanceof QueryExecuter)) {
                    continue;
                }
                QueryExecuter qe = (QueryExecuter) item.getData();
                qeList.add(qe);
            }
            if (qeList.isEmpty()) {
                return;
            }
            ExportQueryResultDialog dialog = new ExportQueryResultDialog(getShell(), qeList);
            dialog.open();
        }
    });
    new ToolItem(topLeftToolBar, SWT.SEPARATOR);
    final ToolItem showLogItem = new ToolItem(topLeftToolBar, SWT.PUSH);
    showLogItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_down.png"));
    showLogItem.setToolTipText(Messages.tooltip_qedit_log_show_hide);
    showLogItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (tableLogSash.getMaximizedControl() == null) {
                tableLogSash.setMaximizedControl(resultContainer);
                showLogItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_up.png"));
                tableLogSash.layout(true);
            } else {
                tableLogSash.setMaximizedControl(null);
                showLogItem.setImage(CommonUIPlugin.getImage("icons/queryeditor/qe_panel_down.png"));
                tableLogSash.layout(true);
            }
        }
    });
    new ToolItem(topLeftToolBar, SWT.SEPARATOR);
    viewForm.setContent(tableLogSash);
    viewForm.setTopRight(topRightToolBar);
    viewForm.setTopLeft(topLeftToolBar);
    final QueryTableTabItem queryTableTabItem = new QueryTableTabItem(parentFolder, SWT.NONE);
    queryTableTabItem.setText(Messages.qedit_result + (result.idx + 1));
    queryTableTabItem.setControl(viewForm);
    queryTableTabItem.setData(result);
    queryTableTabItem.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            InfoWindowManager.getInstance().updateContent(editor);
        }
    });
    parentFolder.setSelection(queryTableTabItem);
    tableSelectSupport.addSelectChangeListener(new ISelectionChangeListener() {

        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangeEvent event) {
            boolean active = event.selectedArray.length > 0;
            boolean canEdit = active && result.getEditable() && result.isEditMode();
            if (delRecordItem != null) {
                delRecordItem.setEnabled(canEdit);
            }
            if (copyInsertSqlFromRecordsItem != null) {
                copyInsertSqlFromRecordsItem.setEnabled(active);
            }
            if (copyUpdateSqlFromRecordsItem != null) {
                copyUpdateSqlFromRecordsItem.setEnabled(active);
            }
            /*TOOLS-3632 Add calculation info*/
            int count = event.selectedArray.length;
            BigDecimal sum = new BigDecimal(0);
            BigDecimal average = null;
            int numericCount = 0;
            QueryResultTableCalcInfo queryResultTableCalcInfo = null;
            StatusLineContrItem statusCont = LayoutManager.getInstance().getStatusLineContrItem();
            if (count > 1) {
                for (Point p : event.selectedArray) {
                    TableColumn column = result.tblResult.getColumn(p.x);
                    if (column == null) {
                        continue;
                    }
                    ColumnInfo columnInfo = (ColumnInfo) column.getData();
                    if (columnInfo == null) {
                        continue;
                    }
                    String dataType = columnInfo.getType();
                    if (!DataType.isNumberType(dataType)) {
                        continue;
                    }
                    TableItem item = result.tblResult.getItem(p.y);
                    if (item == null || item.getData() == null) {
                        continue;
                    }
                    Map<String, CellValue> dataMap = (Map<String, CellValue>) item.getData();
                    CellValue cellValue = dataMap.get(Integer.toString(p.x));
                    if (cellValue != null && cellValue.getValue() != null) {
                        numericCount++;
                        Object value = cellValue.getValue();
                        if (value instanceof Integer) {
                            sum = sum.add(new BigDecimal((Integer) value));
                        } else if (value instanceof Short) {
                            sum = sum.add(new BigDecimal((Short) value));
                        } else if (value instanceof Long) {
                            sum = sum.add(new BigDecimal((Long) value));
                        } else if (value instanceof Float) {
                            sum = sum.add(new BigDecimal((Float) value));
                        } else if (value instanceof Double) {
                            sum = sum.add(new BigDecimal((Double) value));
                        } else if (value instanceof BigDecimal) {
                            sum = sum.add((BigDecimal) value);
                        }
                    }
                }
                if (numericCount > 0) {
                    average = sum.divide(new BigDecimal(numericCount), 3, RoundingMode.HALF_UP);
                    queryResultTableCalcInfo = new QueryResultTableCalcInfo(count, average, sum);
                } else {
                    queryResultTableCalcInfo = new QueryResultTableCalcInfo(count);
                }
            }
            queryTableTabItem.setQueryResultTableCalcInfo(queryResultTableCalcInfo);
            InfoWindowManager.getInstance().updateContent(editor);
            statusCont.changeStuatusLineForViewOrEditPart(editor.getSelectedDatabase(), editor);
        }
    });
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) CTabItem(org.eclipse.swt.custom.CTabItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) CellValue(com.cubrid.common.ui.spi.table.CellValue) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) StatusLineContrItem(com.cubrid.common.ui.spi.contribution.StatusLineContrItem) StyledText(org.eclipse.swt.custom.StyledText) ParamSetException(com.cubrid.common.ui.spi.util.paramSetter.ParamSetException) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) SelectionChangeEvent(com.cubrid.common.ui.spi.table.SelectionChangeEvent) ViewForm(org.eclipse.swt.custom.ViewForm) QueryResultTableCalcInfo(com.cubrid.common.ui.query.editor.QueryResultTableCalcInfo) ExportQueryResultDialog(com.cubrid.common.ui.query.dialog.ExportQueryResultDialog) FocusListener(org.eclipse.swt.events.FocusListener) Map(java.util.Map) SelectionListener(org.eclipse.swt.events.SelectionListener) DisposeListener(org.eclipse.swt.events.DisposeListener) TableCursor(org.eclipse.swt.custom.TableCursor) SQLException(java.sql.SQLException) ToolBarManager(org.eclipse.jface.action.ToolBarManager) ToolItem(org.eclipse.swt.widgets.ToolItem) FormLayout(org.eclipse.swt.layout.FormLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) QueryTableTabItem(com.cubrid.common.ui.query.editor.QueryTableTabItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) BigDecimal(java.math.BigDecimal) SashForm(org.eclipse.swt.custom.SashForm) TableSelectSupport(com.cubrid.common.ui.spi.table.TableSelectSupport) ToolBar(org.eclipse.swt.widgets.ToolBar) ISelectionChangeListener(com.cubrid.common.ui.spi.table.ISelectionChangeListener)

Aggregations

ToolBarManager (org.eclipse.jface.action.ToolBarManager)25 GridData (org.eclipse.swt.layout.GridData)15 GridLayout (org.eclipse.swt.layout.GridLayout)13 ToolBar (org.eclipse.swt.widgets.ToolBar)12 Composite (org.eclipse.swt.widgets.Composite)11 IToolBarManager (org.eclipse.jface.action.IToolBarManager)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 Button (org.eclipse.swt.widgets.Button)6 ToolBarContributionItem (org.eclipse.jface.action.ToolBarContributionItem)4 Label (org.eclipse.swt.widgets.Label)4 Action (org.eclipse.jface.action.Action)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 DisposeEvent (org.eclipse.swt.events.DisposeEvent)3 DisposeListener (org.eclipse.swt.events.DisposeListener)3 ArrayList (java.util.ArrayList)2 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)2 IAction (org.eclipse.jface.action.IAction)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2