Example usage for org.eclipse.jface.dialogs MessageDialog openConfirm

List of usage examples for org.eclipse.jface.dialogs MessageDialog openConfirm

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog openConfirm.

Prototype

public static boolean openConfirm(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple confirm (OK/Cancel) dialog.

Usage

From source file:com.hangum.tadpole.manager.core.editor.transaction.connection.TransactionConnectionListEditor.java

License:Open Source License

/**
 * create transaction composite//from  ww w  .  j av  a2  s  . c o  m
 * 
 * @param compositeTransactionConnection
 */
private void createTransactionComposite(Composite compositeTransactionConnection) {
    Composite compositeToolbar = new Composite(compositeTransactionConnection, SWT.NONE);
    compositeToolbar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_compositeToolbar = new GridLayout(1, false);
    gl_compositeToolbar.verticalSpacing = 1;
    gl_compositeToolbar.horizontalSpacing = 1;
    gl_compositeToolbar.marginHeight = 1;
    gl_compositeToolbar.marginWidth = 1;
    compositeToolbar.setLayout(gl_compositeToolbar);

    ToolBar toolBar = new ToolBar(compositeToolbar, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    ToolItem tltmRefresh = new ToolItem(toolBar, SWT.NONE);
    tltmRefresh.setImage(ImageUtils.getRefresh());
    tltmRefresh.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            initTransactionUI();
        }
    });
    tltmRefresh.setToolTipText("Refresh");

    tltmCommit = new ToolItem(toolBar, SWT.NONE);
    tltmCommit.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!tableViewer.getSelection().isEmpty()) {
                if (!MessageDialog.openConfirm(null, "Confirm", "Do you want DB Commit?"))
                    return;

                executTransaction(true);
            }
        }
    });
    tltmCommit.setEnabled(false);
    tltmCommit.setText("Commit");

    tltmRollback = new ToolItem(toolBar, SWT.NONE);
    tltmRollback.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!tableViewer.getSelection().isEmpty()) {
                if (!MessageDialog.openConfirm(null, "Confirm", "Do you want DB Rollback?"))
                    return;

                executTransaction(false);
            }
        }
    });
    tltmRollback.setEnabled(false);
    tltmRollback.setText("Rollback");

    Composite compositeBody = new Composite(compositeTransactionConnection, SWT.NONE);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    GridLayout gl_compositeBody = new GridLayout(1, false);
    gl_compositeBody.verticalSpacing = 1;
    gl_compositeBody.horizontalSpacing = 1;
    gl_compositeBody.marginHeight = 1;
    gl_compositeBody.marginWidth = 1;
    compositeBody.setLayout(gl_compositeBody);

    tableViewer = new TableViewer(compositeBody, SWT.BORDER | SWT.FULL_SELECTION);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            transactionBtnInit(true);
        }
    });
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    // sorter
    tableComparator = new TransactioonTableComparator();
    tableViewer.setSorter(tableComparator);
    tableComparator.setColumn(0);

    createColumns();

    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setLabelProvider(new TransactionConnectionListLabelProvider());

    initTransactionUI();
}

From source file:com.hangum.tadpole.mongodb.core.composite.result.MongodbResultComposite.java

License:Open Source License

/**
 * document del - tree/* ww w.  j a  va  2  s .c  o  m*/
 */
private void deleteDocumentTree() {
    IStructuredSelection iss = (IStructuredSelection) treeViewerMongo.getSelection();
    if (iss.isEmpty()) {
        MessageDialog.openError(null, Messages.MongodbResultComposite_9, Messages.MongodbResultComposite_10);
        return;
    } else if (MessageDialog.openConfirm(null, Messages.MongodbResultComposite_9,
            Messages.MongodbResultComposite_12)) {

        MongodbTreeViewDTO dto = (MongodbTreeViewDTO) iss.getFirstElement();
        if (logger.isDebugEnabled())
            logger.info("[delete object id is]" + dto.getDbObject().toString()); //$NON-NLS-1$

        try {
            MongoDBQuery.deleteDocument(userDB, collectionName, dto.getDbObject());
            find();
        } catch (Exception e) {
            logger.error(collectionName + " collection document remove object id is" + dto.getDbObject(), e); //$NON-NLS-1$
            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(null, "Error", "Document remove", errStatus); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
}

From source file:com.hangum.tadpole.mongodb.core.composite.result.MongodbResultComposite.java

License:Open Source License

/**
 * document del - table/* w ww  .  ja v  a2  s .c  o m*/
 */
private void deleteDocumentTable() {
    IStructuredSelection iss = (IStructuredSelection) resultTableViewer.getSelection();
    if (iss.isEmpty()) {
        MessageDialog.openError(null, Messages.MongodbResultComposite_9, Messages.MongodbResultComposite_10);
        return;
    } else if (MessageDialog.openConfirm(null, Messages.MongodbResultComposite_9,
            Messages.MongodbResultComposite_12)) {
        HashMap<Integer, Object> rsResult = (HashMap<Integer, Object>) iss.getFirstElement();
        Object dbObject = rsResult.get(MongoDBDefine.PRIMARY_ID_KEY);

        try {
            MongoDBQuery.deleteDocument(userDB, collectionName, (DBObject) dbObject);
            find();
        } catch (Exception e) {
            logger.error(collectionName + " collection document remove object id is" + dbObject, e); //$NON-NLS-1$
            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(null, "Error", "Document remove", errStatus); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
}

From source file:com.hangum.tadpole.mongodb.core.dialogs.collection.CollectionCompactDialog.java

License:Open Source License

@Override
protected void okPressed() {
    if (!NumberUtils.isNumber(textPaddingFactor.getText())) {
        MessageDialog.openError(null, "Error", "padding factor is number.");
        textPaddingFactor.setFocus();/*from   w ww  .j  a v  a  2s. com*/
        return;
    }
    if (!NumberUtils.isNumber(textPaddingBytes.getText())) {
        MessageDialog.openError(null, "Error", "padding Bytes is number.");
        textPaddingBytes.setFocus();
        return;
    }

    if (MessageDialog.openConfirm(null, "Question?",
            "Are you sure you want to run this command?  It can potentially lock the db for a long time.")) {
        try {
            String retMsg = MongoDBQuery.collCompact(userDB, collName, btnForce.getSelection(),
                    NumberUtils.createInteger(textPaddingFactor.getText()),
                    NumberUtils.createInteger(textPaddingBytes.getText()));

            MessageDialog.openInformation(null, "Successful", "Compact success");

        } catch (Exception e) {
            logger.error("mongodb compact" + collName, e); //$NON-NLS-1$
            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(null, "Error", "Collection compact Exception", errStatus); //$NON-NLS-1$ //$NON-NLS-2$

            return;
        }
    }

    super.okPressed();
}

From source file:com.hangum.tadpole.mongodb.core.dialogs.collection.FindAndModifyDialog.java

License:Open Source License

@Override
protected void okPressed() {
    if (!MessageDialog.openConfirm(null, "Confirm", "Are you want to execute?"))
        return;// w ww .j  a va2 s. c  om
    DBObject objQuery = null;
    DBObject objFields = null;
    DBObject objSort = null;
    DBObject objUpdate = null;

    try {
        objQuery = "".equals(textQuery.getText()) ? null : (DBObject) JSON.parse(textQuery.getText());
    } catch (Exception e) {
        textQuery.setFocus();
        MessageDialog.openError(null, "Error",
                e.getMessage() + PublicTadpoleDefine.LINE_SEPARATOR + "{Query} is error.");
        return;
    }

    try {
        objFields = "".equals(textFields.getText()) ? null : (DBObject) JSON.parse(textFields.getText());
    } catch (Exception e) {
        textFields.setFocus();
        MessageDialog.openError(null, "Error",
                e.getMessage() + PublicTadpoleDefine.LINE_SEPARATOR + "{Field} is error.");
        return;
    }

    try {
        objSort = "".equals(textSort.getText()) ? null : (DBObject) JSON.parse(textSort.getText());
    } catch (Exception e) {
        textSort.setFocus();
        MessageDialog.openError(null, "Error",
                e.getMessage() + PublicTadpoleDefine.LINE_SEPARATOR + "{Sort} is error.");
        return;
    }

    try {
        objUpdate = "".equals(textUpdate.getText()) ? null : (DBObject) JSON.parse(textUpdate.getText());
    } catch (Exception e) {
        textUpdate.setFocus();
        MessageDialog.openError(null, "Error",
                e.getMessage() + PublicTadpoleDefine.LINE_SEPARATOR + "{Update} is error.");
        return;
    }

    try {
        DBObject retDBObj = MongoDBQuery.findAndModify(userDB, collName, objQuery, objSort, objFields,
                btnRemove.getSelection(), objUpdate, btnReturnNew.getSelection(), btnUpsert.getSelection());
        if (null != retDBObj) {
            FindOneDetailDialog resultViewDialog = new FindOneDetailDialog(null, userDB,
                    "Update Result Message", retDBObj);
            resultViewDialog.open();
        } else
            MessageDialog.openInformation(null, "Result", "Result message is null");

    } catch (Exception e) {
        logger.error("mongodb FindAndModify", e); //$NON-NLS-1$
        Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
        ExceptionDetailsErrorDialog.openError(null, "Error", "FindAndModify Exception", errStatus); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:com.hangum.tadpole.mongodb.core.dialogs.users.UserManagerDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    if (APPEND_USER_ID == buttonId) {
        String id = textID.getText().trim();
        String passwd = textPassword.getText().trim();
        String passwd2 = textRePassword.getText().trim();
        boolean isReadOnly = btnReadOnly.getSelection();

        if ("".equals(id)) { //$NON-NLS-1$
            MessageDialog.openError(null, "Error", Messages.UserManagerDialog_11); //$NON-NLS-1$
            textID.setFocus();/*from   w w  w. java  2 s .  c  o  m*/
            return;
        } else if ("".equals(passwd)) { //$NON-NLS-1$
            MessageDialog.openError(null, "Error", Messages.UserManagerDialog_14); //$NON-NLS-1$
            textPassword.setFocus();
            return;
        } else if ("".equals(passwd2)) { //$NON-NLS-1$
            MessageDialog.openError(null, "Error", Messages.UserManagerDialog_17); //$NON-NLS-1$
            textRePassword.setFocus();
            return;
        } else if (!passwd.equals(passwd2)) {
            MessageDialog.openError(null, "Error", Messages.UserManagerDialog_19); //$NON-NLS-1$
            textPassword.setFocus();
            return;
        }

        try {
            MongoDBQuery.addUser(userDB, id, passwd2, isReadOnly);

            initTable();
        } catch (Exception e) {
            logger.error("mongodb add user", e); //$NON-NLS-1$

            Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
            ExceptionDetailsErrorDialog.openError(null, "Error", "Add User Exception", errStatus); //$NON-NLS-1$ //$NON-NLS-2$

            return;
        }
    } else if (buttonId == DELETE_ID) {
        IStructuredSelection is = (IStructuredSelection) tableViewerUser.getSelection();
        Object selElement = is.getFirstElement();

        if (selElement instanceof UserDTO) {
            if (MessageDialog.openConfirm(null, "Confirm", Messages.UserManagerDialog_22)) { //$NON-NLS-1$
                UserDTO user = (UserDTO) selElement;
                try {
                    MongoDBQuery.deleteUser(userDB, user.getId());

                    listUser.remove(user);
                    tableViewerUser.refresh();
                } catch (Exception e1) {
                    logger.error("mongodb delete user", e1); //$NON-NLS-1$

                    Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1); //$NON-NLS-1$
                    ExceptionDetailsErrorDialog.openError(null, "Error", "Delete User Exception", errStatus); //$NON-NLS-1$ //$NON-NLS-2$
                }
            }
        } else {
            MessageDialog.openError(null, "Confirm", "  ? ? .");
        }
    } else if (buttonId == IDialogConstants.CANCEL_ID) {
        super.cancelPressed();
    }

}

From source file:com.hangum.tadpole.mongodb.core.ext.editors.javascript.ServerSideJavaScriptEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout gl_parent = new GridLayout(1, false);
    gl_parent.verticalSpacing = 2;//from  ww  w .ja va2 s  . c o  m
    gl_parent.horizontalSpacing = 2;
    gl_parent.marginHeight = 2;
    gl_parent.marginWidth = 2;
    parent.setLayout(gl_parent);

    SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Composite compositeBody = new Composite(sashForm, SWT.NONE);
    GridLayout gl_compositeBody = new GridLayout(1, false);
    gl_compositeBody.verticalSpacing = 1;
    gl_compositeBody.horizontalSpacing = 1;
    gl_compositeBody.marginHeight = 1;
    gl_compositeBody.marginWidth = 1;
    compositeBody.setLayout(gl_compositeBody);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    ToolBar toolBar = new ToolBar(compositeBody, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    // Shortcut prefix
    String prefixOSShortcut = ShortcutPrefixUtils.getCtrlShortcut();

    ToolItem tltmConnectURL = new ToolItem(toolBar, SWT.NONE);
    tltmConnectURL.setImage(
            ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/connect.png"));
    tltmConnectURL.setToolTipText("Connection Info"); //$NON-NLS-1$
    if (PermissionChecker.isShow(SessionManager.getRoleType(userDB))) {
        tltmConnectURL.setText("Connect [ " + userDB.getHost() + ":" + userDB.getDb() + " ]"); //$NON-NLS-1$
    } else {
        tltmConnectURL.setText("Connect Information"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    tltmConnectURL.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            DBInformationDialog dialog = new DBInformationDialog(
                    PlatformUI.getWorkbench().getDisplay().getActiveShell(), userDB);
            dialog.open();

            setFocus();
        }
    });

    new ToolItem(toolBar, SWT.SEPARATOR);

    ToolItem tltmExecute = new ToolItem(toolBar, SWT.NONE);
    tltmExecute.setToolTipText(String.format(Messages.MainEditor_tltmExecute_toolTipText_1, prefixOSShortcut));
    tltmExecute.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID,
            "resources/icons/mongodb/mongo-executable.png"));
    tltmExecute.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                String strContent = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
                executeEval(strContent);
            } catch (Exception ee) {
                logger.error("Execute JS", ee);
            }
        }
    });

    new ToolItem(toolBar, SWT.SEPARATOR);

    ToolItem tltmDownload = new ToolItem(toolBar, SWT.NONE);
    tltmDownload.setImage(
            ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/download_query.png"));
    tltmDownload.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!MessageDialog.openConfirm(null, "Conforim", "Do you want SQL Download?"))
                return;

            try {
                String strJSContent = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
                downloadJavaScript(getUserDB().getDisplay_name() + ".js", strJSContent);
            } catch (Exception ee) {
                logger.error("Download JS", ee);
            }
        }
    });
    tltmDownload.setToolTipText("Download JavaScript"); //$NON-NLS-1$

    new ToolItem(toolBar, SWT.SEPARATOR);

    ToolItem tltmHelp = new ToolItem(toolBar, SWT.NONE);
    tltmHelp.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/about.png"));
    tltmHelp.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            MongoDBShortcutHelpDialog dialog = new MongoDBShortcutHelpDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.NONE);
            dialog.open();

            setFocus();
        }
    });
    tltmHelp.setToolTipText("Editor Shortcut Help"); //$NON-NLS-1$

    browserQueryEditor = new Browser(compositeBody, SWT.BORDER);
    browserQueryEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    addBrowserService();

    Composite compositeTail = new Composite(sashForm, SWT.NONE);
    compositeTail.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gl_compositeTail = new GridLayout(1, false);
    gl_compositeTail.verticalSpacing = 1;
    gl_compositeTail.horizontalSpacing = 1;
    gl_compositeTail.marginHeight = 1;
    gl_compositeTail.marginWidth = 1;
    compositeTail.setLayout(gl_compositeTail);

    tabFolder = new CTabFolder(compositeTail, SWT.BORDER);
    tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tabFolder.setSelectionBackground(
            Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));

    CTabItem tbtmEvalJavaScript = new CTabItem(tabFolder, SWT.NONE);
    tbtmEvalJavaScript.setText(Messages.ServerSideJavaScriptEditor_tbtmEvalJavaScript_text_1);

    Composite compositeTabJS = new Composite(tabFolder, SWT.NONE);
    tbtmEvalJavaScript.setControl(compositeTabJS);
    GridLayout gl_compositeTabJS = new GridLayout(1, false);
    gl_compositeTabJS.verticalSpacing = 1;
    gl_compositeTabJS.horizontalSpacing = 1;
    gl_compositeTabJS.marginHeight = 1;
    gl_compositeTabJS.marginWidth = 1;
    compositeTabJS.setLayout(gl_compositeTabJS);

    textResultJavaScript = new Text(compositeTabJS,
            SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    textResultJavaScript.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    compositeDumy = new Composite(compositeTabJS, SWT.NONE);
    compositeDumy.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    compositeDumy.setLayout(new GridLayout(1, false));

    sashForm.setWeights(new int[] { 7, 3 });

    initEditor();
}

From source file:com.hangum.tadpole.monitoring.core.dialogs.schedule.AddScheduleDialog.java

License:Open Source License

/**
 * Create contents of the dialog.//from  www  .j ava 2 s.com
 * @param parent
 */
@Override
protected Control createDialogArea(final Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = (GridLayout) container.getLayout();
    gridLayout.verticalSpacing = 5;
    gridLayout.horizontalSpacing = 5;
    gridLayout.marginHeight = 5;
    gridLayout.marginWidth = 5;

    Composite compositeHead = new Composite(container, SWT.BORDER);
    compositeHead.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    compositeHead.setLayout(new GridLayout(3, false));

    Label lblTitle = new Label(compositeHead, SWT.NONE);
    lblTitle.setText(Messages.AddScheduleDialog_0);

    textTitle = new Text(compositeHead, SWT.BORDER);
    textTitle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(compositeHead, SWT.NONE);

    Label lblDescription = new Label(compositeHead, SWT.NONE);
    lblDescription.setText(Messages.AddScheduleDialog_1);

    textDescription = new Text(compositeHead, SWT.BORDER);
    textDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(compositeHead, SWT.NONE);

    Label lblCronExpression = new Label(compositeHead, SWT.NONE);
    lblCronExpression.setText("<a href='http://www.cronmaker.com/' target='_blank'>Cron Expression</a>"); //$NON-NLS-1$
    lblCronExpression.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);

    textCronExp = new Text(compositeHead, SWT.BORDER);
    textCronExp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Button btnViewSchedule = new Button(compositeHead, SWT.NONE);
    btnViewSchedule.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            showExp();
        }
    });
    btnViewSchedule.setText(Messages.AddScheduleDialog_3);
    new Label(compositeHead, SWT.NONE);

    textViewSchedule = new Text(compositeHead, SWT.BORDER | SWT.MULTI);
    GridData gd_textViewSchedule = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd_textViewSchedule.heightHint = 60;
    textViewSchedule.setLayoutData(gd_textViewSchedule);

    Composite compositeBody = new Composite(container, SWT.BORDER);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    compositeBody.setLayout(new GridLayout(1, false));

    ToolBar toolBar = new ToolBar(compositeBody, SWT.FLAT | SWT.RIGHT);

    final ToolItem tltmAdd = new ToolItem(toolBar, SWT.NONE);
    tltmAdd.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            AddSQLDialog dialog = new AddSQLDialog(parent.getShell(), listSchedule.size());
            if (Dialog.OK == dialog.open()) {
                listSchedule.add(dialog.getDao());

                tableViewer.refresh();
            }
        }
    });
    tltmAdd.setText(Messages.AddScheduleDialog_4);

    tltmModify = new ToolItem(toolBar, SWT.NONE);
    tltmModify.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection iss = (IStructuredSelection) tableViewer.getSelection();
            if (!iss.isEmpty()) {
                ScheduleDAO dao = (ScheduleDAO) iss.getFirstElement();
                AddSQLDialog dialog = new AddSQLDialog(null, dao);
                if (Dialog.OK == dialog.open()) {
                    tableViewer.refresh(dialog.getDao());
                }
            }
        }
    });
    tltmModify.setEnabled(false);
    tltmModify.setText(Messages.AddScheduleDialog_5);

    tltmDelete = new ToolItem(toolBar, SWT.NONE);
    tltmDelete.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection iss = (IStructuredSelection) tableViewer.getSelection();
            if (!iss.isEmpty()) {
                if (!MessageDialog.openConfirm(null, Messages.AddScheduleDialog_20,
                        Messages.AddScheduleDialog_7))
                    return;

                ScheduleDAO dao = (ScheduleDAO) iss.getFirstElement();
                listSchedule.remove(dao);
                tableViewer.refresh();
            }
        }
    });
    tltmDelete.setEnabled(false);
    tltmDelete.setText(Messages.AddScheduleDialog_8);

    tableViewer = new TableViewer(compositeBody, SWT.BORDER | SWT.FULL_SELECTION);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            tltmModify.setEnabled(true);
            tltmDelete.setEnabled(true);
        }
    });
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    tableViewerColumn.setEditingSupport(new SQLOrderEditingSupport(tableViewer));
    TableColumn tblclmnSeq = tableViewerColumn.getColumn();
    tblclmnSeq.setWidth(50);

    TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnTitle = tableViewerColumn_1.getColumn();
    tblclmnTitle.setWidth(100);
    tblclmnTitle.setText(Messages.AddScheduleDialog_9);

    TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnSql = tableViewerColumn_2.getColumn();
    tblclmnSql.setWidth(273);
    tblclmnSql.setText(Messages.AddScheduleDialog_10);

    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    tableViewer.setLabelProvider(new AddScheduleLableProvider());
    tableViewer.setInput(listSchedule);

    initData();

    return container;
}

From source file:com.hangum.tadpole.monitoring.core.dialogs.schedule.AddScheduleDialog.java

License:Open Source License

@Override
protected void okPressed() {
    String txtTitle = StringUtils.trim(textTitle.getText());
    String txtDescription = StringUtils.trim(textDescription.getText());
    String txtCronExp = StringUtils.trim(textCronExp.getText());

    if (StringUtils.isEmpty(txtTitle)) {
        MessageDialog.openError(null, Messages.AddScheduleDialog_14, Messages.AddScheduleDialog_15);
        textTitle.setFocus();//w  w w  .j a va  2 s.  c o  m
        return;
    }

    if (!CronExpression.isValidExpression(txtCronExp)) {
        MessageDialog.openError(null, Messages.AddScheduleDialog_16, Messages.AddScheduleDialog_17);
        textCronExp.setFocus();
        return;
    }

    if (listSchedule.size() == 0) {
        MessageDialog.openError(null, Messages.AddScheduleDialog_16, Messages.AddScheduleDialog_19);
        return;
    }

    // ?? .
    if (scheduleDao == null) {
        try {
            if (!MessageDialog.openConfirm(null, Messages.AddScheduleDialog_20, Messages.AddScheduleDialog_21))
                return;
            ScheduleMainDAO dao = TadpoleSystem_Schedule.addSchedule(userDB, txtTitle, txtDescription,
                    txtCronExp, listSchedule);

            // cron manager ?.
            Date nextJob = ScheduleManager.getInstance().newJob(userDB, dao);

            MessageDialog.openInformation(null, Messages.AddScheduleDialog_20,
                    Messages.AddScheduleDialog_23 + convPretty(nextJob));

        } catch (Exception e) {
            logger.error("save schedule", e); //$NON-NLS-1$
            MessageDialog.openError(null, Messages.AddScheduleDialog_25, e.getMessage());
            return;
        }
        // ?? .
    } else {
        try {
            if (!MessageDialog.openConfirm(null, Messages.AddScheduleDialog_20,
                    "?? ?"))
                return;

            // remove job
            ScheduleManager.getInstance().deleteJob(userDB, scheduleDao);

            scheduleDao.setTitle(txtTitle);
            scheduleDao.setDescription(txtDescription);
            scheduleDao.setCron_exp(txtCronExp);

            TadpoleSystem_Schedule.modifySchedule(userDB, scheduleDao, listSchedule);

            // cron manager ?.
            Date nextJob = ScheduleManager.getInstance().newJob(userDB, scheduleDao);

            MessageDialog.openInformation(null, Messages.AddScheduleDialog_20,
                    Messages.AddScheduleDialog_23 + convPretty(nextJob));

        } catch (Exception e) {
            logger.error("save schedule", e); //$NON-NLS-1$
            MessageDialog.openError(null, Messages.AddScheduleDialog_25, e.getMessage());
            return;
        }
    }

    super.okPressed();
}

From source file:com.hangum.tadpole.notes.core.dialogs.NewNoteDialog.java

License:Open Source License

@Override
protected void okPressed() {
    // ? .//from   w ww .  j ava2s.  c o m
    String strSender = comboUserName.getText();
    if ("".equals(strSender)) { //$NON-NLS-1$
        MessageDialog.openConfirm(null, Messages.NewNoteDialog_0, Messages.NewNoteDialog_5);
        comboUserName.setFocus();
        return;
    }
    UserDAO userDao = null;
    try {
        userDao = TadpoleSystem_UserQuery.findUser(strSender);
    } catch (Exception e) {
        MessageDialog.openError(null, Messages.NewNoteDialog_0, e.getMessage());
        return;
    }

    // ? .
    String strTitle = textTitle.getText();
    if ("".equals(strTitle)) {
        MessageDialog.openConfirm(null, Messages.NewNoteDialog_0, Messages.NewNoteDialog_8);
        textTitle.setFocus();
        return;
    }

    //  .
    String strContent = textContent.getText();
    if ("".equals(strContent)) {
        MessageDialog.openConfirm(null, Messages.NewNoteDialog_0, Messages.NewNoteDialog_11);
        textContent.setFocus();
        return;
    }

    // find receive seq
    try {
        // User data save
        TadpoleSystem_Notes.saveNote(comboTypes.getText(), listAlluser, SessionManager.getSeq(),
                userDao.getSeq(), strTitle, strContent);
    } catch (Exception e) {
        logger.error("note save", e); //$NON-NLS-1$
        MessageDialog.openError(null, Messages.NewNoteDialog_0, e.getMessage());
        return;
    }

    super.okPressed();
}