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

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

Introduction

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

Prototype

public static void openError(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a standard error dialog.

Usage

From source file:com.amalto.workbench.utils.Util.java

License:Open Source License

public static IStatus changeElementTypeToSequence(XSDElementDeclaration decl, int maxOccurs) {
    if (maxOccurs < -1) {
        MessageDialog.openError(null, Messages.Util_30, Messages.Util_31);
        return Status.CANCEL_STATUS;
    }/*from  w w w .  ja va 2 s. co m*/
    if (Util.getParent(decl) instanceof XSDElementDeclaration) {
        XSDElementDeclaration parent = (XSDElementDeclaration) Util.getParent(decl);

        return doChangeElementTypeToSequence((XSDComplexTypeDefinition) parent.getTypeDefinition(), maxOccurs);

    } else {
        if (Util.getParent(decl) instanceof XSDComplexTypeDefinition) {
            return doChangeElementTypeToSequence((XSDComplexTypeDefinition) Util.getParent(decl), maxOccurs);
        }
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.widgets.ComplexTableViewer.java

License:Open Source License

protected void createRightmostPortion(Composite parent) {
    addButton = toolkit.createButton(parent, "", SWT.PUSH | SWT.CENTER);//$NON-NLS-1$
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1));
    addButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addButton.setToolTipText(Messages.ComplexTableViewer_Add);
    addButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        };/*from w ww.  j  a  v  a  2 s. c  o  m*/

        @SuppressWarnings("unchecked")
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {

            String uniqueVal = "";//$NON-NLS-1$
            String keyVal = "";//$NON-NLS-1$
            // Make sure texts are not nill (empty) where not authorized
            for (ComplexTableViewerColumn column : columns) {
                String text = "";//$NON-NLS-1$
                if (column.isCombo()) {
                    text = ((CCombo) column.getControl()).getText();
                } else if (column.isText()) {
                    text = ((Text) column.getControl()).getText();
                } else if (column.isXPATH()) {
                    Control text1 = ((Composite) column.getControl()).getChildren()[0];
                    if (text1 instanceof Text) {
                        text = ((Text) text1).getText();
                    }
                }
                if (text.length() == 0) {
                    if (column.isNillable()) {
                        text = column.getNillValue();
                        if (column.isCombo()) {
                            ((CCombo) column.getControl()).setText(text);
                        } else {
                            ((Text) column.getControl()).setText(text);
                        }
                    } else {
                        MessageDialog.openError(ComplexTableViewer.this.getViewer().getControl().getShell(),
                                Messages.ComplexTableViewer_InputError, Messages.ComplexTableViewer_ErrorMsg
                                        + column.getName() + Messages.ComplexTableViewer_ErrorMsgA);
                        return;
                    }
                }
                if (keyColumns != null && Arrays.asList(keyColumns).indexOf(column) >= 0) {
                    keyVal += text;
                }
                uniqueVal += "." + text;//$NON-NLS-1$
            }

            // check uniqueness by concatenating all the values
            List<Line> list = (List<Line>) getViewer().getInput();
            for (Line line : list) {
                String thisLineVal = "";//$NON-NLS-1$
                for (KeyValue keyvalue : line.keyValues) {
                    thisLineVal += "." + keyvalue.value;//$NON-NLS-1$
                }
                if (thisLineVal.equals(uniqueVal)
                        || (keyVal.length() > 0 && thisLineVal.indexOf(keyVal) >= 0)) {
                    MessageDialog.openInformation(null, ERROR_ITEMALREADYEXISTS_TITLE,
                            ERROR_ITEMALREADYEXISTS_CONTENT);
                    return;
                }
            }

            // Update the model
            Line line = new Line(columns.toArray(new ComplexTableViewerColumn[columns.size()]),
                    getTextValues());
            list.add(line);
            // update the instances viewer
            markDirty();
            viewer.setSelection(null);
            viewer.refresh();
            viewer.getTable().select(viewer.getTable().getItemCount() - 1);
        };
    });
}

From source file:com.amazonaws.eclipse.core.accounts.AccountInfoProvider.java

License:Apache License

private void reloadProfileAccountInfo(final boolean boostrapCredentialsFile,
        final boolean showWarningOnFailure) {

    profileAccountInfoCache.clear();//from   w  w  w .ja va  2 s.  c  o m

    /* Load the credential profiles file */

    String credFileLocation = prefStore.getString(PreferenceConstants.P_CREDENTIAL_PROFILE_FILE_LOCATION);
    File credFile = new File(credFileLocation);

    ProfilesConfigFile profileConfigFile = null;

    try {
        if (!credFile.exists() && boostrapCredentialsFile) {
            ProfilesConfigFileWriter.dumpToFile(credFile, true, // overwrite=true
                    new Profile(PreferenceConstants.DEFAULT_ACCOUNT_NAME, new BasicAWSCredentials("", "")));
        }

        profileConfigFile = new ProfilesConfigFile(credFile);
    } catch (Exception e) {
        String errorMsg = String.format("Failed to load credential profiles from (%s).", credFileLocation);
        AwsToolkitCore.getDefault().logInfo(errorMsg + e.getMessage());

        if (showWarningOnFailure) {
            MessageDialog.openError(null, "Unable to load profile accounts",
                    errorMsg + " Please check that your credentials file is at the correct location "
                            + "and that it is in the correct format.");
        }
    }

    if (profileConfigFile == null)
        return;

    /* Set up the AccountInfo objects */

    // Map from profile name to its pre-configured account id
    Map<String, String> exisitingProfileAccountIds = getExistingProfileAccountIds();

    // Iterate through the newly loaded profiles. Re-use the existing
    // account id if the profile name is already configured in the toolkit.
    // Otherwise assign a new UUID for it.
    for (Entry<String, Profile> entry : profileConfigFile.getAllProfiles().entrySet()) {
        String profileName = entry.getKey();
        Profile profile = entry.getValue();

        String accountId = exisitingProfileAccountIds.get(profileName);
        if (accountId == null) {
            AwsToolkitCore.getDefault().logInfo("No profile found: " + profileName);
            accountId = UUID.randomUUID().toString();
        }

        AccountInfo profileAccountInfo = new AccountInfoImpl(accountId,
                new SdkProfilesCredentialsConfiguration(prefStore, accountId, profile),
                // Profile accounts use profileName as the preference name prefix
                // @see PluginPreferenceStoreAccountOptionalConfiguration
                new PluginPreferenceStoreAccountOptionalConfiguration(prefStore, profileName));
        profileAccountInfoCache.put(accountId, profileAccountInfo);
    }

    /* Update the preference store metadata for the newly loaded profile accounts */

    updateProfileAccountMetadataInPreferenceStore(profileAccountInfoCache.values());
}

From source file:com.amazonaws.eclipse.datatools.sqltools.tablewizard.simpledb.ui.popup.actions.NewDomainWizardAction.java

License:Apache License

@Override
public void run() {
    if (!this.event.getSelection().isEmpty()) {
        try {/*  w ww .j  a v  a  2  s.  c  om*/
            Display display = Display.getCurrent();
            Object o = ((IStructuredSelection) this.event.getSelection()).getFirstElement();
            Database db = findDatabase(o);
            if (db != null) {
                ConnectionInfo info = ConnectionUtil.getConnectionForEObject(db);
                if (info != null) {
                    InputDialog dlg = new InputDialog(display.getActiveShell(), Messages.CreateNewDomain,
                            Messages.NewDomainName, "", new IInputValidator() { //$NON-NLS-1$

                                public String isValid(final String newText) {
                                    return newText != null && newText.trim().length() > 0 ? null
                                            : Messages.EmptyDomainName;
                                }

                            });
                    if (dlg.open() == Window.OK) {
                        String domainName = dlg.getValue();

                        if (!Pattern.matches("^[\\w\\.-]{3,255}+$", domainName)) { //$NON-NLS-1$
                            MessageDialog.openError(Display.getCurrent().getActiveShell(),
                                    Messages.InvalidDomainName, Messages.InvalidDomainNameDescription);
                            return;
                        }

                        performFinish(info, domainName, db);
                    }
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.amazonaws.eclipse.ec2.ui.views.instances.CreateAmiAction.java

License:Apache License

private void createAmiFromInstance(Instance instance) {
    boolean userIdIsValid = (InstanceSelectionTable.accountInfo.getUserId() != null);
    if (!InstanceSelectionTable.accountInfo.isValid()
            || !InstanceSelectionTable.accountInfo.isCertificateValid() || !userIdIsValid) {
        String message = "Your AWS account information doesn't appear to be fully configured yet.  "
                + "To bundle an instance you'll need all the information configured, "
                + "including your AWS account ID, EC2 certificate and private key file."
                + "\n\nWould you like to configure it now?";

        if (MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
                "Configure AWS Account Information", message)) {
            new SetupAwsAccountAction().run();
        }/*  w ww . j  a v  a2s. co  m*/

        return;
    }

    KeyPairManager keyPairManager = new KeyPairManager();
    String keyName = instance.getKeyName();
    String keyPairFilePath = keyPairManager
            .lookupKeyPairPrivateKeyFile(AwsToolkitCore.getDefault().getCurrentAccountId(), keyName);

    if (keyPairFilePath == null) {
        String message = "There is no private key registered for the key this host was launched with ("
                + keyName + ").";
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "No Registered Private Key", message);
        return;
    }

    BundleDialog bundleDialog = new BundleDialog(Display.getCurrent().getActiveShell());
    if (bundleDialog.open() != IDialogConstants.OK_ID)
        return;

    String bundleName = bundleDialog.getImageName();
    String s3Bucket = bundleDialog.getS3Bucket();

    BundleJob job = new BundleJob(instance, s3Bucket, bundleName);
    job.schedule();
}

From source file:com.amazonaws.eclipse.lambda.serverless.handler.DeployServerlessProjectHandler.java

License:Open Source License

public static void doDeployServerlessTemplate(IProject project) {
    List<String> handlerClasses = UploadFunctionUtil.findValidHandlerClass(project);
    if (handlerClasses.isEmpty()) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Invalid AWS Lambda Project",
                "No Lambda function handler class is found in the project. "
                        + "You need to have at least one concrete class that implements the "
                        + "com.amazonaws.services.lambda.runtime.RequestHandler interface.");
        return;//  w w  w  .j  av  a 2  s. c o m
    }
    String packagePrefix = getPackagePrefix(handlerClasses);
    if (packagePrefix == null) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Invalid Serverless Project",
                "The Serverless project function structure is not valid.");
        return;
    }
    WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(),
            new DeployServerlessProjectWizard(project, packagePrefix));
    wizardDialog.open();
}

From source file:com.amazonaws.eclipse.lambda.upload.wizard.handler.UploadFunctionToLambdaCommandHandler.java

License:Open Source License

public static void doUploadFunctionProjectToLambda(IProject project) {

    // Load valid request handler classes

    List<String> handlerClasses = UploadFunctionUtil.findValidHandlerClass(project);

    if (handlerClasses == null || handlerClasses.isEmpty()) {
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Invalid AWS Lambda Project",
                "No Lambda function handler class is found in the project. "
                        + "You need to have at least one concrete class that implements the "
                        + "com.amazonaws.services.lambda.runtime.RequestHandler interface.");
        return;/*w ww  . ja v a  2  s.  c o m*/
    }

    // Load existing lambda project metadata

    LambdaFunctionProjectMetadata md = FunctionProjectUtil.loadLambdaProjectMetadata(project);

    if (md != null && !md.isValid()) {
        md = null;
        LambdaPlugin.getDefault().logInfo("Ignoring the existing metadata for project [" + project.getName()
                + "] since the content is invalid.");
    }

    WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(),
            new UploadFunctionWizard(project, handlerClasses, md));
    wizardDialog.open();
}

From source file:com.amazonaws.eclipse.opsworks.deploy.wizard.DeployProjectToOpsworksWizard.java

License:Open Source License

@Override
public boolean performFinish() {

    try {//from www.  ja  va2s.  c o m
        getContainer().run(true, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                monitor.beginTask(
                        "Deploying local project [" + dataModel.getProject().getName() + "] to OpsWorks", 110);

                final String deploymentId = DeployUtils.runDeployment(dataModel, monitor);

                // Open deployment progress tracker (10/110)
                monitor.subTask("Waiting for the deployment to finish...");

                Job trackProgressJob = new Job("Waiting for the deployment to finish") {
                    @Override
                    protected IStatus run(IProgressMonitor monitor) {

                        monitor.beginTask(String.format("Waiting deployment [%s] to finish...", deploymentId),
                                IProgressMonitor.UNKNOWN);

                        String endpoint = dataModel.getRegion().getServiceEndpoints()
                                .get(ServiceAbbreviations.OPSWORKS);
                        AWSOpsWorks client = AwsToolkitCore.getClientFactory()
                                .getOpsWorksClientByEndpoint(endpoint);

                        try {
                            final Deployment deployment = waitTillDeploymentFinishes(client, deploymentId,
                                    monitor);

                            if ("successful".equalsIgnoreCase(deployment.getStatus())) {
                                final App appDetail = client
                                        .describeApps(
                                                new DescribeAppsRequest().withAppIds(deployment.getAppId()))
                                        .getApps().get(0);

                                Display.getDefault().syncExec(new Runnable() {
                                    public void run() {
                                        MessageDialog.openInformation(Display.getDefault().getActiveShell(),
                                                "Deployment success",
                                                String.format("Deployment [%s] succeeded (Instance count: %d). "
                                                        + "The application will be available at %s://{instance-public-endpoint}/%s/",
                                                        deployment.getDeploymentId(),
                                                        deployment.getInstanceIds().size(),
                                                        appDetail.isEnableSsl() ? "https" : "http",
                                                        appDetail.getShortname()));
                                    }
                                });
                                return ValidationStatus.ok();

                            } else {
                                Display.getDefault().syncExec(new Runnable() {
                                    public void run() {
                                        MessageDialog.openError(Display.getDefault().getActiveShell(),
                                                "Deployment failed", "");
                                    }
                                });
                                return ValidationStatus.error("The deployment failed.");
                            }

                        } catch (Exception e) {
                            return ValidationStatus.error("Unable to query the progress of the deployment", e);
                        }
                    }

                    private Deployment waitTillDeploymentFinishes(AWSOpsWorks client, String deploymentId,
                            IProgressMonitor monitor) throws InterruptedException {

                        while (true) {
                            Deployment deployment = client
                                    .describeDeployments(
                                            new DescribeDeploymentsRequest().withDeploymentIds(deploymentId))
                                    .getDeployments().get(0);

                            monitor.subTask(String.format("Instance count: %d, Last status: %s",
                                    deployment.getInstanceIds().size(), deployment.getStatus()));

                            if ("successful".equalsIgnoreCase(deployment.getStatus())
                                    || "failed".equalsIgnoreCase(deployment.getStatus())) {
                                return deployment;
                            }

                            Thread.sleep(5 * 1000);
                        }
                    }
                };

                trackProgressJob.setUser(true);
                trackProgressJob.schedule();

                monitor.worked(10);

                monitor.done();
            }
        });

    } catch (InvocationTargetException e) {
        OpsWorksPlugin.getDefault().reportException("Unexpected error during deployment", e.getCause());

    } catch (InterruptedException e) {
        OpsWorksPlugin.getDefault().reportException("Unexpected InterruptedException during deployment",
                e.getCause());
    }

    return true;
}

From source file:com.amitinside.e4.rcp.todo.handlers.UpdateHandler.java

License:Apache License

@Execute
public void execute(final IProvisioningAgent agent, final Shell parent, final UISynchronize sync,
        final IWorkbench workbench) {
    Job j = new Job("Update Job") {
        private boolean doInstall = false;

        /*/*  w  w w . j av  a  2s  .  co m*/
         * (non-Javadoc)
         * 
         * @see
         * org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime
         * .IProgressMonitor)
         */
        @Override
        protected IStatus run(final IProgressMonitor monitor) {

            /* 1. Prepare update plumbing */

            final ProvisioningSession session = new ProvisioningSession(agent);
            final UpdateOperation operation = new UpdateOperation(session);

            // Create uri
            URI uri = null;
            try {
                uri = new URI(REPOSITORY_LOC);
            } catch (final URISyntaxException e) {
                sync.syncExec(new Runnable() {
                    @Override
                    public void run() {
                        MessageDialog.openError(parent, "URI invalid", e.getMessage());
                    }
                });
                return Status.CANCEL_STATUS;
            }

            // Set location of artifact and metadata repo
            // (Explain difference between meta und artifact repo)
            operation.getProvisioningContext().setArtifactRepositories(new URI[] { uri });
            operation.getProvisioningContext().setMetadataRepositories(new URI[] { uri });

            /* 2. Check for updates */

            // Run update checks causing I/O
            final IStatus status = operation.resolveModal(monitor);

            // Failed to find updates (inform user and exit)
            if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
                sync.syncExec(new Runnable() {
                    /*
                     * (non-Javadoc)
                     * 
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        MessageDialog.openWarning(parent, "No update",
                                "No updates for the current installation have been found");
                    }
                });
                return Status.CANCEL_STATUS;
            }

            /* 3. Ask if updates should be installed and run installation */

            // found updates, ask user if to install?
            if (status.isOK() && status.getSeverity() != IStatus.ERROR) {
                sync.syncExec(new Runnable() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        String updates = "";
                        Update[] possibleUpdates = operation.getPossibleUpdates();
                        for (Update update : possibleUpdates) {
                            updates += update + "\n";
                        }
                        doInstall = MessageDialog.openQuestion(parent, "Relly install updates?", updates);
                    }
                });
            }

            // Install! (causing I/0)
            if (doInstall) {
                final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
                // Updates cannot run from within Eclipse IDE!!!
                if (provisioningJob == null) {
                    System.err.println("Running update from within Eclipse IDE? This won't work!!!");
                    throw new NullPointerException();
                }

                // Register a job change listener to track
                // installation progress and notify user upon success
                provisioningJob.addJobChangeListener(new JobChangeAdapter() {
                    @Override
                    public void done(IJobChangeEvent event) {
                        if (event.getResult().isOK()) {
                            sync.syncExec(new Runnable() {

                                @Override
                                public void run() {
                                    boolean restart = MessageDialog.openQuestion(parent,
                                            "Updates installed, restart?",
                                            "Updates have been installed successfully, do you want to restart?");
                                    if (restart) {
                                        workbench.restart();
                                    }
                                }
                            });

                        }
                        super.done(event);
                    }
                });

                provisioningJob.schedule();
            }
            return Status.OK_STATUS;
        }
    };
    j.schedule();
}

From source file:com.amitinside.e4.rcp.todo.parts.EMFTodoDetailsPart.java

License:Apache License

@Persist
public void save(Shell shell) {
    if (flagBeforeSave) {
        service.saveTodo(todo);//from w ww .j  a  v a  2  s . co m
        dirty.setDirty(false);
        return;
    }
    MessageDialog.openError(shell, "Error while saving changes", "Please check all inputs");

}