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.sap.dirigible.ide.publish.AbstractPublisher.java

License:Open Source License

private boolean checkOverridePermissionsForResource(String fileName, String user,
        final com.sap.dirigible.repository.api.IResource targetResource) throws IOException {
    if (targetResource.exists() && targetResource.getInformation().getModifiedBy() != null
            && !"".equals(targetResource.getInformation().getModifiedBy()) //$NON-NLS-1$
            && !"null".equalsIgnoreCase(targetResource.getInformation().getModifiedBy()) //$NON-NLS-1$
            && !targetResource.getInformation().getModifiedBy().equalsIgnoreCase(user)) {

        boolean override = MessageDialog.openConfirm(null, PUBLISH, String.format(
                FILE_WITH_THE_SAME_NAME_ALREADY_PUBLISHED_BY_ANOTHER_USER_S_DO_YOU_WANT_TO_OVERRIDE_IT_ANYWAY,
                targetResource.getInformation().getModifiedBy()));
        if (!override) {
            logger.debug(String.format(PUBLISH_OF_FILE_S_SKIPPED, fileName));
            return false;
        }//from   www .  ja v a2s  .  co m

        logger.warn(String.format(PUBLISH_OF_FILE_S_BY_S_OVERRIDES_THE_PREVIOUS_MODIFICATIONS_MADE_BY_S,
                fileName, user, targetResource.getInformation().getModifiedBy()));
    }
    return true;
}

From source file:com.sap.dirigible.ide.repository.ui.command.DeleteHandler.java

License:Open Source License

private static boolean confirmDelete(int count) {
    String message = EMPTY_STRING;
    if (count == 1) {
        message = ARE_YOU_SURE_YOU_WANT_TO_DELETE_SELECTED_ITEM;
    } else {/*from  w ww. j  av  a 2 s .  c  om*/
        message = String.format(ARE_YOU_SURE_YOU_WANT_TO_DELETE_SELECTED_ITEMS_D, count);
    }
    return MessageDialog.openConfirm(null, CONFIRM_DELETE, message);
}

From source file:com.sap.dirigible.ide.services.security.manager.views.SecurityManagerView.java

License:Open Source License

private void makeActions() {
    actionSecure = new Action() {
        /**//from w w w  .  java 2 s. c o  m
         * 
         */
        private static final long serialVersionUID = -6534944336694980431L;

        public void run() {
            InputDialog dlg = new InputDialog(viewer.getControl().getShell(), SECURE_LOCATION, PROTECTED_URL,
                    "/project1/securedFolder", new LengthValidator()); //$NON-NLS-1$
            if (dlg.open() == Window.OK) {
                try {
                    securityManager.secureLocation(dlg.getValue(), RWT.getRequest());
                    viewer.refresh();
                } catch (SecurityException e) {
                    logger.error(SECURITY_ERROR, e);
                    MessageDialog.openError(viewer.getControl().getShell(), SECURITY_ERROR, e.getMessage());
                }
            }
        }
    };
    actionSecure.setText(SECURE_LOCATION);
    actionSecure.setToolTipText(PROTECT_A_GIVEN_RELATIVE_URL_TRANSITIVELY);
    actionSecure.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_STOP));

    actionUnsecure = new Action() {
        /**
         * 
         */
        private static final long serialVersionUID = 1336014167502247774L;

        public void run() {

            if (!viewer.getSelection().isEmpty()) {
                StructuredSelection selection = (StructuredSelection) viewer.getSelection();
                SecurityLocationMetadata location = (SecurityLocationMetadata) selection.getFirstElement();
                if (MessageDialog.openConfirm(viewer.getControl().getShell(), UNSECURE_LOCATION,
                        ARE_YOU_SURE_YOU_WANT_TO_REMOVE_THE_SELECTED_LOCATION_FROM_THE_LIST_OF_PROTECTED_LOCATIONS
                                + location.getLocation())) {
                    try {
                        securityManager.unsecureLocation(location.getLocation());
                        viewer.refresh();
                    } catch (SecurityException e) {
                        logger.error(SECURITY_ERROR, e);
                        MessageDialog.openError(viewer.getControl().getShell(), SECURITY_ERROR, e.getMessage());
                    }
                }
            }
        }
    };
    actionUnsecure.setText(UNSECURE_LOCATION);
    actionUnsecure.setToolTipText(REMOVE_THE_SELECTED_LOCATION_FROM_THE_LIST_OF_PROTECTED_LOCATIONS);
    actionUnsecure.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE));

    actionRefresh = new Action() {
        /**
         * 
         */
        private static final long serialVersionUID = 506492927597193506L;

        public void run() {
            viewer.refresh();
        }
    };
    actionRefresh.setText(REFRESH);
    actionRefresh.setToolTipText(REFRESH_THE_LIST_OF_PROTECTED_LOCATIONS);
    actionRefresh.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_SYNCED));

}

From source file:com.sap.dirigible.ide.workspace.ui.commands.DeleteHandler.java

License:Open Source License

private static boolean confirmDelete(int count) {
    String message = ""; //$NON-NLS-1$
    if (count == 1) {
        message = ARE_YOU_SURE_YOU_WANT_TO_DELETE_SELECTED_ITEM;
    } else {//from w  ww  .  ja  v a  2s .com
        message = String.format(ARE_YOU_SURE_YOU_WANT_TO_DELETE_SELECTED_ITEMS_D, count);
    }
    return MessageDialog.openConfirm(null, Messages.DeleteHandler_CONFIRM_DELETE, message);
}

From source file:com.sap.dirigible.ide.workspace.ui.commands.UploadHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    FileDialog dlg = new FileDialog(HandlerUtil.getActiveShell(event), SWT.TITLE | SWT.MULTI);
    dlg.setAutoUpload(true);//from  www  .j  a  v a 2  s . c o  m
    dlg.setText(UPLOAD_FILE);
    dlg.open();

    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
    Object firstElement = selection.getFirstElement();

    if (firstElement instanceof IFolder) {
        IFolder folder = (IFolder) firstElement;
        String fileName = null;
        for (String fullFileName : dlg.getFileNames()) {
            fileName = fullFileName.substring(fullFileName.lastIndexOf(File.separatorChar) + 1);
            IFile file = folder.getFile(fileName);
            InputStream in = null;
            try {
                in = new FileInputStream(fullFileName);
                if (file.exists()) {
                    boolean overrideIt = MessageDialog.openConfirm(null,
                            String.format(FILE_S_ALREADY_EXISTS, file.getName()), DO_YOU_WANT_TO_OVERRIDE_IT);
                    if (overrideIt) {
                        file.setContents(in, IResource.FORCE, null);
                    }
                } else {
                    file.create(in, false, null);
                }
            } catch (Exception e) {
                logger.error(CANNOT_SAVE_UPLOADED_FILE + fileName, e);
                MessageDialog.openError(null, UPLOAD_ERROR, CANNOT_UPLOAD + fileName + REASON + e.getMessage());
                cleanUp(folder, fileName);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        logger.warn(CANNOT_CLOSE_INPUT_STREAM_TO_AN_UPLOADED_FILE, e);
                    }
                }
            }
        }
    }
    return null;
}

From source file:com.sap.dirigible.ide.workspace.wizard.project.commands.UploadProjectHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    FileDialog dlg = new FileDialog(HandlerUtil.getActiveShell(event), SWT.TITLE | SWT.MULTI);
    dlg.setAutoUpload(true);//from  w ww . j av  a  2  s .c om
    dlg.setText(UPLOAD_PROJECT_ARCHIVE);
    dlg.setFilterExtensions(new String[] { "*.zip" }); //$NON-NLS-1$
    String projectPath = dlg.open();

    if (projectPath != null && MessageDialog.openConfirm(null, OVERRIDE_PROJECTS,
            THIS_PROCESS_WILL_OVERRIDE_YOUR_EXISTING_PROJECTS_DO_YOU_WANT_TO_CONTINUE)) {
        String fileName = null;
        for (String fullFileName : dlg.getFileNames()) {
            fileName = fullFileName.substring(fullFileName.lastIndexOf(File.separatorChar) + 1);
            InputStream in = null;
            try {
                in = new FileInputStream(fullFileName);
                IRepository repository = RepositoryFacade.getInstance().getRepository();
                Workspace workspace = (Workspace) RemoteResourcesPlugin.getWorkspace();
                String root = workspace.getRepositoryPathForWorkspace(RemoteResourcesPlugin.getUserName());
                repository.importZip(new ZipInputStream(in), root);
                refreshWorkspace();
            } catch (Exception e) {
                error.error(CANNOT_SAVE_UPLOADED_FILE + fileName, e);
                MessageDialog.openError(null, UPLOAD_ERROR, CANNOT_UPLOAD + fileName + REASON + e.getMessage());
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        error.warn(CANNOT_CLOSE_INPUT_STREAM_TO_AN_UPLOADED_FILE, e);
                    }
                }
            }
        }
    }
    return null;
}

From source file:com.siteview.mde.internal.ui.nls.NLSFragmentGenerator.java

License:Open Source License

private Map promptForOverwrite(List plugins, List locales) {
    Map overwrites = new HashMap();

    if (overwriteWithoutAsking)
        return overwrites;

    for (Iterator iter = plugins.iterator(); iter.hasNext();) {
        IMonitorModelBase plugin = (IMonitorModelBase) iter.next();
        for (Iterator it = locales.iterator(); it.hasNext();) {
            Locale locale = (Locale) it.next();
            IProject project = getNLProject(plugin, locale);

            if (project.exists() && !overwrites.containsKey(project.getName())) {
                boolean overwrite = MessageDialog.openConfirm(MDEPlugin.getActiveWorkbenchShell(),
                        MDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteTitle,
                        NLS.bind(MDEUIMessages.InternationalizeWizard_NLSFragmentGenerator_overwriteMessage,
                                pluginName(plugin, locale)));
                overwrites.put(project.getName(), overwrite ? OVERWRITE : null);
            }/*from  w ww . j a va  2 s .c  om*/
        }
    }

    return overwrites;
}

From source file:com.softberries.klerk.gui.editors.CompaniesEditor.java

License:Open Source License

@Override
protected void deleteButtonClicked() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if (this.getSelectedCompany() == null || this.getSelectedCompany().getId() == null) {
        MessageDialog.openInformation(shell, "Information", "Nothing to delete");
        return;//w  ww  .j  ava2s.com
    }
    boolean confirmed = MessageDialog.openConfirm(shell, "Confirm",
            "Are you sure you want to delete this company?");
    if (confirmed) {
        CompanyDao dao = new CompanyDao(DB_FOLDER_PATH);
        try {
            dao.delete(this.getSelectedCompany().getId());
            closeOpenedEditorForThisItem(new CompanyEditorInput(this.getSelectedCompany()));
            CompaniesModelProvider.INSTANCE.getCompanies().remove(this.getSelectedCompany());
            this.setSelectedCompany(null);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        viewer.setInput(CompaniesModelProvider.INSTANCE.getCompanies());
        viewer.refresh();
    }
}

From source file:com.softberries.klerk.gui.editors.DocumentsEditor.java

License:Open Source License

@Override
protected void deleteButtonClicked() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if (this.getSelectedDocument() == null || this.getSelectedDocument().getId() == null) {
        MessageDialog.openInformation(shell, "Information", "Nothing to delete");
        return;/* w w w.j  a  v  a  2  s  .  c  o  m*/
    }
    boolean confirmed = MessageDialog.openConfirm(shell, "Confirm",
            "Are you sure you want to delete this document?");
    if (confirmed) {
        DocumentDao dao = new DocumentDao(DB_FOLDER_PATH);
        try {
            dao.delete(this.getSelectedDocument().getId());
            closeOpenedEditorForThisItem(new DocumentEditorInput(this.getSelectedDocument()));
            DocumentsModelProvider.INSTANCE.getDocuments(getDocumentType(), false)
                    .remove(this.getSelectedDocument());
            this.setSelectedDocument(null);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        viewer.setInput(DocumentsModelProvider.INSTANCE.getDocuments(getDocumentType(), false));
        viewer.refresh();
    }
}

From source file:com.softberries.klerk.gui.editors.PeopleEditor.java

License:Open Source License

@Override
public void deleteButtonClicked() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if (this.getSelectedPerson() == null || this.getSelectedPerson().getId() == null) {
        MessageDialog.openInformation(shell, "Information", "Nothing to delete");
        return;//from  w w w .  ja v a 2 s  .  c o  m
    }
    boolean confirmed = MessageDialog.openConfirm(shell, "Confirm",
            "Are you sure you want to delete this person?");
    if (confirmed) {
        PeopleDao dao = new PeopleDao(DB_FOLDER_PATH);
        try {
            dao.delete(this.getSelectedPerson().getId());
            closeOpenedEditorForThisItem(new PersonEditorInput(this.getSelectedPerson()));
            PeopleModelProvider.INSTANCE.getPeople().remove(this.getSelectedPerson());
            this.setSelectedPerson(null);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        viewer.setInput(ProductsModelProvider.INSTANCE.getProducts());
        viewer.refresh();
    }
}