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:eu.modelwriter.marker.command.MappingHandler.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    if (AlloyUtilities.isExists()) {
        MarkerMapping.getInstance().runWithSelection();
        if (Activator.getDefault().getWorkbench().getWorkbenchWindows()[0].getActivePage()
                .findView(Visualization.ID) != null) {
            Visualization.showViz();//from   w ww  .  ja v  a2 s. co m
        }
    } else {
        final MessageDialog infoDialog = new MessageDialog(MarkerActivator.getShell(), "System Information",
                null, "You dont have any registered alloy file to system.", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        infoDialog.open();
    }
    return null;
}

From source file:eu.modelwriter.marker.command.MarkAllHandler.java

License:Open Source License

private void createMarkers() {
    this.editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    this.file = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
            .getEditorInput().getAdapter(IFile.class);
    this.selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();

    ITextSelection textSelection = (ITextSelection) this.selection;

    if (MarkerFactory.findMarkerWithAbsolutePosition(this.file, textSelection.getOffset(),
            textSelection.getOffset() + textSelection.getLength()) != null) {

        MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                "In these area, there is already a marker", MessageDialog.WARNING, new String[] { "OK" }, 0);
        dialog.open();//from w w  w  . j  a  v  a 2s. co  m
    } else {
        String content = MarkerFactory.getCurrentEditorContent();
        int index = 0;
        int offset = 0;
        int length = textSelection.getLength();
        String id = UUID.randomUUID().toString();
        String leader_id = UUID.randomUUID().toString();

        if (length != 0) {
            while ((offset = content.toLowerCase().indexOf(textSelection.getText().toLowerCase(),
                    index)) != -1) {
                TextSelection nextSelection = new TextSelection(MarkerFactory.getDocument(), offset, length);
                if (MarkerFactory.findMarkerWithAbsolutePosition(this.file, offset, offset + length) == null) {
                    IMarker mymarker = MarkerFactory.createMarker(this.file, nextSelection);
                    MarkUtilities.setGroupId(mymarker, id);
                    if (textSelection.getOffset() == offset) {
                        MarkUtilities.setLeaderId(mymarker, leader_id);
                    }
                    AnnotationFactory.addAnnotation(mymarker, AnnotationFactory.ANNOTATION_MARKING);
                    this.addToAlloyXML(mymarker);
                }
                index = offset + length;
            }
            // MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
            // "Mark Information will be provided by this wizard.", null,
            // "\"" + textSelection.getText() + "\" has been selected to be marked",
            // MessageDialog.INFORMATION, new String[] {"OK"}, 0);
            // dialog.open();
        } else {
            MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(),
                    "Mark Information will be provided by this wizard.", null,
                    "Please select a valid information", MessageDialog.INFORMATION, new String[] { "OK" }, 0);
            dialog.open();
        }
    }
}

From source file:eu.modelwriter.marker.command.MarkAllHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (AlloyUtilities.isExists()) {
        this.createMarkers();
        this.refresh();
    } else {/*from  w ww .  j a  v a2 s.  com*/
        MessageDialog infoDialog = new MessageDialog(MarkerActivator.getShell(), "System Information", null,
                "You dont have any registered alloy file to system.", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        infoDialog.open();
    }
    return null;
}

From source file:eu.modelwriter.marker.command.MarkAllInWorkspaceHandler.java

License:Open Source License

private void createMarkersWs() {
    ITextSelection textSelection = (ITextSelection) this.selection;
    if (MarkerFactory.findMarkerWithAbsolutePosition(this.file, textSelection.getOffset(),
            textSelection.getOffset() + textSelection.getLength()) != null) {
        MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                "In these area, there is already a marker", MessageDialog.WARNING, new String[] { "OK" }, 0);
        dialog.open();/*from   w w  w. j  a  va 2 s  . c om*/
        return;
    } else {
        MarkAllInWsWizard markAllWsWizard = new MarkAllInWsWizard(textSelection, this.file);
        WizardDialog selectionDialog = new WizardDialog(MarkerActivator.getShell(), markAllWsWizard);
        selectionDialog.open();
    }
}

From source file:eu.modelwriter.marker.command.MarkAllInWorkspaceHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    if (AlloyUtilities.isExists()) {
        this.file = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
                .getEditorInput().getAdapter(IFile.class);
        this.selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
                .getSelection();//from   ww  w  .j  a  v  a 2  s.co m

        this.createMarkersWs();
        this.refresh();
    } else {
        MessageDialog infoDialog = new MessageDialog(MarkerActivator.getShell(), "System Information", null,
                "You dont have any registered alloy file to system.", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        infoDialog.open();
    }
    return null;
}

From source file:eu.modelwriter.marker.command.MarkHandler.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    if (AlloyUtilities.isExists()) {
        createMarker();/*from   ww w. j a  v  a 2  s  .c o m*/
        refresh();
    } else {
        final MessageDialog infoDialog = new MessageDialog(MarkerActivator.getShell(), "System Information",
                null, "You dont have any registered alloy file to system.", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        infoDialog.open();
    }
    return null;
}

From source file:eu.modelwriter.marker.command.MarkWithTypeHandler.java

License:Open Source License

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    if (AlloyUtilities.isExists()) {
        return markWithType();
    } else {/*  w ww  .ja  v a2s. co  m*/
        final MessageDialog infoDialog = new MessageDialog(MarkerActivator.getShell(), "System Information",
                null, "You dont have any registered alloy file to system.", MessageDialog.INFORMATION,
                new String[] { "OK" }, 0);
        infoDialog.open();
    }
    return null;
}

From source file:eu.modelwriter.marker.command.MarkWithTypeHandler.java

License:Open Source License

private Object markWithType() {
    file = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
            .getEditorInput().getAdapter(IFile.class);
    selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
    editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();

    if (!MarkerPage.isParsed()) {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Type Information", null,
                "You dont have any marker type registered to system! \n" + "Please parse an alloy file first",
                MessageDialog.INFORMATION, new String[] { "OK" }, 0);
        dialog.open();//from   w ww  . ja v  a2 s.co  m
        return null;
    }

    final IMarker selectedMarker = getMarker();
    if (selectedMarker != null) {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                "In these area, there is already a marker", MessageDialog.WARNING, new String[] { "OK" }, 0);
        dialog.open();
        return null;
    } else if (selection instanceof ITextSelection && ((ITextSelection) selection).getLength() == 0) {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                "Please make a valid selection", MessageDialog.WARNING, new String[] { "OK" }, 0);
        dialog.open();
        return null;
    }

    final MarkerWizard markerWizard = new MarkerWizard(selection, file);
    final WizardDialog dialog = new WizardDialog(MarkerActivator.getShell(), markerWizard);
    dialog.open();

    Visualization.showViz();
    return null;
}

From source file:eu.modelwriter.marker.internal.MarkerFactory.java

License:Open Source License

/**
 * Creates a Marker from TextSelection//from  w w  w . j a va  2 s . c  o m
 */
public static IMarker createMarker(final IResource resource, final ITextSelection selection) {
    try {
        IMarker createdMarker = null;

        if (selection != null && !selection.getText().isEmpty()) {

            if (MarkerFactory.findMarkerWithAbsolutePosition(resource, selection.getOffset(),
                    selection.getOffset() + selection.getLength()) != null) {

                final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information",
                        null, "In these area, there is already a marker", MessageDialog.WARNING,
                        new String[] { "OK" }, 0);
                dialog.open();

                return null;
            }

            final int start = selection.getOffset();
            final int end = selection.getOffset() + selection.getLength();

            final HashMap<String, Object> map = new HashMap<>();

            MarkerUtilities.setLineNumber(map, selection.getStartLine());
            MarkerUtilities.setMessage(map, "Marker Type : non-type");
            MarkerUtilities.setCharStart(map, start);
            MarkerUtilities.setCharEnd(map, end);
            map.put(IMarker.TEXT, selection.getText());
            map.put(IMarker.LOCATION, selection.getStartLine());
            map.put(IMarker.SOURCE_ID, MarkerFactory.generateId());
            map.put(MarkUtilities.MARKER_TYPE, null);
            MarkerUtilities.createMarker(resource, map, MarkerFactory.MARKER_MARKING);

            createdMarker = MarkerFactory.findMarkerWithAbsolutePosition(resource, start, end);

        } else {
            final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                    "Please perform a valid selection", MessageDialog.WARNING, new String[] { "OK" }, 0);
            dialog.open();
        }
        return createdMarker;
    } catch (final CoreException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:eu.modelwriter.marker.internal.MarkerFactory.java

License:Open Source License

/**
 * Creates a Marker from TreeSelection//w  w  w.j  a v  a  2  s.c om
 */
@SuppressWarnings({ "resource" })
public static IMarker createMarker(final IResource res, final ITreeSelection selection) {
    if (selection == null) {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                "Please perform a valid selection", MessageDialog.WARNING, new String[] { "OK" }, 0);
        dialog.open();
        return null;
    } else if (MarkerFactory.findMarkerByTreeSelection(selection, res) != null) {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                "In these area, there is already a marker", MessageDialog.WARNING, new String[] { "OK" }, 0);
        dialog.open();
        return null;
    }

    // Fetch IResource
    final IWorkbench workbench = PlatformUI.getWorkbench();
    final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    final IWorkbenchPage page = window.getActivePage();
    final IEditorPart editor = page.getActiveEditor();
    final IFileEditorInput input = (IFileEditorInput) editor.getEditorInput();
    final IFile file = input.getFile();

    IMarker marker = null;
    if (MarkerActivator.getEditor() instanceof EcoreEditor
            && selection.getFirstElement() instanceof ENamedElement
            && ((ENamedElement) selection.getFirstElement()).getName() != null
            && !((ENamedElement) selection.getFirstElement()).getName().isEmpty()) {

        marker = MarkerFactory.createEcoreMarker(selection, file, res, editor);

    } else if (editor instanceof EcoreEditor && selection.getFirstElement() != null) {
        marker = MarkerFactory.createInstanceMarker(selection, file, res, editor);
    } else if (editor instanceof CompilationUnitEditor) {
        final Object element = selection.getFirstElement();

        String content = null;
        try {
            content = new Scanner(file.getContents()).useDelimiter("\\Z").next();
        } catch (final CoreException e1) {
            e1.printStackTrace();
        }
        int startOffset = 0;
        int length = 0;

        if (element instanceof IField) {
            final IField field = (IField) element;
            try {
                final ISourceRange nameRange = field.getNameRange();
                final int nameStartOffset = nameRange.getOffset();
                final int nameEndOffset = nameStartOffset + nameRange.getLength();

                final ISourceRange sourceRange = field.getSourceRange();
                startOffset = field.getJavadocRange().getOffset() + field.getJavadocRange().getLength() + 1;
                if (nameEndOffset + 1 == sourceRange.getOffset() + sourceRange.getLength()) {
                    length = sourceRange.getOffset() + sourceRange.getLength() - startOffset;
                } else {
                    final int indexOfAssignment = content.indexOf("=", nameEndOffset);
                    length = indexOfAssignment - startOffset;
                }

            } catch (final JavaModelException e) {
                e.printStackTrace();
            }
        } else if (element instanceof IInitializer) {
            final IInitializer initializer = (IInitializer) element;
            try {
                final ISourceRange sourceRange = initializer.getSourceRange();
                startOffset = initializer.getJavadocRange().getOffset()
                        + initializer.getJavadocRange().getLength() + 1;
                length = sourceRange.getLength();
            } catch (final JavaModelException e) {
                e.printStackTrace();
            }
        } else if (element instanceof IMethod) {
            final IMethod method = (IMethod) element;
            try {
                final ISourceRange nameRange = method.getNameRange();
                final int nameStartOffset = nameRange.getOffset();
                final int nameEndOffset = nameStartOffset + nameRange.getLength();

                final ISourceRange sourceRange = method.getSourceRange();
                startOffset = method.getJavadocRange().getOffset() + method.getJavadocRange().getLength() + 1;
                if (content.toCharArray()[sourceRange.getOffset() + sourceRange.getLength() - 1] == '}') {
                    final int indexOfParanthesis = content.indexOf("{", nameEndOffset);
                    length = indexOfParanthesis - startOffset;
                } else if (content.toCharArray()[sourceRange.getOffset() + sourceRange.getLength()
                        - 1] == ';') {
                    length = sourceRange.getLength();
                }

            } catch (final JavaModelException e) {
                e.printStackTrace();
            }
        } else if (element instanceof IType) {
            final IType type = (IType) element;
            try {
                final ISourceRange nameRange = type.getNameRange();
                final int nameStartOffset = nameRange.getOffset();
                final int nameEndOffset = nameStartOffset + nameRange.getLength();

                final int indexOfParanthesis = content.indexOf("{", nameEndOffset);

                startOffset = type.getJavadocRange().getOffset() + type.getJavadocRange().getLength() + 1;
                length = indexOfParanthesis - startOffset;
            } catch (final JavaModelException e) {
                e.printStackTrace();
            }
        }

        final IDocument document = new Document(content);
        final TextSelection textSelection = new TextSelection(document, startOffset, length);
        return MarkerFactory.createMarker(file, textSelection);

    } else {
        final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark Information", null,
                "Please perform a valid selection", MessageDialog.WARNING, new String[] { "OK" }, 0);
        dialog.open();
    }
    return marker;
}