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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

From source file:com.amazonaws.eclipse.core.ui.preferences.AwsAccountPreferencePageTab.java

License:Apache License

/**
 * Add the enable-region-default-account check-box and the remove-this-tab
 * button//from  w  ww  .j av a  2s  .com
 */
private void addEnableRegionDefaultControls(Composite parent) {
    enableRegionDefaultAccount = new BooleanFieldEditor(getRegionAccountEnabledPrefKey(),
            "Enable region default account for " + region.getName(), parent);
    enableRegionDefaultAccount.setPreferenceStore(getPreferenceStore());

    Button removeTabButton = new Button(parent, SWT.PUSH);
    removeTabButton.setText("Remove");
    removeTabButton.setToolTipText("Remove default account configuration for this region.");
    removeTabButton.setImage(AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_REMOVE));
    removeTabButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    removeTabButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            MessageDialog confirmRemoveTabDialog = new MessageDialog(Display.getDefault().getActiveShell(),
                    "Remove all accounts for " + region.getName(),
                    AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_AWS_ICON),
                    "Are you sure you want to remove all the configured accounts for " + region.getName() + "?",
                    MessageDialog.CONFIRM, new String[] { "Cancel", "OK" }, 1);
            if (confirmRemoveTabDialog.open() == 1) {
                AwsAccountPreferencePageTab.this.dispose();
            }

        }
    });
}

From source file:com.amazonaws.eclipse.elasticbeanstalk.jobs.TerminateEnvironmentJob.java

License:Open Source License

@Override
protected IStatus run(IProgressMonitor monitor) {
    AWSElasticBeanstalk client = AwsToolkitCore.getClientFactory(environment.getAccountId())
            .getElasticBeanstalkClientByEndpoint(environment.getRegionEndpoint());
    EnvironmentBehavior behavior = (EnvironmentBehavior) environment.getServer()
            .loadAdapter(EnvironmentBehavior.class, monitor);

    final DialogHolder dialogHolder = new DialogHolder();
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(),
                    "Confirm environment termination",
                    AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_AWS_ICON),
                    "Are you sure you want to terminate the environment " + environment.getEnvironmentName()
                            + "?  All EC2 instances in the environment will be terminated and you will be unable to use "
                            + "this environment again until you have recreated it.",
                    MessageDialog.QUESTION_WITH_CANCEL, new String[] { "OK", "Cancel" }, 1);
            dialogHolder.dialog = dialog;
            dialog.open();/*from   w w  w  .  jav a  2s.  com*/
        }
    });

    if (dialogHolder.dialog.getReturnCode() != 0) {
        behavior.updateServerState(IServer.STATE_STOPPED);
        return Status.OK_STATUS;
    }

    try {
        if (doesEnvironmentExist()) {
            client.terminateEnvironment(
                    new TerminateEnvironmentRequest().withEnvironmentName(environment.getEnvironmentName()));
        }

        // It's more correct to set the state to stopping, rather than stopped immediately, 
        // but if we set it to stopping, WTP will block workspace actions waiting for the 
        // environment's state to get updated to stopped.  To prevent this, we stop immediately.
        behavior.updateServerState(IServer.STATE_STOPPED);
        return Status.OK_STATUS;
    } catch (AmazonClientException ace) {
        return new Status(Status.ERROR, ElasticBeanstalkPlugin.PLUGIN_ID, "Unable to terminate environment "
                + environment.getEnvironmentName() + " : " + ace.getMessage(), ace);
    }
}

From source file:com.amazonaws.eclipse.explorer.dynamodb.CreateTableSecondPage.java

License:Apache License

public void createControl(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);

    GridDataFactory.fillDefaults().grab(true, true).applyTo(comp);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(comp);
    createLinkSection(comp);//  w w  w .  j a  va  2  s. c o m

    // LSI
    Group lsiGroup = CreateTablePageUtil.newGroup(comp, "Local Secondary Index", 1);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(lsiGroup);

    Button addLSIButton = new Button(lsiGroup, SWT.PUSH);
    addLSIButton.setText("Add Local Secondary Index");
    addLSIButton.setImage(AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_ADD));
    addLSIButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (localSecondaryIndexes.size() >= MAX_NUM_LSI) {
                new MessageDialog(getShell(), "Validation Error", null,
                        "A table cannot have more than five local secondary indexes.", MessageDialog.ERROR,
                        new String[] { "OK", "CANCEL" }, 0).open();
                return;

            }
            AddLSIDialog addLSIDialog = new AddLSIDialog(Display.getCurrent().getActiveShell(),
                    wizard.getDataModel());
            if (addLSIDialog.open() == 0) {
                // Add the LSI schema object
                localSecondaryIndexes.add(addLSIDialog.getLocalSecondaryIndex());
                // Add the key attribute definitions associated with this LSI
                localSecondaryIndexKeyAttributes.add(addLSIDialog.getIndexRangeKeyAttributeDefinition());
                wizard.collectAllAttribtueDefinitions();

                localSecondaryIndexesTable.refresh();
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    // LSI label provider
    IndexTable.IndexTableLabelProvider localSecondaryIndexTableLabelProvider = new IndexTable.IndexTableLabelProvider() {

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (element instanceof LocalSecondaryIndex == false)
                return "";
            LocalSecondaryIndex index = (LocalSecondaryIndex) element;
            switch (columnIndex) {
            case 0: // index name
                return index.getIndexName();
            case 1: // index range key
                String returnString = "";
                returnString += index.getKeySchema().get(1).getAttributeName() + " (";
                returnString += findAttributeType(index.getKeySchema().get(1).getAttributeName()) + ")";
                return returnString;
            case 2: // index projection
                return IndexTable.getProjectionAttributes(index.getProjection(), index.getKeySchema(),
                        wizard.getDataModel());
            }
            return element.toString();
        }

    };
    localSecondaryIndexesTable = new IndexTable<LocalSecondaryIndex>(lsiGroup, localSecondaryIndexes,
            localSecondaryIndexTableLabelProvider) {

        @Override
        protected void createColumns(TableColumnLayout columnLayout, Table table) {
            createColumn(table, columnLayout, "Index Name");
            createColumn(table, columnLayout, "Attribute To Index");
            createColumn(table, columnLayout, "Projected Attributes");
        }

        @Override
        protected void onRemoveItem(int removed) {
            localSecondaryIndexKeyAttributes.remove(removed);
            wizard.collectAllAttribtueDefinitions();
        }
    };
    GridDataFactory.fillDefaults().grab(true, true).applyTo(localSecondaryIndexesTable);

    // GSI
    Group gsiGroup = CreateTablePageUtil.newGroup(comp, "Global Secondary Index", 1);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(gsiGroup);

    Button addGSIButton = new Button(gsiGroup, SWT.PUSH);
    addGSIButton.setText("Add Global Secondary Index");
    addGSIButton.setImage(AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_ADD));
    addGSIButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            if (globalSecondaryIndexes.size() >= MAX_NUM_GSI) {
                new MessageDialog(getShell(), "Validation Error", null,
                        "A table cannot have more than five global secondary indexes.", MessageDialog.ERROR,
                        new String[] { "OK", "CANCEL" }, 0).open();
                return;

            }
            AddGSIDialog addGSIDialog = new AddGSIDialog(Display.getCurrent().getActiveShell(),
                    wizard.getDataModel());
            if (addGSIDialog.open() == 0) {
                globalSecondaryIndexes.add(addGSIDialog.getGlobalSecondaryIndex());
                globalSecondaryIndexKeyAttributes.add(addGSIDialog.getIndexKeyAttributeDefinitions());
                wizard.collectAllAttribtueDefinitions();

                globalSecondaryIndexesTable.refresh();
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    // GSI label provider
    IndexTable.IndexTableLabelProvider globalSecondaryIndexTableLabelProvider = new IndexTable.IndexTableLabelProvider() {

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (element instanceof GlobalSecondaryIndex == false)
                return "";
            GlobalSecondaryIndex index = (GlobalSecondaryIndex) element;
            switch (columnIndex) {
            case 0: // index name
                return index.getIndexName();
            case 1: // index hash
                String returnString = "";
                returnString += index.getKeySchema().get(0).getAttributeName() + " (";
                returnString += findAttributeType(index.getKeySchema().get(0).getAttributeName()) + ")";
                return returnString;
            case 2: // index range
                returnString = "";
                if (index.getKeySchema().size() > 1) {
                    returnString += index.getKeySchema().get(1).getAttributeName() + " (";
                    returnString += findAttributeType(index.getKeySchema().get(1).getAttributeName()) + ")";
                }
                return returnString;
            case 3: // index projection
                return IndexTable.getProjectionAttributes(index.getProjection(), index.getKeySchema(),
                        wizard.getDataModel());
            case 4: // index throughput
                return "Read : " + index.getProvisionedThroughput().getReadCapacityUnits() + ", Write : "
                        + index.getProvisionedThroughput().getWriteCapacityUnits();
            default:
                return "";
            }
        }

    };
    globalSecondaryIndexesTable = new IndexTable<GlobalSecondaryIndex>(gsiGroup, globalSecondaryIndexes,
            globalSecondaryIndexTableLabelProvider) {

        @Override
        protected void createColumns(TableColumnLayout columnLayout, Table table) {
            createColumn(table, columnLayout, "Index Name");
            createColumn(table, columnLayout, "Index Hash Key");
            createColumn(table, columnLayout, "Index Range Key");
            createColumn(table, columnLayout, "Projected Attributes");
            createColumn(table, columnLayout, "Provisioned Throughput");
        }

        @Override
        protected void onRemoveItem(int removed) {
            globalSecondaryIndexKeyAttributes.remove(removed);
            wizard.collectAllAttribtueDefinitions();
        }
    };
    GridDataFactory.fillDefaults().grab(true, true).applyTo(globalSecondaryIndexesTable);

    setControl(comp);
}

From source file:com.amazonaws.eclipse.explorer.dynamodb.DynamoDBTableNode.java

License:Apache License

/**
 * Sets the status of the table that this node represents, and changes to
 * the corresponding open action./*from  ww w.ja  v a 2 s.co m*/
 */
public void setTableStatus(final TableStatus tableStatus) {
    this.tableStatus = tableStatus;
    if (tableStatus == null) {
        setOpenAction(new Action() {

            @Override
            public void run() {
                /*
                 * Update the table status immediately when the node is
                 * being opened, but has not been set with table status.
                 */
                AmazonDynamoDB dynamoDBClient = AwsToolkitCore.getClientFactory().getDynamoDBV2Client();
                boolean describeTableError = false;
                TableStatus updatedStatus = null;
                try {
                    updatedStatus = TableStatus.valueOf(
                            dynamoDBClient.describeTable(new DescribeTableRequest().withTableName(tableName))
                                    .getTable().getTableStatus());
                } catch (AmazonServiceException ase) {
                    if (ase.getErrorCode().equalsIgnoreCase("ResourceNotFoundException") == true) {
                        /* Show warning that the table has already been deleted */
                        MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                                "Cannot open this table",
                                AwsToolkitCore.getDefault().getImageRegistry()
                                        .get(AwsToolkitCore.IMAGE_AWS_ICON),
                                "Table has been deleted.", MessageDialog.ERROR, new String[] { "OK" }, 0);
                        dialog.open();

                        /*
                         * We need to explicitly refresh the tree view if a
                         * table node has already been deleted in DynamoDB
                         */
                        DynamoDBContentProvider.getInstance().refresh();
                        return;
                    } else {
                        describeTableError = true;
                    }
                } catch (IllegalArgumentException iae) {
                    /* Unrecognized table status */
                    describeTableError = true;
                }

                if (describeTableError) {
                    /*
                     * Still allow the user to open the table editor if we
                     * cannot get the table status now. (But the background
                     * job will still keep trying to update the table
                     * status).
                     */
                    setOpenAction(new OpenTableEditorAction(tableName));
                    return;
                }

                /* assert: updatedStatus != null */
                setTableStatus(updatedStatus);
                DynamoDBTableNode.this.getOpenAction().run();
            }
        });
    } else if (tableStatus == TableStatus.ACTIVE) {
        /*
         * Open the table editor only when the node is in ACTIVE status.
         */
        setOpenAction(new OpenTableEditorAction(tableName));
    } else {
        /*
         * For CREATING/DELETING/UPDATING, suppress opening the table editor.
         * Show a warning on the table status instead.
         */
        setOpenAction(new Action() {

            @Override
            public void run() {
                /* Show the warning that the table is CREATING/DELETING/UPDATING */
                MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                        "Cannot open this table",
                        AwsToolkitCore.getDefault().getImageRegistry().get(AwsToolkitCore.IMAGE_AWS_ICON),
                        "Cannot open this table(" + tableName + "), since it is in the status of " + tableStatus
                                + ".",
                        MessageDialog.ERROR, new String[] { "OK" }, 0);
                dialog.open();
            }
        });
    }
}

From source file:com.amazonaws.eclipse.explorer.s3.actions.DeleteBucketAction.java

License:Apache License

private Dialog newConfirmationDialog(String title, String message) {
    return new MessageDialog(Display.getDefault().getActiveShell(), title, null, message,
            MessageDialog.QUESTION, new String[] { "No", "Yes" }, 1);
}

From source file:com.amazonaws.eclipse.explorer.sns.CreateTopicWizard.java

License:Apache License

@Override
public boolean performFinish() {
    String topicName = (String) page.getInputValue(TOPIC_NAME_INPUT);
    String displayName = (String) page.getInputValue(DISPLAY_NAME_INPUT);

    AmazonSNS client = AwsToolkitCore.getClientFactory().getSNSClient();

    CreateTopicResult result = client.createTopic(new CreateTopicRequest(topicName));

    if (displayName != null && displayName.length() > 0) {
        try {//  w w w. java  2s .c o  m

            client.setTopicAttributes(new SetTopicAttributesRequest().withTopicArn(result.getTopicArn())
                    .withAttributeName(DISPLAY_NAME_ATTRIBUTE).withAttributeValue(displayName));

        } catch (AmazonClientException exception) {
            AwsToolkitCore.getDefault().logException("Error setting topic display name", exception);

            MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Warning", null,
                    ("The topic was successfully created, but the display " + "name could not be set ("
                            + exception.toString() + ")"),
                    MessageDialog.WARNING, new String[] { "OK" }, 0);
            dialog.open();
        }
    }

    ContentProviderRegistry.refreshAllContentProviders();
    return true;
}

From source file:com.amazonaws.eclipse.explorer.sns.SNSActionProvider.java

License:Apache License

private Dialog newConfirmationDialog(String title, String message) {
    return new MessageDialog(Display.getDefault().getActiveShell(), title, null, message, MessageDialog.WARNING,
            new String[] { "OK", "Cancel" }, 0);
}

From source file:com.amazonaws.eclipse.lambda.invoke.handler.InvokeFunctionHandler.java

License:Open Source License

private static void askForDeploymentFirst(IProject project) {
    MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Function not uploaded yet",
            null, "You need to upload the function to Lambda before invoking it.", MessageDialog.INFORMATION,
            new String[] { "Upload now", "Cancel" }, 0);
    int result = dialog.open();

    if (result == 0) {
        trackUploadWizardOpenedBeforeFunctionInvoke();
        UploadFunctionToLambdaCommandHandler.doUploadFunctionProjectToLambda(project);
    }//from   www.  j  a v a  2s.  com
}

From source file:com.android.glesv2debugger.ShaderEditor.java

License:Apache License

@Override
public void widgetSelected(SelectionEvent e) {
    if (e.getSource() == uploadShader && null != current) {
        uploadShader();/*from  ww w .  ja v a  2  s .  co m*/
        return;
    } else if (e.getSource() == restoreShader && null != current) {
        current.source = styledText.getText();
        styledText.setText(current.originalSource);
        return;
    }

    if (list.getSelectionCount() < 1)
        return;
    if (null != current && !current.source.equals(styledText.getText())) {
        String[] btns = { "&Upload", "&Save", "&Discard" };
        MessageDialog dialog = new MessageDialog(this.getShell(), "Shader Edited", null,
                "Shader source has been edited", MessageDialog.QUESTION, btns, 0);
        int rc = dialog.open();
        if (rc == SWT.DEFAULT || rc == 0)
            uploadShader();
        else if (rc == 1)
            current.source = styledText.getText();
        // else if (rc == 2) do nothing; selection is changing
    }
    String[] details = list.getSelection()[0].split("\\s+");
    final int contextId = Integer.parseInt(details[0], 16);
    int name = Integer.parseInt(details[2]);
    current = sampleView.debugContexts.get(contextId).currentContext.serverShader.shaders.get(name);
    styledText.setText(current.source);
}

From source file:com.android.ide.eclipse.adt.AdtPlugin.java

License:Open Source License

/**
 * Checks the location of the SDK in the prefs is valid.
 * If it is not, display a warning dialog to the user and try to display
 * some useful link to fix the situation (setup the preferences, perform an
 * update, etc.)//from  w  w w .  j  av a 2  s  .co  m
 *
 * @return True if the SDK location points to an SDK.
 *  If false, the user has already been presented with a modal dialog explaining that.
 */
public boolean checkSdkLocationAndId() {
    String sdkLocation = AdtPrefs.getPrefs().getOsSdkFolder();

    return checkSdkLocationAndId(sdkLocation, new CheckSdkErrorHandler() {
        private String mTitle = "Android SDK";

        /**
         * Handle an error, which is the case where the check did not find any SDK.
         * This returns false to {@link AdtPlugin#checkSdkLocationAndId()}.
         */
        @Override
        public boolean handleError(Solution solution, String message) {
            displayMessage(solution, message, MessageDialog.ERROR);
            return false;
        }

        /**
         * Handle an warning, which is the case where the check found an SDK
         * but it might need to be repaired or is missing an expected component.
         *
         * This returns true to {@link AdtPlugin#checkSdkLocationAndId()}.
         */
        @Override
        public boolean handleWarning(Solution solution, String message) {
            displayMessage(solution, message, MessageDialog.WARNING);
            return true;
        }

        private void displayMessage(final Solution solution, final String message, final int dialogImageType) {
            final Display disp = getDisplay();
            disp.asyncExec(new Runnable() {
                @Override
                public void run() {
                    Shell shell = disp.getActiveShell();
                    if (shell == null) {
                        shell = AdtPlugin.getShell();
                    }
                    if (shell == null) {
                        return;
                    }

                    String customLabel = null;
                    switch (solution) {
                    case OPEN_ANDROID_PREFS:
                        customLabel = "Open Preferences";
                        break;
                    case OPEN_P2_UPDATE:
                        customLabel = "Check for Updates";
                        break;
                    case OPEN_SDK_MANAGER:
                        customLabel = "Open SDK Manager";
                        break;
                    }

                    String btnLabels[] = new String[customLabel == null ? 1 : 2];
                    btnLabels[0] = customLabel;
                    btnLabels[btnLabels.length - 1] = IDialogConstants.CLOSE_LABEL;

                    MessageDialog dialog = new MessageDialog(shell, // parent
                            mTitle, null, // dialogTitleImage
                            message, dialogImageType, btnLabels, btnLabels.length - 1);
                    int index = dialog.open();

                    if (customLabel != null && index == 0) {
                        switch (solution) {
                        case OPEN_ANDROID_PREFS:
                            openAndroidPrefs();
                            break;
                        case OPEN_P2_UPDATE:
                            openP2Update();
                            break;
                        case OPEN_SDK_MANAGER:
                            openSdkManager();
                            break;
                        }
                    }
                }
            });
        }

        private void openSdkManager() {
            // Open the standalone external SDK Manager since we know
            // that ADT on Windows is bound to be locking some SDK folders.
            //
            // Also when this is invoked because SdkManagerAction.run() fails, this
            // test will fail and we'll fallback on using the internal one.
            if (SdkManagerAction.openExternalSdkManager()) {
                return;
            }

            // Otherwise open the regular SDK Manager bundled within ADT
            if (!SdkManagerAction.openAdtSdkManager()) {
                // We failed because the SDK location is undefined. In this case
                // let's open the preferences instead.
                openAndroidPrefs();
            }
        }

        private void openP2Update() {
            Display disp = getDisplay();
            if (disp == null) {
                return;
            }
            disp.asyncExec(new Runnable() {
                @Override
                public void run() {
                    String cmdId = "org.eclipse.equinox.p2.ui.sdk.update"; //$NON-NLS-1$
                    IWorkbench wb = PlatformUI.getWorkbench();
                    if (wb == null) {
                        return;
                    }

                    ICommandService cs = (ICommandService) wb.getService(ICommandService.class);
                    IHandlerService is = (IHandlerService) wb.getService(IHandlerService.class);
                    if (cs == null || is == null) {
                        return;
                    }

                    Command cmd = cs.getCommand(cmdId);
                    if (cmd != null && cmd.isDefined()) {
                        try {
                            is.executeCommand(cmdId, null/*event*/);
                        } catch (Exception ignore) {
                            AdtPlugin.log(ignore, "Failed to execute command %s", cmdId);
                        }
                    }
                }
            });
        }

        private void openAndroidPrefs() {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getDisplay().getActiveShell(),
                    "com.android.ide.eclipse.preferences.main", //$NON-NLS-1$ preferencePageId
                    null, // displayedIds
                    null); // data
            dialog.open();
        }
    });
}