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:eu.modelwriter.marker.ui.internal.views.visualizationview.commands.DeleteAtomCommand.java

License:Open Source License

private void deleteMarker() {
    try {//from   www.  java  2  s  . c  o  m
        final IMarker beDeleted = marker;
        if (beDeleted != null && beDeleted.exists()) {
            final MessageDialog warningDialog = new MessageDialog(Activator.getShell(), "Warning!", null,
                    "If you delete marker, all relations of this marker has been removed! Do you want to continue to delete marker?",
                    MessageDialog.WARNING, new String[] { "YES", "NO" }, 0);
            if (warningDialog.open() != 0) {
                return;
            }

            findCandidateToTypeChangingMarkers(beDeleted);
            final String sourceIdOfSelectedMarker = MarkUtilities.getSourceId(beDeleted);

            for (final IMarker iMarker : candidateToTypeChanging) {
                AnnotationFactory.convertAnnotationType(iMarker, true,
                        MarkUtilities.compare(MarkUtilities.getSourceId(iMarker), sourceIdOfSelectedMarker),
                        AlloyUtilities.getTotalTargetCount(iMarker));
            }
            final String markerText = MarkUtilities.getText(beDeleted);

            if (MarkUtilities.getLeaderId(beDeleted) != null) {
                final String markerGroupId = MarkUtilities.getGroupId(beDeleted);
                final List<IMarker> markers = MarkerFactory.findMarkersByGroupId(beDeleted.getResource(),
                        markerGroupId);

                for (int i = markers.size() - 1; i >= 0; i--) {
                    deleteFromAlloyXML(markers.get(i));
                    AnnotationFactory.removeAnnotation(markers.get(i));
                    markers.get(i).delete();
                }
            } else {
                deleteFromAlloyXML(beDeleted);
                AnnotationFactory.removeAnnotation(beDeleted);
                beDeleted.delete();
            }
            final MessageDialog dialog = new MessageDialog(Activator.getShell(),
                    "Mark will be deleted by this wizard", null,
                    "\"" + markerText + "\" has been selected to be unmarked", MessageDialog.INFORMATION,
                    new String[] { "OK" }, 0);
            dialog.open();
        }
    } catch (final CoreException e) {
        e.printStackTrace();
    }
}

From source file:eu.modelwriter.marker.ui.internal.views.visualizationview.commands.DeleteAtomCommand.java

License:Open Source License

@Override
public void run() {
    // FIXME//from w w w . j  a v  a 2s .  c  o m
    // editor = MarkerFactory.getOpenEditorOfMarker(marker);
    if (AlloyUtilities.isExists()) {
        candidateToTypeChanging = new ArrayList<IMarker>();
        deleteMarker();
        // this.refresh();
    } else {
        final MessageDialog infoDialog = new MessageDialog(Activator.getShell(), "System Information", null,
                "You dont have any registered alloy file to system.", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        infoDialog.open();
    }
}

From source file:eu.modelwriter.marker.ui.internal.views.visualizationview.commands.MappingCommand.java

License:Open Source License

@Override
public void run() {
    if (AlloyUtilities.isExists()) {
        if (this.marker != null && this.marker.exists()) {
            MappingCommand.chooseForAction(this.marker);
        } else {//from w w w .  j a va  2 s . c o  m
            final MessageDialog dialog = new MessageDialog(Activator.getShell(),
                    "There is no marker in this position", null, "Please select valid marker",
                    MessageDialog.INFORMATION, new String[] { "OK" }, 0);
            dialog.open();
        }
    } else {
        final MessageDialog infoDialog = new MessageDialog(Activator.getShell(), "System Information", null,
                "You dont have any registered alloy file to system.", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        infoDialog.open();
    }
}

From source file:eu.modelwriter.marker.ui.internal.wizards.mappingwizard.MarkerMapping.java

License:Open Source License

private void run() {
    if (MarkerMapping.marker != null && MarkerMapping.marker.exists()) {
        chooseForAction(MarkerMapping.marker);
    } else {/*from   www.ja v a 2s.  co  m*/
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
                "There is no marker in this position", null, "Please select valid marker",
                MessageDialog.INFORMATION, new String[] { "OK" }, 0);
        dialog.open();
    }
}

From source file:eu.modelwriter.marker.ui.internal.wizards.markallinwswizard.MarkAllInWsWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final Object[] checkedElements = MarkAllInWsPage.checkboxTreeViewer.getCheckedElements();
    final String text = this.textSelection.getText();
    final String leader_id = UUID.randomUUID().toString();
    boolean success = false;

    final Image image = MarkerActivator.getDefault().getImageRegistry()
            .get(MarkerActivator.Images.IMAGE_MODELWRITER_ID);
    final ProgressMonitorDialog pmd = new ProgressMonitorDialog(
            Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell());
    ProgressMonitorDialog.setDefaultImage(image);
    pmd.open();//w  w w  .java  2s  . c o m
    final IProgressMonitor pmdmoni = pmd.getProgressMonitor();
    try {
        pmdmoni.beginTask("Marking", checkedElements.length);
        for (int i = 0; i < checkedElements.length && !pmdmoni.isCanceled(); i++) {
            try {
                if (checkedElements[i] instanceof IFile) {
                    final IFile iFile = (IFile) checkedElements[i];
                    pmdmoni.subTask(iFile.getName());
                    pmdmoni.worked(1);

                    if (!iFile.getFileExtension().equals("xmi") && !iFile.getFileExtension().equals("ecore")
                            && !iFile.getFileExtension().equals("reqif")) {
                        final String charSet = iFile.getCharset();
                        final Scanner scanner = new Scanner(iFile.getContents(), charSet);
                        final IDocument document = new Document(scanner.useDelimiter("\\A").next());
                        scanner.close();

                        final String fullText = document.get();
                        boolean hasLeader = false;
                        int index = 0;
                        int offset = 0;
                        final int lenght = this.textSelection.getLength();
                        final String id = UUID.randomUUID().toString();

                        if (lenght != 0) {
                            while ((offset = fullText.indexOf(text, index)) != -1) {
                                final TextSelection nextSelection = new TextSelection(document, offset, lenght);
                                if (MarkerFactory.findMarkerByOffset(iFile, offset) == null) {
                                    final IMarker mymarker = MarkerFactory.createMarker(iFile, nextSelection);
                                    MarkUtilities.setGroupId(mymarker, id);
                                    if (!iFile.equals(this.file)) {
                                        if (hasLeader == false) {
                                            MarkUtilities.setLeaderId(mymarker, leader_id);
                                            hasLeader = true;
                                        }
                                    } else {
                                        if (this.textSelection.getOffset() == offset) {
                                            MarkUtilities.setLeaderId(mymarker, leader_id);
                                        }
                                    }

                                    this.addToAlloyXML(mymarker);
                                    AnnotationFactory.addAnnotation(mymarker,
                                            AnnotationFactory.ANNOTATION_MARKING);
                                }
                                index = offset + lenght;
                            }
                        }
                        success = true;
                    } else {
                        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
                                "Mark All In Workspace", null,
                                iFile.getName() + " doesn't supported for this command.",
                                MessageDialog.INFORMATION, new String[] { "OK" }, 0);
                        dialog.open();
                        MarkAllInWsPage.checkboxTreeViewer.setChecked(iFile, false);
                    }
                }
            } catch (final CoreException e) {
                e.printStackTrace();
            }
        }
    } finally {
        pmdmoni.done();
    }
    pmd.close();

    if (success == true) {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark All In Workspace",
                null, "Selected project(s) have been marked by selected text", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        dialog.open();
        return true;
    } else {
        return false;
    }
}

From source file:eu.modelwriter.marker.ui.internal.wizards.markerwizard.MarkerWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    AlloyOtherSolutionReasoning.getInstance().finish();

    this.candidateToTypeChanging = new ArrayList<IMarker>();
    if (MarkerPage.markTreeViewer.getTree().getSelection().length == 1) {
        if (MarkerPage.markTreeViewer.getTree().getSelection()[0].getText().endsWith("{abs}")) {
            final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Trace Type Information",
                    null, "Selected type is not appropriate because it is marked as Abstact",
                    MessageDialog.INFORMATION, new String[] { "OK" }, 0);
            dialog.open();
            return false;
        }/*from   ww  w .ja  v  a 2s  . c om*/

        if (!MarkerPage.markTreeViewer.getTree().getItems()[0]
                .equals(MarkerPage.markTreeViewer.getTree().getSelection()[0])) {
            if (this.selection != null) {
                CreateMarkerWithType.createMarker(this.file, this.selection,
                        MarkerPage.markTreeViewer.getTree().getSelection()[0].getText());
                // MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
                // "Marker Type Information", null, "Marker has been created with selected type",
                // MessageDialog.INFORMATION, new String[] {"OK"}, 0);
                // dialog.open();
            } else {
                this.findCandidateToTypeChangingMarkers(this.selectedMarker);
                this.selectedMarker = AnnotationFactory.convertAnnotationType(this.selectedMarker, true, true,
                        AlloyUtilities.getTotalTargetCount(this.selectedMarker));

                IMarker marker = null;
                for (int i = 1; i < this.candidateToTypeChanging.size(); i++) {
                    marker = this.candidateToTypeChanging.get(i);
                    AnnotationFactory.convertAnnotationType(marker, true,
                            MarkUtilities.compare(marker, this.selectedMarker),
                            AlloyUtilities.getTotalTargetCount(marker));
                }
                AlloyUtilities.removeAllRelationsOfMarker(this.selectedMarker);
                AlloyUtilities.removeRelationOfMarker(this.selectedMarker);
                if (MarkUtilities.getGroupId(this.selectedMarker) != null) {
                    final List<IMarker> list = MarkerFactory.findMarkersByGroupId(
                            this.selectedMarker.getResource(), MarkUtilities.getGroupId(this.selectedMarker));
                    for (final IMarker iMarker : list) {
                        AlloyUtilities.removeTypeFromMarker(iMarker);
                        MarkUtilities.setType(iMarker,
                                MarkerPage.markTreeViewer.getTree().getSelection()[0].getText());
                        if (MarkUtilities.getLeaderId(iMarker) != null) {
                            AlloyUtilities.addTypeToMarker(iMarker);
                        }
                        AlloyUtilities.addMarkerToRepository(this.selectedMarker);
                    }
                } else {
                    AlloyUtilities.removeTypeFromMarker(this.selectedMarker);
                    MarkUtilities.setType(this.selectedMarker,
                            MarkerPage.markTreeViewer.getTree().getSelection()[0].getText());
                    AlloyUtilities.addTypeToMarker(this.selectedMarker);
                    AlloyUtilities.addMarkerToRepository(this.selectedMarker);
                }

                // MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
                // "Marker Type Information", null, "Selected type added to selected marker",
                // MessageDialog.INFORMATION, new String[] {"OK"}, 0);
                // dialog.open();
            }
            return true;
        } else {
            final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Trace Type Information",
                    null, "Please select a valid marker type.", MessageDialog.INFORMATION,
                    new String[] { "OK" }, 0);
            dialog.open();
            return false;
        }
    } else {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Trace Type Information",
                null, "Please select one trace type.", MessageDialog.INFORMATION, new String[] { "OK" }, 0);
        dialog.open();
        return false;
    }
}

From source file:eu.numberfour.n4js.product.N4JSApplication.java

License:Open Source License

/**
 * Return true if the argument directory is ok to use as a workspace and false otherwise. A version check will be
 * performed, and a confirmation box may be displayed on the argument shell if an older version is detected.
 *
 * @return true if the argument URL is ok to use as a workspace and false otherwise.
 *///from www. ja  va 2s  .c  o  m
private boolean checkValidWorkspace(final Shell shell, final URL url) {
    // a null url is not a valid workspace
    if (url == null) {
        return false;
    }

    if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) {
        // no reference bundle installed, no check possible
        return true;
    }

    final Version version = readWorkspaceVersion(url);
    // if the version could not be read, then there is not any existing
    // workspace data to trample, e.g., perhaps its a new directory that
    // is just starting to be used as a workspace
    if (version == null) {
        return true;
    }

    final Version ide_version = toMajorMinorVersion(WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION);
    final Version workspace_version = toMajorMinorVersion(version);
    final int versionCompareResult = workspace_version.compareTo(ide_version);

    // equality test is required since any version difference (newer
    // or older) may result in data being trampled
    if (versionCompareResult == 0) {
        return true;
    }

    // At this point workspace has been detected to be from a version
    // other than the current ide version -- find out if the user wants
    // to use it anyhow.
    int severity;
    String title;
    String message;
    if (versionCompareResult < 0) {
        // Workspace < IDE. Update must be possible without issues,
        // so only inform user about it.
        severity = INFORMATION;
        title = IDEApplication_versionTitle_olderWorkspace;
        message = NLS.bind(IDEApplication_versionMessage_olderWorkspace, url.getFile());
    } else {
        // Workspace > IDE. It must have been opened with a newer IDE version.
        // Downgrade might be problematic, so warn user about it.
        severity = WARNING;
        title = IDEApplication_versionTitle_newerWorkspace;
        message = NLS.bind(IDEApplication_versionMessage_newerWorkspace, url.getFile());
    }

    final MessageDialog dialog = new MessageDialog(shell, title, null, message, severity,
            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    return dialog.open() == Window.OK;
}

From source file:eu.numberfour.n4js.ui.export.AbstractExportToSingleFileWizardPage.java

License:Open Source License

/**
 * The default implementation of this <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString/*ww  w.j a  va  2s  .c o  m*/
 *            the path of the archive
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
 *         <code>"CANCEL"</code>
 */
@Override
public String queryOverwrite(String pathString) {

    IPath path = Path.fromOSString(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
    } else {
        messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
                path.lastSegment(), path.removeLastSegments(1).toOSString());
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            null, messageString, MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        @Override
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:eu.numberfour.n4js.ui.export.AbstractExportToSingleFileWizardPage.java

License:Open Source License

/**
 * Displays a Yes/No question to the user with the specified message and returns the user's response.
 *
 * @param message//from www . j a va  2s . c  o  m
 *            the question to ask
 * @return <code>true</code> for Yes, and <code>false</code> for No
 */
private boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question,
            (Image) null, message, MessageDialog.NONE,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    return dialog.open() == 0;
}

From source file:eu.numberfour.n4js.ui.preferences.N4JSBuilderPreferencePage.java

License:Open Source License

/**
 * This method has been copied and adapted from org.eclipse.xtext.ui.preferences.OptionsConfigurationBlock.
 *///  www  .ja va2 s  . c  o m
@Override
protected boolean processChanges(IWorkbenchPreferenceContainer container) {
    boolean needsBuild = !getPreferenceChanges().isEmpty() | projectSpecificChanged;
    boolean doBuild = false;
    if (needsBuild) {
        int count = getRebuildCount();
        if (count > rebuildCount) {
            needsBuild = false;
            rebuildCount = count;
        }
    }
    if (needsBuild) {
        String[] strings = getFullBuildDialogStrings(project == null);
        if (strings != null) {
            MessageDialog dialog = new MessageDialog(this.getShell(), strings[0], null, strings[1],
                    MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL,
                            IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                    2);
            int res = dialog.open();
            if (res == 0) {
                doBuild = true;
            } else if (res != 1) {
                return false;
            }
        }
    }
    if (container != null) {
        if (doBuild) {
            incrementRebuildCount();
            container.registerUpdateJob(getBuildJob(getProject()));
        }
    } else {
        if (doBuild) {
            getBuildJob(getProject()).schedule();
        }
    }
    return true;
}