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.safi.workshop.sqlexplorer.plugin.SQLExplorerPlugin.java

License:Open Source License

@SuppressWarnings("unchecked")
public void updateDBResource(ManagedDriver md) {
    DBDriver oldDriver = md.getDriver();
    if (oldDriver.getLastUpdated() == null)
        return;// w  ww .jav  a  2s .  c o  m
    DBResource newVersion = null;
    try {
        newVersion = DBManager.getInstance().updateDBResource(safiDriverManager, oldDriver);
    } catch (DBManagerException e) {
        e.printStackTrace();
        MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Update Error",
                "Couldn't update DB Driver: " + e.getLocalizedMessage());
        AsteriskDiagramEditorPlugin.getInstance().logError("Couldn't update Driver", e);
        return;
    }
    if (oldDriver == newVersion) {
        MessageDialog.openInformation(getWorkbench().getDisplay().getActiveShell(), "No changes",
                "There have been no changes to the selected resource");
        return;
    }
    if (newVersion == null) {
        boolean isModified = false;
        for (DBConnection conn : oldDriver.getConnections()) {
            if (conn.getLastUpdated() == null || conn.getLastModified().compareTo(conn.getLastUpdated()) >= 0) {
                isModified = true;
                break;
            }
        }
        if (isModified) {
            boolean ok = MessageDialog.openConfirm(getWorkbench().getDisplay().getActiveShell(),
                    "Resource Deleted",
                    "The selected resource " + md.getId() + " has been renamed or deleted but\n"
                            + "one or more child connections have been modified.  Press 'OK' to continue or 'Cancel' \nto keep your changes ");
            if (!ok) {
                disconnectChildren(oldDriver);
                return;
            }
        }

        // try {
        // removes the driver from the Safi Model AND DbNav model
        SQLExplorerPlugin.getDefault().getDriverModel().removeDriver(md);
        // } catch (Exception e) {
        // e.printStackTrace();
        // }
    } else if (newVersion != oldDriver) {
        ArrayList<Alias> existingAliases = new ArrayList<Alias>();
        for (Alias a : SQLExplorerPlugin.getDefault().getAliasManager().getAliases()) {
            if (md.equals(a.getDriver()))
                existingAliases.add(a);
        }
        DBDriver newDriver = (DBDriver) newVersion;
        try {
            DBManager.getInstance().copyProperties(oldDriver, newDriver, false);
        } catch (DBManagerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            MessageDialog.openError(getWorkbench().getDisplay().getActiveShell(), "Name Conflict",
                    e.getLocalizedMessage());
        }
        Date now = new Date();

        // newDriver.setLastModified(now);
        // newDriver.setLastUpdated(now);
        oldDriver.setLastUpdated(now);
        DBManager.touchChildren(oldDriver, now);
        // ArrayList<Integer> locals = new ArrayList<Integer>();
        // ArrayList<Alias> cloned = (ArrayList<Alias>) existingAliases.clone();
        // for (Alias a : cloned) {
        // DBConnection conn = (DBConnection) a.getConnection();
        // if (conn.getLastUpdated() == null || conn.getId() == -1) {
        // existingAliases.remove(a);
        // }
        // else {
        // locals.add(conn.getId());
        // }
        // }
        //      
        //      
        // SQLExplorerPlugin.getDefault().getAliasManager().removeAll(existingAliases,
        // false);
        // DBManager.getInstance().copyProperties(oldDriver, newDriver, false);
        // for (DBConnection conn : newDriver.getConnections()){
        // int id = conn.getId();
        // if (locals.contains(id)){
        // Alias a = new Alias(conn);
        // }
        // }
        // // replace the old DBDriver with the new on in the EObject tree
        // // EcoreUtil.replace(md.getDriver(), newDriver);
        // // SQLExplorerPlugin.getDefault().getAliasManager().removeAll(existingAliases,
        // false);
        // // set the new DBDriver
        // // md.setDriver(newDriver);
        // // SQLExplorerPlugin.getDefault().getDriverModel().addDriver(md, false);
        // for (Alias a : existingAliases) {
        //        
        // DBConnection connection = newDriver.getConnection(a.getName());
        // if (connection != null){
        // oldDriver.getConnections().add(connection);
        // SQLExplorerPlugin.getDefault().getAliasManager().addAlias(a, false);
        // }
        //        
        // }
        // SQLExplorerPlugin.getDefault().getAliasManager().removeAll(existingAliases,
        // false);
        // List<DBConnection> copied = new
        // ArrayList<DBConnection>(newDriver.getConnections());
        // for (DBConnection c : copied) {
        // if (!locals.contains(c.getId())){
        // newDriver.getConnections().remove(c);
        // continue;
        // }
        // c.setLastUpdated(now);
        //        
        // try {
        // Alias alias = new Alias(c);
        // SQLExplorerPlugin.getDefault().getAliasManager().addAlias(alias, false);
        // } catch (ExplorerException e) {
        // e.printStackTrace();
        // }
        // for (Query q : c.getQueries()) {
        // q.setLastUpdated(now);
        //  
        // }
        // }
        // EcoreUtil.replace(oldDriver, newVersion);
    }

    SafiWorkshopEditorUtil.getSafiNavigator().modelChanged(SafiServerPlugin.getDefault().isConnected());

}

From source file:com.safi.workshop.sqlexplorer.plugin.SQLExplorerPlugin.java

License:Open Source License

private void saveDBResourceHelper(DBResource resource)
        throws IOException, DBResourceException, ResourceModifiedException, DBManagerException {

    try {//from  ww  w .j  a  va  2  s .  c o m
        DBManager.getInstance().saveDBResourceHierarchy(resource);
    } catch (ResourceModifiedException e) {
        boolean ok = MessageDialog.openConfirm(getWorkbench().getDisplay().getActiveShell(),
                "Resource Modified", e.getLocalizedMessage() + ".\nWould you like to commit anyway?");
        if (ok) {
            resource.setLastUpdated(resource.getLastModified());
            DBManager.getInstance().saveDBResourceHierarchy(resource);
        } else
            throw e;
    }
}

From source file:com.safi.workshop.sqlexplorer.plugin.SQLExplorerPlugin.java

License:Open Source License

public void deleteDBResource(DBResource resource)
        throws IOException, DBResourceException, ResourceModifiedException, DBManagerException {

    try {/*  w w  w  . j  a  v  a 2s  .c o m*/
        DBManager.getInstance().deleteDBResource(resource);
    } catch (ResourceModifiedException e) {
        boolean ok = MessageDialog.openConfirm(getWorkbench().getDisplay().getActiveShell(),
                "Resource Modified", e.getLocalizedMessage() + ".\nWould you like to commit anyway?");
        if (ok) {
            resource.setLastUpdated(resource.getLastModified());
            DBManager.getInstance().deleteDBResource(resource);
        } else
            throw e;
    }
}

From source file:com.safi.workshop.sqlexplorer.preferences.DriverPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {

    noDefaultAndApplyButton();//from ww w. ja va  2 s . c o  m
    _driverModel = SQLExplorerPlugin.getDefault().getDriverModel();

    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
            SQLExplorerPlugin.PLUGIN_ID + ".DriverContainerGroup");

    _prefs = SQLExplorerPlugin.getDefault().getPreferenceStore();

    GridLayout parentLayout = new GridLayout(1, false);
    parentLayout.marginTop = parentLayout.marginBottom = 0;
    parentLayout.marginHeight = 0;
    parentLayout.verticalSpacing = 10;
    parent.setLayout(parentLayout);

    GridLayout layout;

    Composite myComposite = new Composite(parent, SWT.NONE);

    // Define layout.
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = 20;
    layout.verticalSpacing = 10;
    myComposite.setLayout(layout);

    myComposite.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));

    GridData gid = new GridData(GridData.FILL_BOTH);
    gid.grabExcessHorizontalSpace = gid.grabExcessVerticalSpace = true;
    gid.horizontalAlignment = gid.verticalAlignment = GridData.FILL;
    gid.verticalSpan = 6;
    _tableViewer = new TableViewer(myComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    _tableViewer.getControl().setLayoutData(gid);
    _tableViewer.setContentProvider(new DriverContentProvider());
    final DriverLabelProvider dlp = new DriverLabelProvider();
    _tableViewer.setLabelProvider(dlp);
    _tableViewer.getTable().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            dlp.dispose();
            if (_boldfont != null)
                _boldfont.dispose();

        }
    });
    _tableViewer.getTable().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            changeDriver();
        }
    });

    _tableViewer.setInput(_driverModel);
    selectFirst();
    final Table table = _tableViewer.getTable();

    myComposite.layout();
    parent.layout();

    // Add Buttons
    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button add = new Button(myComposite, SWT.PUSH);
    add.setText(Messages.getString("Preferences.Drivers.Button.Add"));
    add.setLayoutData(gid);
    add.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            CreateDriverDlg dlg = new CreateDriverDlg(getShell(), CreateDriverDlg.Type.CREATE, null);
            dlg.open();

            _tableViewer.refresh();
            selectFirst();
        }
    });

    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button edit = new Button(myComposite, SWT.PUSH);
    edit.setText(Messages.getString("Preferences.Drivers.Button.Edit"));
    edit.setLayoutData(gid);
    edit.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            changeDriver();
            _tableViewer.refresh();
        }
    });

    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button copy = new Button(myComposite, SWT.PUSH);
    copy.setText(Messages.getString("Preferences.Drivers.Button.Copy"));
    copy.setLayoutData(gid);
    copy.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            StructuredSelection sel = (StructuredSelection) _tableViewer.getSelection();
            ManagedDriver dv = (ManagedDriver) sel.getFirstElement();
            if (dv != null) {
                CreateDriverDlg dlg = new CreateDriverDlg(getShell(), CreateDriverDlg.Type.COPY, dv);
                dlg.open();
                _tableViewer.refresh();
            }
        }
    });

    gid = new GridData(GridData.FILL);
    gid.widthHint = 75;
    Button remove = new Button(myComposite, SWT.PUSH);
    remove.setText(Messages.getString("Preferences.Drivers.Button.Remove"));
    remove.setLayoutData(gid);
    remove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {

            boolean okToDelete = MessageDialog.openConfirm(getShell(),
                    Messages.getString("Preferences.Drivers.ConfirmDelete.Title"),
                    Messages.getString("Preferences.Drivers.ConfirmDelete.Prefix")
                            + _tableViewer.getTable().getSelection()[0].getText()
                            + Messages.getString("Preferences.Drivers.ConfirmDelete.Postfix"));
            if (okToDelete) {
                StructuredSelection sel = (StructuredSelection) _tableViewer.getSelection();
                ManagedDriver dv = (ManagedDriver) sel.getFirstElement();
                if (dv != null) {
                    if (dv.getDriver() != null && dv.getDriver().isDefault()) {
                        MessageDialog.openConfirm(getShell(), "Default Driver",
                                "This is a default driver and cannot be deleted");
                    } else {
                        _driverModel.removeDriver(dv);
                        _tableViewer.refresh();
                        selectFirst();
                    }
                }
            }
        }
    });

    gid = new GridData(GridData.FILL);
    gid.widthHint = 73;
    Button bdefault = new Button(myComposite, SWT.PUSH);
    bdefault.setText(Messages.getString("Preferences.Drivers.Button.Default"));
    bdefault.setLayoutData(gid);
    // Remove bold font on all elements, and make selected element bold
    bdefault.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (int i = 0; i < _tableViewer.getTable().getItemCount(); i++) {

                _tableViewer.getTable().getItem(i).setFont(0, table.getFont());
            }
            _boldfont = new Font(_tableViewer.getTable().getDisplay(), table.getFont().toString(),
                    table.getFont().getFontData()[0].getHeight(), SWT.BOLD);
            _tableViewer.getTable().getSelection()[0].setFont(0, _boldfont);
            _prefs.setValue(IConstants.DEFAULT_DRIVER, _tableViewer.getTable().getSelection()[0].getText());
        }
    });

    // add button to restore default drivers
    Button bRestore = new Button(parent, SWT.PUSH);
    bRestore.setText(Messages.getString("Preferences.Drivers.Button.RestoreDefault"));
    bRestore.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                _driverModel.restoreDrivers();
                _tableViewer.refresh();
                selectFirst();
            } catch (ExplorerException ex) {
                SQLExplorerPlugin.error("Cannot restore default driver configuration", ex);
            }
        }
    });

    bRestore.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));

    selectDefault(table);

    return parent;
}

From source file:com.salesforce.ide.core.internal.utils.Utils.java

License:Open Source License

public static boolean openConfirm(String pTitle, String pMessage) {
    return MessageDialog.openConfirm(getShell(), pTitle, pMessage);
}

From source file:com.salesforce.ide.core.internal.utils.Utils.java

License:Open Source License

public static boolean openConfirm(Shell shell, String pTitle, String pMessage) {
    return MessageDialog.openConfirm(shell, pTitle, pMessage);
}

From source file:com.sap.dirigible.ide.db.viewer.views.actions.DeleteTableAction.java

License:Open Source License

@SuppressWarnings("rawtypes")
public void run() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    TreeParent parent = null;//from   ww  w  .j  av a 2  s .co  m

    for (Iterator nextSelection = selection.iterator(); nextSelection.hasNext();) {
        Object obj = nextSelection.next();
        if (TreeObject.class.isInstance(obj)) {
            if (((TreeObject) obj).getTableDefinition() != null) {
                TableDefinition tableDefinition = ((TreeObject) obj).getTableDefinition();

                boolean confirm = MessageDialog.openConfirm(viewer.getControl().getShell(), DELETE_TABLE,
                        String.format(WARNING_THIS_ACTION_WILL_DELETE_THE_TABLE_AND_ALL_OF_ITS_CONTENT_CONTINUE,
                                tableDefinition.getTableName()));
                if (!confirm) {
                    continue;
                }
                parent = ((TreeObject) obj).getParent();
                IDbConnectionFactory connectionFactory = parent.getConnectionFactory();
                try {
                    deleteTable(tableDefinition, connectionFactory);
                } catch (SQLException e) {
                    showMessage(String.format(FAILED_TO_DELETE_TABLE_S, tableDefinition.getTableName()));
                    logger.error(e.getMessage(), e);
                }
            }
        }
    }
    if (parent != null) {
        RefreshViewAction refresh = new RefreshViewAction(viewer, parent.getChildren()[0]);
        refresh.run();
    }
}

From source file:com.sap.dirigible.ide.generic.ui.GenericListView.java

License:Open Source License

private void makeActions() {
    actionAddLocation = new Action() {
        private static final long serialVersionUID = -6534944336694980431L;

        public void run() {
            InputDialog dlg = new InputDialog(viewer.getControl().getShell(), ADD_LOCATION, URL, "http://", //$NON-NLS-1$
                    new UriValidator());
            if (dlg.open() == Window.OK) {
                try {
                    // TODO - parse for name
                    URI uri = new URI(dlg.getValue());
                    genericListManager.addLocation(getNameForLocation(uri), dlg.getValue());
                    viewer.refresh();/*from w  w w .  j a va 2s  . co m*/
                } catch (Exception e) {
                    logger.error(GENERIC_VIEW_ERROR, e);
                    MessageDialog.openError(viewer.getControl().getShell(), GENERIC_VIEW_ERROR, e.getMessage());
                }
            }
        }

        private String getNameForLocation(URI uri) throws IOException {
            String name = CommonUtils.replaceNonAlphaNumericCharacters(uri.getHost());
            String originalName = name;
            int i = 1;
            while (genericListManager.existsLocation(name)) {
                name = originalName + i++;
            }

            return name;
        }
    };
    actionAddLocation.setText(ADD_LOCATION);
    actionAddLocation.setToolTipText(ADD_LOCATION_TO_THE_GENERIC_VIEWS_LIST);
    actionAddLocation.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));

    actionRemoveLocation = new Action() {
        private static final long serialVersionUID = 1336014167502247774L;

        public void run() {

            if (!viewer.getSelection().isEmpty()) {
                StructuredSelection selection = (StructuredSelection) viewer.getSelection();
                GenericLocationMetadata location = (GenericLocationMetadata) selection.getFirstElement();
                if (MessageDialog.openConfirm(viewer.getControl().getShell(), REMOVE_LOCATION,
                        ARE_YOU_SURE_YOU_WANT_TO_REMOVE_THIS_LOCATION + location.getLocation())) {
                    try {
                        genericListManager.removeLocation(location.getName());
                        viewer.refresh();
                    } catch (Exception e) {
                        logger.error(GENERIC_VIEW_ERROR, e);
                        MessageDialog.openError(viewer.getControl().getShell(), GENERIC_VIEW_ERROR,
                                e.getMessage());
                    }
                }
            }
        }
    };
    actionRemoveLocation.setText(REMOVE_LOCATION);
    actionRemoveLocation.setToolTipText(REMOVE_LOCATION_FROM_THE_GENERIC_VIEWS_LIST);
    actionRemoveLocation.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE));

    actionOpenLocation = new Action() {
        private static final long serialVersionUID = 1336014167502247774L;

        public void run() {

            if (!viewer.getSelection().isEmpty()) {
                StructuredSelection selection = (StructuredSelection) viewer.getSelection();
                GenericLocationMetadata location = (GenericLocationMetadata) selection.getFirstElement();

                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                IWorkbenchPage page = win.getActivePage();
                String id = GenericPerspective.GENERIC_VIEW_ID;
                try {
                    IViewPart view = page.showView(id, location.getName(), IWorkbenchPage.VIEW_VISIBLE);
                    ((GenericView) view).setSiteUrl(location.getLocation());
                    ((GenericView) view).setViewTitle(location.getName());
                } catch (PartInitException e) {
                    logger.error(GENERIC_VIEW_ERROR, e);
                }

            }
        }
    };
    actionOpenLocation.setText(OPEN_LOCATION);
    actionOpenLocation.setToolTipText(OPEN_LOCATION_FROM_THE_GENERIC_VIEWS_LIST);
    actionOpenLocation.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEF_VIEW));

}

From source file:com.sap.dirigible.ide.jgit.command.ResetCommandHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    final IProject[] projects = CommandHandlerUtils.getProjects(selection, logger);

    if (projects.length == 0) {
        logger.warn(NO_PROJECT_IS_SELECTED_FOR_HARD_RESET);
        StatusLineManagerUtil.setWarningMessage(NO_PROJECT_IS_SELECTED_FOR_HARD_RESET);
        MessageDialog.openWarning(null, NO_PROJECT_IS_SELECTED_FOR_HARD_RESET, PLEASE_SELECT_ONE);
        return null;
    } else if (projects.length > 1) {
        logger.warn(ONLY_ONE_PROJECT_CAN_BE_HARD_RESETED_AT_A_TIME);
        StatusLineManagerUtil.setWarningMessage(ONLY_ONE_PROJECT_CAN_BE_HARD_RESETED_AT_A_TIME);
        MessageDialog.openWarning(null, ONLY_ONE_PROJECT_CAN_BE_HARD_RESETED_AT_A_TIME, PLEASE_SELECT_ONE);
        return null;
    }//from ww  w . j ava 2s.co  m

    IProject project = projects[0];
    final Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    String message = String.format(DO_YOU_REALLY_WANT_TO_HARD_RESET_PROJECT_S, project.getName());

    DefaultProgressMonitor monitor = new DefaultProgressMonitor();
    monitor.beginTask(TASK_RESETING_PROJECT, IProgressMonitor.UNKNOWN);

    boolean confirmed = MessageDialog.openConfirm(parent, HARD_RESET, message);
    if (confirmed) {
        hardReset(project);
    }

    monitor.done();
    return null;
}

From source file:com.sap.dirigible.ide.publish.AbstractPublisher.java

License:Open Source License

private boolean checkOverridePermissionsForFolder(String folderName, String user,
        final ICollection targetFolder) throws IOException {
    if (targetFolder.exists() && targetFolder.getInformation().getModifiedBy() != null
            && !"".equals(targetFolder.getInformation().getModifiedBy()) //$NON-NLS-1$
            && !"null".equalsIgnoreCase(targetFolder.getInformation().getModifiedBy()) //$NON-NLS-1$
            && !targetFolder.getInformation().getModifiedBy().equalsIgnoreCase(user)) {

        boolean publishOverride = Boolean.parseBoolean(CommonParameters.get(PUBLISH_OVERRIDE));

        if (!publishOverride) {
            boolean override = MessageDialog.openConfirm(null, PUBLISH, String.format(
                    FOLDER_WITH_THE_SAME_NAME_ALREADY_PUBLISHED_BY_ANOTHER_USER_S_DO_YOU_WANT_TO_OVERRIDE_IT_ANYWAY,
                    targetFolder.getName(), targetFolder.getInformation().getModifiedBy()));
            if (!override) {
                logger.debug(String.format(PUBLISH_OF_FOLDER_S_SKIPPED, folderName));
                return false;
            } else {
                CommonParameters.set(PUBLISH_OVERRIDE, Boolean.TRUE.toString());
            }//from   w w w. j a va  2 s.c om
        }
        logger.warn(String.format(PUBLISH_OF_FOLDER_S_BY_S_OVERRIDES_THE_PREVIOUS_MODIFICATIONS_MADE_BY_S,
                folderName, user, targetFolder.getInformation().getModifiedBy()));
    }
    return true;
}