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

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

Introduction

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

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:com.palantir.typescript.preferences.BuildPathPropertyPage.java

License:Apache License

private Button createUseTsConfigField(final Composite composite) {
    Label label = new Label(composite, SWT.NONE);
    label.setLayoutData(new GridData(GridData.BEGINNING, SWT.CENTER, false, false));
    label.setText("Use tsconfig");

    final Button button = new Button(composite, SWT.CHECK);
    button.setLayoutData(new GridData(GridData.BEGINNING, SWT.CENTER, false, false));
    button.addListener(SWT.Selection, new Listener() {
        @Override//from w  w  w.ja  v  a 2  s .  co m
        public void handleEvent(Event e) {
            projectPreferenceStore.setUsingTsConfigFile(button.getSelection());
            if (button.getSelection()) {
                Builders.promptRecompile(getShell(), getProject());
            }
            updateFieldStates();
            updateFieldValues();
        }
    });
    button.setSelection(projectPreferenceStore.isUsingTsConfigFile());

    Button forceReloadButton = new Button(composite, SWT.NONE);
    forceReloadButton.setLayoutData(new GridData(GridData.CENTER, SWT.CENTER, false, false));
    forceReloadButton.setText("Force reload");
    forceReloadButton.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event e) {
            boolean loaded = projectPreferenceStore.getTsConfigPreferences().reloadTsConfigFile();
            if (!loaded) {
                String title = Resources.BUNDLE.getString("title.error");
                String message = Resources.BUNDLE.getString("preferences.tsconfig.loadError");
                String[] buttonLabels = new String[] { IDialogConstants.OK_LABEL };
                MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.ERROR,
                        buttonLabels, 1);
                dialog.open();
                return;
            }
            projectPreferenceStore.setUsingTsConfigFile(true);
            Builders.promptRecompile(getShell(), getProject());
            updateFieldStates();
            updateFieldValues();
        }
    });

    return button;
}

From source file:com.palantir.typescript.preferences.GeneralPreferencePage.java

License:Apache License

@Override
public boolean performOk() {
    String oldNodePath = this.getPreferenceStore().getString(IPreferenceConstants.GENERAL_NODE_PATH);
    String newNodePath = this.nodePathText.getText();

    if (!oldNodePath.equals(newNodePath)) {
        String title = Resources.BUNDLE.getString("preferences.general.node.path.dialog.title");
        String message = Resources.BUNDLE.getString("preferences.general.node.path.dialog.message");
        String[] buttonLabels = new String[] { IDialogConstants.OK_LABEL };
        MessageDialog dialog = new MessageDialog(this.getShell(), title, null, message, MessageDialog.QUESTION,
                buttonLabels, 2);//from   w w  w  . j a v  a 2  s.c om
        dialog.open();

        this.getPreferenceStore().setValue(IPreferenceConstants.GENERAL_NODE_PATH, newNodePath);
    }

    return true;
}

From source file:com.persistent.winazureroles.WARComponents.java

License:Open Source License

/**
 * Listener method for remove button which
 * deletes the selected component./*from   w w  w  . ja  v  a  2 s  . c om*/
 */
protected void removeBtnListener() {
    int selIndex = tblViewer.getTable().getSelectionIndex();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    WindowsAzureRoleComponent component = listComponents.get(selIndex);
    if (selIndex > -1) {
        try {
            /* First condition: Checks component is part of a JDK,
             * server configuration
             * Second condition: For not showing error message
             * "Disable Server JDK Configuration"
             * while removing server application
             * when server or JDK  is already disabled.
             */
            if (component.getIsPreconfigured() && (!(component.getType().equals(Messages.typeSrvApp)
                    && windowsAzureRole.getServerName() == null))) {
                PluginUtil.displayErrorDialog(getShell(), Messages.jdkDsblErrTtl, Messages.jdkDsblErrMsg);
            } else {
                boolean choice = MessageDialog.openQuestion(getShell(), Messages.cmpntRmvTtl,
                        Messages.cmpntRmvMsg);
                if (choice) {
                    String cmpntPath = String.format("%s%s%s%s%s",
                            root.getProject(waProjManager.getProjectName()).getLocation(), File.separator,
                            windowsAzureRole.getName(), Messages.approot, component.getDeployName());
                    File file = new File(cmpntPath);
                    // Check import source is equal to approot
                    if (component.getImportPath().isEmpty() && file.exists()) {
                        MessageDialog dialog = new MessageDialog(getShell(), Messages.cmpntSrcRmvTtl, null,
                                Messages.cmpntSrcRmvMsg, MessageDialog.QUESTION_WITH_CANCEL,
                                new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                                        IDialogConstants.CANCEL_LABEL },
                                0);
                        switch (dialog.open()) {
                        case 0:
                            //yes
                            component.delete();
                            tblViewer.refresh();
                            fileToDel.add(file);
                            break;
                        case 1:
                            //no
                            component.delete();
                            tblViewer.refresh();
                            break;
                        case 2:
                            //cancel
                            break;
                        default:
                            break;
                        }
                    } else {
                        component.delete();
                        tblViewer.refresh();
                        fileToDel.add(file);
                    }
                }
            }
            if (tblComponents.getItemCount() == 0) {
                // table is empty i.e. number of rows = 0
                btnRemove.setEnabled(false);
                btnEdit.setEnabled(false);
            }
        } catch (WindowsAzureInvalidProjectOperationException e) {
            PluginUtil.displayErrorDialogAndLog(getShell(), Messages.cmpntSetErrTtl, Messages.cmpntRmvErrMsg,
                    e);
        }
    }
    updateMoveButtons();
}

From source file:com.persistent.winazureroles.WARGeneral.java

License:Open Source License

private void handleSmallVMCacheConf() {
    try {/*from w w  w .  j  a  v a  2  s .com*/
        if (Messages.txtExtraSmallVM.equals(comboVMSize.getText())
                && windowsAzureRole.getCacheMemoryPercent() > 0) {
            // If extra small VM and cache is enabled
            MessageDialog dialog = new MessageDialog(getShell(), Messages.cacheConfTitle, null,
                    Messages.cacheConfMsg, MessageDialog.WARNING, new String[] { "Yes", "No" }, 2);

            int choice = dialog.open();
            switch (choice) {
            case 0: // Yes - Disable cache
                windowsAzureRole.setCacheMemoryPercent(0);
                break;

            case 1: // No or if dialog is closed directly then reset VM size back to original
            case -1:
                comboVMSize.setText(arrVMSize[getVMSizeIndex()]);
                break;
            }
        }
    } catch (WindowsAzureInvalidProjectOperationException e) {
        PluginUtil.displayErrorDialogAndLog(getShell(), Messages.cachErrTtl, Messages.cachGetErMsg, e);
    }
}

From source file:com.puppetlabs.geppetto.pp.dsl.ui.linked.ExtLinkedXtextEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {

    Shell shell = getSite().getShell();//  ww w  .j a v a2 s .  c o m
    final IEditorInput input = getEditorInput();

    // Customize save as if the file is linked, and it is in the special external link project
    //
    if (input instanceof IFileEditorInput && ((IFileEditorInput) input).getFile().isLinked()
            && ((IFileEditorInput) input).getFile().getProject().getName()
                    .equals(ExtLinkedFileHelper.AUTOLINK_PROJECT_NAME)) {
        final IEditorInput newInput;
        IDocumentProvider provider = getDocumentProvider();

        // 1. If file is "untitled" suggest last save location
        // 2. ...otherwise use the file's location (i.e. likely to be a rename in same folder)
        // 3. If a "last save location" is unknown, use user's home
        //
        String suggestedName = null;
        String suggestedPath = null;
        {
            // is it "untitled"
            java.net.URI uri = ((IURIEditorInput) input).getURI();
            String tmpProperty = null;
            try {
                tmpProperty = ((IFileEditorInput) input).getFile()
                        .getPersistentProperty(TmpFileStoreEditorInput.UNTITLED_PROPERTY);
            } catch (CoreException e) {
                // ignore - tmpProperty will be null
            }
            boolean isUntitled = tmpProperty != null && "true".equals(tmpProperty);

            // suggested name
            IPath oldPath = URIUtil.toPath(uri);
            // TODO: input.getName() is probably always correct
            suggestedName = isUntitled ? input.getName() : oldPath.lastSegment();

            // suggested path
            try {
                suggestedPath = isUntitled
                        ? ((IFileEditorInput) input).getFile().getWorkspace().getRoot()
                                .getPersistentProperty(LAST_SAVEAS_LOCATION)
                        : oldPath.toOSString();
            } catch (CoreException e) {
                // ignore, suggestedPath will be null
            }

            if (suggestedPath == null) {
                // get user.home
                suggestedPath = System.getProperty("user.home");
            }
        }
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        if (suggestedName != null)
            dialog.setFileName(suggestedName);
        if (suggestedPath != null)
            dialog.setFilterPath(suggestedPath);

        dialog.setFilterExtensions(new String[] { "*.pp", "*.*" });
        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }

        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, "Save As", null,
                    path + " already exists.\nDo you want to replace it?", MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            EditorsPlugin.log(ex.getStatus());
            String title = "Problems During Save As...";
            String msg = "Save could not be completed. " + ex.getMessage();
            MessageDialog.openError(shell, title, msg);
            return;
        }

        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else {
            IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
            java.net.URI uri = uriInput.getURI();
            IFile linkedFile = ExtLinkedFileHelper.obtainLink(uri, false);

            newInput = new FileEditorInput(linkedFile);
        }

        if (provider == null) {
            // editor has been closed while the dialog was open
            return;
        }

        boolean success = false;
        try {

            provider.aboutToChange(newInput);
            provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
            success = true;

        } catch (CoreException x) {
            final IStatus status = x.getStatus();
            if (status == null || status.getSeverity() != IStatus.CANCEL) {
                String title = "Problems During Save As...";
                String msg = "Save could not be completed. " + x.getMessage();
                MessageDialog.openError(shell, title, msg);
            }
        } finally {
            provider.changed(newInput);
            if (success)
                setInput(newInput);
            // the linked file must be removed (esp. if it is an "untitled" link).
            ExtLinkedFileHelper.unlinkInput(((IFileEditorInput) input));
            // remember last saveAs location
            String lastLocation = URIUtil.toPath(((FileEditorInput) newInput).getURI()).toOSString();
            try {
                ((FileEditorInput) newInput).getFile().getWorkspace().getRoot()
                        .setPersistentProperty(LAST_SAVEAS_LOCATION, lastLocation);
            } catch (CoreException e) {
                // ignore
            }
        }

        if (progressMonitor != null)
            progressMonitor.setCanceled(!success);

        return;
    }

    super.performSaveAs(progressMonitor);
}

From source file:com.python.pydev.ui.search.ReplaceDialog2.java

License:Open Source License

private int askForSkip(final IFile file) {

    String message = Messages.format(SearchMessages.ReadOnlyDialog_message, file.getFullPath().toOSString());
    String[] buttonLabels = null;
    boolean showSkip = countResources() > 1;
    if (showSkip) {
        String skipLabel = SearchMessages.ReadOnlyDialog_skipFile;
        String skipAllLabel = SearchMessages.ReadOnlyDialog_skipAll;
        buttonLabels = new String[] { skipLabel, skipAllLabel, IDialogConstants.CANCEL_LABEL };
    } else {//from  w  w w.  ja va  2 s .  co  m
        buttonLabels = new String[] { IDialogConstants.CANCEL_LABEL };

    }

    MessageDialog msd = new MessageDialog(getShell(), getShell().getText(), null, message, MessageDialog.ERROR,
            buttonLabels, 0);
    int rc = msd.open();
    switch (rc) {
    case 0:
        return showSkip ? SKIP_FILE : CANCEL;
    case 1:
        return SKIP_ALL;
    default:
        return CANCEL;
    }
}

From source file:com.rcpcompany.uibindings.tests.application.ApplicationWorkbenchAdvisor.java

License:Open Source License

@Override
public boolean preShutdown() {
    final IManager manager = IManager.Factory.getManager();
    final EditingDomain editingDomain = manager.getEditingDomain();
    int res = 1; // == NO
    if (editingDomain.getCommandStack().canUndo()) {
        final IWorkbenchWindow window = getWorkbenchConfigurer().getWorkbench().getActiveWorkbenchWindow();
        final MessageDialog dialog = new MessageDialog(window.getShell(), "Save Shop?", null,
                "Changes has been made to the shop. Save these?", MessageDialog.QUESTION, new String[] {
                        IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                0);/*  w w  w  . j  a  va  2  s. co  m*/
        res = dialog.open();
        if (res == 0) {
            final ICommandService cs = (ICommandService) window.getService(ICommandService.class);
            final IHandlerService hs = (IHandlerService) window.getService(IHandlerService.class);

            try {
                final String c = manager.getCommandIDs().get(IWorkbenchCommandConstants.FILE_SAVE);
                final ParameterizedCommand command = cs.deserialize(c);
                hs.executeCommand(command, null);
            } catch (final Exception ex) {
                LogUtils.error(this, ex);
            }
        }
    }
    return res != 2;
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

public static IRemoveOldBinariesQuery getRemoveOldBinariesQuery(final Shell shell) {
    return new IRemoveOldBinariesQuery() {
        public boolean doQuery(final boolean removeFolder, final IPath oldOutputLocation)
                throws OperationCanceledException {
            final int[] res = new int[] { 1 };
            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    Shell sh = shell != null ? shell : JavaPlugin.getActiveWorkbenchShell();
                    String title = NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_title;
                    String message;
                    String pathLabel = BasicElementLabels.getPathLabel(oldOutputLocation, false);
                    if (removeFolder) {
                        message = Messages.format(
                                NewWizardMessages.BuildPathsBlock_RemoveOldOutputFolder_description, pathLabel);
                    } else {
                        message = Messages.format(
                                NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_description, pathLabel);
                    }//from  w ww.  ja va 2 s .  c  om
                    MessageDialog dialog = new MessageDialog(sh, title, null, message, MessageDialog.QUESTION,
                            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                                    IDialogConstants.CANCEL_LABEL },
                            0);
                    res[0] = dialog.open();
                }
            });
            if (res[0] == 0) {
                return true;
            } else if (res[0] == 1) {
                return false;
            }
            throw new OperationCanceledException();
        }
    };
}

From source file:com.safi.workshop.sqlexplorer.connections.actions.DeleteAction.java

License:Open Source License

@Override
public void run() {
    SafiNavigator nav = SafiWorkshopEditorUtil.getSafiNavigator();
    IStructuredSelection viewerSelection = nav.getViewerSelection();
    if (viewerSelection.isEmpty())
        return;/*ww  w .j  a  v a  2  s  .c  o  m*/

    boolean okToDelete = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Delete Resource",
            "Are you sure you  want to delete the selected resource?");

    if (!okToDelete)
        return;

    List<IResource> resources = new ArrayList<IResource>();
    List<Object> dbResources = new ArrayList<Object>();
    List<ServerResource> serverResources = new ArrayList<ServerResource>();
    for (Object selected : viewerSelection.toArray()) {
        if (selected instanceof ManagedDriver) {

            MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Delete Driver rejected",
                    "You can not delete Driver Resource.");
            return;

        }
        if (selected instanceof DBResource || selected instanceof User || selected instanceof Alias
        /* || selected instanceof ManagedDriver */) {
            dbResources.add(selected);
        } else if (selected instanceof IResource)
            resources.add((IResource) selected);
        else if (selected instanceof ServerResource)
            serverResources.add((ServerResource) selected);
    }

    if (!resources.isEmpty()) {
        if (SafiServerPlugin.getDefault().isConnected()) {
            boolean foundPersisted = false;
            for (IResource res : resources) {
                try {
                    int id = SafletPersistenceManager.getInstance().getResourceId(res);
                    if (id >= 0) {
                        foundPersisted = true;
                        break;
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            if (foundPersisted)
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Delete Local Only",
                        "This operation will delete only local copies of any selected Saflets or SafiProjects.  "
                                + " If you wish to delete them from the production SafiServer open the Delete Saflet dialog from the main toolbar.");
        }
        com.safi.workshop.navigator.DeleteResourceAction ac = new com.safi.workshop.navigator.DeleteResourceAction();
        ac.selectionChanged(viewerSelection);
        ac.run();
    }
    if (!dbResources.isEmpty()) {
        int deletePref = 1;
        com.safi.db.server.config.User user = SafiServerPlugin.getDefault().getCurrentUser();
        boolean isConnected = SafiServerPlugin.getDefault().isConnected();

        if (isConnected
                && !EntitlementUtils.isUserEntitled(user, EntitlementUtils.ENTIT_PUBLISH_DB_RESOURCES)) {
            MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Not Entitled",
                    "You do not have sufficient privileges to carry out this operation.");
            return;
        }
        removeDBResourceChildren(dbResources);

        // if (SafiServerPlugin.getDefault().isConnected())
        // deleteFromServer =
        // MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
        // "Delete From Server?",
        // "Do you want to delete database resource(s) from the production SafiServer?");
        for (Object o : dbResources) {
            if (o instanceof Alias) {
                Alias alias = (Alias) o;
                DBConnection conn = alias.getConnection();
                List<Query> queries = new ArrayList<Query>(conn.getQueries());

                alias.getConnection().setLastModified(new Date());
                if (deletePref != 2 && deletePref != 3 && isConnected && alias.getConnection().getId() != -1) {
                    MessageDialog dialog = new MessageDialog(SafiWorkshopEditorUtil.getActiveShell(),
                            "Delete From Server?", null,
                            "Do you want to delete database connection " + alias.getName()
                                    + " from the production SafiServer?",
                            SWT.ICON_QUESTION,
                            new String[] { "YES", "NO", "YES TO ALL", "NO TO ALL", "CANCEL" }, 1);
                    deletePref = dialog.open();
                    if (deletePref == 4)
                        return;
                }
                try {
                    alias.remove(deletePref == 0 || deletePref == 2, true);
                } catch (Exception e) {
                    MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Delete Failed",
                            "Couldn't delete alias " + alias.getName() + ": " + e.getLocalizedMessage());
                    AsteriskDiagramEditorPlugin.getInstance().logError("Couldn't delete alias", e);
                }
                for (Query query : queries) {
                    SafiWorkshopEditorUtil.closeSQLEditors(query);
                }
            } else if (o instanceof Query) {
                Query query = (Query) o;
                if (deletePref != 2 && deletePref != 3 && isConnected && query.getId() != -1) {
                    MessageDialog dialog = new MessageDialog(SafiWorkshopEditorUtil.getActiveShell(),
                            "Delete From Server?", null,
                            "Do you want to delete database query " + query.getName()
                                    + " from the production SafiServer?",
                            SWT.ICON_QUESTION,
                            new String[] { "YES", "NO", "YES TO ALL", "NO TO ALL", "CANCEL" }, 1);
                    deletePref = dialog.open();
                    if (deletePref == 4)
                        return;
                }
                if (deletePref == 0 || deletePref == 2) {

                    try {
                        SQLExplorerPlugin.getDefault().deleteDBResource(query);
                    } catch (Exception e) {
                        MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Delete Failed",
                                "Couldn't delete query " + query.getName() + ": " + e.getLocalizedMessage());
                        AsteriskDiagramEditorPlugin.getInstance()
                                .logError("Couldn't delete query " + query.getName(), e);
                    }
                }
                query.getConnection().setLastModified(new Date());
                query.getConnection().getQueries().remove(query);
                SafiWorkshopEditorUtil.closeSQLEditors(query);
            } else if (o instanceof ManagedDriver) {
                ManagedDriver driver = (ManagedDriver) o;
                if (driver.getDriver() != null && !driver.getDriver().isDefault()) {
                    if (deletePref != 2 && deletePref != 3 && isConnected && driver.getDriver().getId() != -1) {
                        MessageDialog dialog = new MessageDialog(SafiWorkshopEditorUtil.getActiveShell(),
                                "Delete From Server?", null,
                                "Do you want to delete database driver " + driver.getDriver().getName()
                                        + " from the production SafiServer?",
                                SWT.ICON_QUESTION,
                                new String[] { "YES", "NO", "YES TO ALL", "NO TO ALL", "CANCEL" }, 1);
                        deletePref = dialog.open();
                        if (deletePref == 4)
                            return;
                    }
                    if (deletePref == 0 || deletePref == 1) {
                        try {
                            SQLExplorerPlugin.getDefault().deleteDBResource(driver.getDriver());
                        } catch (Exception e) {
                            MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Delete Failed",
                                    "Couldn't delete query " + driver.getDriver().getName() + ": "
                                            + e.getLocalizedMessage());
                            AsteriskDiagramEditorPlugin.getInstance()
                                    .logError("Couldn't delete query " + driver.getDriver().getName(), e);
                        }
                    }
                    SQLExplorerPlugin.getDefault().getDriverModel().removeDriver(driver);
                }
            }
        }
        SQLExplorerPlugin.getDefault().saveDBResources(false);
    }

    if (!serverResources.isEmpty()) {
        com.safi.db.server.config.User user = SafiServerPlugin.getDefault().getCurrentUser();

        List<ServerResource> deleted = new ArrayList<ServerResource>();
        SafiServer production = null;
        try {
            production = SafiServerPlugin.getDefault().getSafiServer(true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (production != null) {
            removeChildren(serverResources);
            boolean checkedTelEntit = false;
            boolean checkedUsers = false;
            for (ServerResource r : serverResources) {
                if (r instanceof com.safi.db.server.config.User) {
                    if (!checkedUsers) {
                        if (!EntitlementUtils.isUserEntitled(user, EntitlementUtils.ENTIT_MANAGE_USERS)) {
                            MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Not Entitled",
                                    "You do not have sufficient privileges to carry out this operation.");
                            return;
                        } else
                            checkedUsers = true;
                    }

                    if (r.getId() == SafiServerPlugin.getDefault().getCurrentUser().getId()) {
                        MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                                "Can't Delete Self", "The currently logged in user cannot be deleted.");
                        continue;
                    } else {
                        production.getUsers().remove(r);
                        deleted.add(r);
                    }
                }

            }
        } else {
            MessageDialog.openInformation(Display.getCurrent().getActiveShell(), "Can't Delete",
                    "An error has occurred.  No SafiServer instance could be found.");
            return;
        }
        deleteServerResources(production, deleted);

    }

    if (dbResources.isEmpty() && serverResources.isEmpty())
        nav.refresh();
    else {
        try {
            SafiServerPlugin.getDefault().updateServerResources(new NullProgressMonitor());
        } catch (Exception e) {
            e.printStackTrace();
            MessageDialog.openError(SafiWorkshopEditorUtil.getActiveShell(), "Database Error",
                    "Couldn't refresh from production SafiServer: " + e.getLocalizedMessage());
            return;
        }
        // nav.modelChanged(SafiServerPlugin.getDefault().isConnected());
    }

    // if (!viewerSelection.isEmpty() && viewerSelection.getFirstElement()
    // instanceof
    // IResource){
    // DeleteResourceAction action = new
    // DeleteResourceAction(Display.getCurrent().getActiveShell());
    // action.selectionChanged(viewerSelection);
    // action.run();
    // return;
    // }
    //    
    //
    //    
    // boolean deleteFromServer = false;
    // if (SafiServerPlugin.getDefault().hasProductionServerInfo())
    // deleteFromServer =
    // MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
    // "Delete From Server?",
    // "Do you want to delete from the production SafiServer?");
    // boolean needsToSave = false;
    //    
    // Set<User> selectedUsers = nav.getSelectedUsers(false);
    // Date now = new Date();
    // for (User user : selectedUsers) {
    // user.getAlias().removeUser(user);
    // user.getAlias().getConnection().setLastModified(now);
    // }
    // if (!selectedUsers.isEmpty()) {
    // needsToSave = true;
    // }
    // Set<Alias> selectedAliases = nav.getSelectedAliases(false);
    // for (Alias alias : selectedAliases) {
    // alias.getConnection().setLastModified(now);
    // try {
    // alias.remove(deleteFromServer, true);
    // } catch (Exception e) {
    // MessageDialog.openError(AsteriskDiagramEditorUtil.getActiveShell(),
    // "Delete Failed", "Couldn't delete alias " + alias.getName() + ": "
    // + e.getLocalizedMessage());
    // AsteriskDiagramEditorPlugin.getInstance().logError("Couldn't delete alias",
    // e);
    // return;
    // }
    // }
    // if (!selectedAliases.isEmpty())
    // needsToSave = true;
    // Set<Query> selectedQueries = nav.getSelectedQueries(false);
    // for (Query query : selectedQueries) {
    // if (deleteFromServer) {
    // query.getConnection().setLastModified(now);
    // try {
    // SQLExplorerPlugin.getDefault().deleteDBResource(query);
    // } catch (Exception e) {
    // MessageDialog.openError(AsteriskDiagramEditorUtil.getActiveShell(),
    // "Delete Failed", "Couldn't delete query " + query.getName() + ": "
    // + e.getLocalizedMessage());
    // AsteriskDiagramEditorPlugin.getInstance().logError(
    // "Couldn't delete query " + query.getName(), e);
    // }
    // }
    // query.getConnection().getQueries().remove(query);
    // }
    // if (!selectedQueries.isEmpty())
    // needsToSave = true;
    //
    // Set<ManagedDriver> selectedDrivers = nav.getSelectedDrivers(false);
    // if (selectedDrivers != null && !selectedDrivers.isEmpty()) {
    // for (ManagedDriver driver : selectedDrivers) {
    // if (driver.getDriver() != null && !driver.getDriver().isDefault()) {
    // if (deleteFromServer) {
    // try {
    // SQLExplorerPlugin.getDefault().deleteDBResource(driver.getDriver());
    // } catch (Exception e) {
    // MessageDialog.openError(AsteriskDiagramEditorUtil.getActiveShell(),
    // "Delete Failed", "Couldn't delete query "
    // + driver.getDriver().getName() + ": " + e.getLocalizedMessage());
    // AsteriskDiagramEditorPlugin.getInstance().logError(
    // "Couldn't delete query " + driver.getDriver().getName(), e);
    // }
    // }
    // SQLExplorerPlugin.getDefault().getDriverModel().removeDriver(driver);
    // needsToSave = true;
    // }
    // }
    // }
    //
    // if (needsToSave) {
    // SQLExplorerPlugin.getDefault().saveDBResources(false);
    // nav.modelChanged();
    // return;
    // }
    // nav.refresh();
}

From source file:com.safi.workshop.sqlexplorer.dbproduct.ConnectionJob.java

License:Open Source License

/**
 * Prompts the user for a new username/password to attempt login with; if the dialog is
 * cancelled then this.user is set to null.
 * //from  ww w. j  a  v  a2s . c o m
 * @param message
 */
private void promptForPassword(final String message) {
    final Shell shell = SafiWorkshopEditorUtil.getSafiNavigator().getSite().getShell();

    // Switch to the UI thread to run the password dialog, but run it synchronously so we
    // wait for it to complete
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            if (message != null) {
                String title = Messages.getString("Progress.Connection.Title") + ' ' + alias.getName();
                if (user != null && !alias.hasNoUserName())
                    title += '/' + user.getUserName();
                if (alias.hasNoUserName()) {
                    MessageDialog dlg = new MessageDialog(shell, title, null,
                            Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message,
                            MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
                    dlg.open();
                    cancelled = true;
                    return;
                } else {
                    MessageDialog dlg = new MessageDialog(shell, title, null,
                            Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message
                                    + "\n\n" + Messages.getString("Progress.Connection.ErrorMessage_Part2"),
                            MessageDialog.ERROR,
                            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                    boolean retry = dlg.open() == 0;
                    if (!retry) {
                        cancelled = true;
                        return;
                    }
                }
            }

            Shell shell = Display.getCurrent().getActiveShell();
            PasswordConnDlg dlg = new PasswordConnDlg(shell, user.getAlias(), user);
            if (dlg.open() != Window.OK) {
                cancelled = true;
                return;
            }

            // Create a new user and add it to the alias
            User userTmp = new User(dlg.getUserName(), dlg.getPassword());
            userTmp.setAutoCommit(dlg.getAutoCommit());
            userTmp.setCommitOnClose(dlg.getCommitOnClose());
            user = alias.addUser(userTmp);
        }
    });
}