001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal.ide.undo;
011:
012: import java.util.Map;
013:
014: import org.eclipse.core.resources.IMarker;
015: import org.eclipse.core.resources.IResource;
016: import org.eclipse.core.runtime.CoreException;
017:
018: /**
019: * MarkerDescription is a lightweight description of a marker that can be used
020: * to describe a marker to be created or updated.
021: *
022: * This class is not intended to be instantiated or used by clients.
023: *
024: * @since 3.3
025: *
026: */
027: public class MarkerDescription {
028: String type;
029:
030: Map attributes;
031:
032: IResource resource;
033:
034: /**
035: *
036: * Create a marker description from the specified marker.
037: *
038: * @param marker
039: * the marker to be described
040: * @throws CoreException
041: */
042: public MarkerDescription(IMarker marker) throws CoreException {
043: this .type = marker.getType();
044: this .attributes = marker.getAttributes();
045: this .resource = marker.getResource();
046:
047: }
048:
049: /**
050: * Create a marker description from the specified marker type, attributes,
051: * and resource.
052: *
053: * @param type
054: * the type of marker to be created.
055: * @param attributes
056: * the attributes to be assigned to the marker
057: * @param resource
058: * the resource on which the marker should be created
059: */
060: public MarkerDescription(String type, Map attributes,
061: IResource resource) {
062: this .type = type;
063: this .attributes = attributes;
064: this .resource = resource;
065: }
066:
067: /**
068: * Create a marker from the marker description.
069: *
070: * @return the created marker
071: * @throws CoreException
072: */
073: public IMarker createMarker() throws CoreException {
074: IMarker marker = resource.createMarker(type);
075: marker.setAttributes(attributes);
076: return marker;
077: }
078:
079: /**
080: * Update an existing marker using the attributes in the marker description.
081: *
082: * @param marker
083: * the marker to be updated
084: * @throws CoreException
085: */
086: public void updateMarker(IMarker marker) throws CoreException {
087: marker.setAttributes(attributes);
088: }
089:
090: /**
091: * Return the resource associated with this marker.
092: *
093: * @return the resource associated with this marker
094: */
095: public IResource getResource() {
096: return resource;
097: }
098:
099: /**
100: * Return the marker type associated with this marker.
101: *
102: * @return the string marker type of this marker
103: */
104: public String getType() {
105: return type;
106: }
107: }
|