Search in sources :

Example 1 with CreateMarkersOperation

use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project eclipse.platform.text by eclipse.

the class AddMarkerAction method run.

@Override
public void run() {
    IResource resource = getResource();
    if (resource == null)
        return;
    Map<String, Object> attributes = getInitialAttributes();
    if (fAskForLabel) {
        if (!askForLabel(attributes))
            return;
    }
    String name = getToolTipText();
    name = name == null ? TextEditorMessages.AddMarkerAction_addMarker : name;
    final Shell shell = getTextEditor().getSite().getShell();
    IAdaptable context = new IAdaptable() {

        @SuppressWarnings("unchecked")
        @Override
        public <T> T getAdapter(Class<T> adapter) {
            if (adapter == Shell.class)
                return (T) shell;
            return null;
        }
    };
    IUndoableOperation operation = new CreateMarkersOperation(fMarkerType, attributes, resource, name);
    IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
    try {
        operationHistory.execute(operation, null, context);
    } catch (ExecutionException x) {
        Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
        ILog log = Platform.getLog(bundle);
        // $NON-NLS-2$ //$NON-NLS-1$
        String msg = getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message");
        log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, x));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IAdaptable(org.eclipse.core.runtime.IAdaptable) ResourceBundle(java.util.ResourceBundle) Bundle(org.osgi.framework.Bundle) CreateMarkersOperation(org.eclipse.ui.ide.undo.CreateMarkersOperation) Shell(org.eclipse.swt.widgets.Shell) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ILog(org.eclipse.core.runtime.ILog) ExecutionException(org.eclipse.core.commands.ExecutionException) IResource(org.eclipse.core.resources.IResource)

Example 2 with CreateMarkersOperation

use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project eclipse.platform.text by eclipse.

the class MarkerRulerAction method addMarker.

/**
 * Creates a new marker according to the specification of this action and
 * adds it to the marker resource.
 */
protected void addMarker() {
    IResource resource = getResource();
    if (resource == null)
        return;
    Map<String, Object> attributes = getInitialAttributes();
    if (fAskForLabel) {
        if (!askForLabel(attributes))
            return;
    }
    execute(new CreateMarkersOperation(fMarkerType, attributes, resource, getOperationName()));
}
Also used : CreateMarkersOperation(org.eclipse.ui.ide.undo.CreateMarkersOperation) IResource(org.eclipse.core.resources.IResource)

Example 3 with CreateMarkersOperation

use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project xtext-eclipse by eclipse.

the class ProblemHoverTest method testBug357516_bookmark.

@Test
public void testBug357516_bookmark() throws Exception {
    IResource resource = editor.getResource();
    HashMap<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(IMarker.MESSAGE, CUSTOM_MARKER_TEST_MESSAGE);
    attributes.put(IMarker.LINE_NUMBER, 1);
    attributes.put(IMarker.LOCATION, resource.getFullPath().toPortableString());
    IUndoableOperation operation = new CreateMarkersOperation(IMarker.BOOKMARK, attributes, resource, CUSTOM_MARKER_TEST_MESSAGE);
    IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
    try {
        operationHistory.execute(operation, null, null);
    } catch (ExecutionException x) {
        fail(x.getMessage());
    }
    String hoverInfo = hover.getHoverInfo(editor.getInternalSourceViewer(), 0);
    assertNotNull(hoverInfo);
    assertTrue(hoverInfo.contains(CUSTOM_MARKER_TEST_MESSAGE));
}
Also used : HashMap(java.util.HashMap) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ExecutionException(org.eclipse.core.commands.ExecutionException) CreateMarkersOperation(org.eclipse.ui.ide.undo.CreateMarkersOperation) IResource(org.eclipse.core.resources.IResource) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Example 4 with CreateMarkersOperation

use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project tdq-studio-se by Talend.

the class TdDialogMarkerProperties method saveChanges.

/**
 * Saves the changes made in the dialog if needed. Creates a new marker if needed. Updates the existing marker only
 * if there have been changes.
 */
@SuppressWarnings("unchecked")
private void saveChanges() {
    Map attrs = getMarkerAttributes();
    IUndoableOperation op = null;
    if (marker == null) {
        if (resource == null)
            return;
        op = new CreateMarkersOperation(type, attrs, resource, getCreateOperationTitle());
    } else {
        if (isDirty()) {
            op = new UpdateMarkersOperation(marker, attrs, getModifyOperationTitle(), true);
        }
    }
    if (op != null) {
        try {
            PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, null, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
        } catch (ExecutionException e) {
            if (e.getCause() instanceof CoreException) {
                ErrorDialog.openError(getShell(), MarkerMessages.Error, null, ((CoreException) e.getCause()).getStatus());
            } else {
                IDEWorkbenchPlugin.log(e.getMessage(), e);
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) UpdateMarkersOperation(org.eclipse.ui.ide.undo.UpdateMarkersOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) CreateMarkersOperation(org.eclipse.ui.ide.undo.CreateMarkersOperation)

Aggregations

CreateMarkersOperation (org.eclipse.ui.ide.undo.CreateMarkersOperation)4 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IUndoableOperation (org.eclipse.core.commands.operations.IUndoableOperation)3 IResource (org.eclipse.core.resources.IResource)3 HashMap (java.util.HashMap)2 IOperationHistory (org.eclipse.core.commands.operations.IOperationHistory)2 Map (java.util.Map)1 ResourceBundle (java.util.ResourceBundle)1 CoreException (org.eclipse.core.runtime.CoreException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 ILog (org.eclipse.core.runtime.ILog)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Shell (org.eclipse.swt.widgets.Shell)1 UpdateMarkersOperation (org.eclipse.ui.ide.undo.UpdateMarkersOperation)1 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1