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;
011:
012: import java.util.EventObject;
013:
014: /**
015: * Event object describing a change to a set of Saveable objects.
016: *
017: * @since 3.2
018: */
019: public class SaveablesLifecycleEvent extends EventObject {
020:
021: /**
022: * Serial version UID for this class.
023: * <p>
024: * Note: This class is not intended to be serialized.
025: * </p>
026: */
027: private static final long serialVersionUID = -3530773637989046452L;
028:
029: /**
030: * Event type constant specifying that the given saveables have been opened.
031: */
032: public static final int POST_OPEN = 1;
033:
034: /**
035: * Event type constant specifying that the given saveables are about to be
036: * closed. Listeners may veto the closing if isForce() is false.
037: */
038: public static final int PRE_CLOSE = 2;
039:
040: /**
041: * Event type constant specifying that the given saveables have been closed.
042: */
043: public static final int POST_CLOSE = 3;
044:
045: /**
046: * Event type constant specifying that the dirty state of the given saveables
047: * has changed.
048: */
049: public static final int DIRTY_CHANGED = 4;
050:
051: private int eventType;
052:
053: private Saveable[] saveables;
054:
055: private boolean force;
056:
057: private boolean veto = false;
058:
059: /**
060: * Creates a new SaveablesLifecycleEvent.
061: *
062: * @param source
063: * The source of the event. If an ISaveablesSource notifies
064: * about changes to the saveables returned by
065: * {@link ISaveablesSource#getSaveables()}, the source must be
066: * the ISaveablesSource object.
067: * @param eventType
068: * the event type, currently one of POST_OPEN, PRE_CLOSE,
069: * POST_CLOSE, DIRTY_CHANGED
070: * @param saveables
071: * The affected saveables
072: * @param force
073: * true if the event type is PRE_CLOSE and this is a closed force
074: * that cannot be canceled.
075: */
076: public SaveablesLifecycleEvent(Object source, int eventType,
077: Saveable[] saveables, boolean force) {
078: super (source);
079: this .eventType = eventType;
080: this .saveables = saveables;
081: this .force = force;
082: }
083:
084: /**
085: * Returns the eventType, currently one of POST_OPEN, PRE_CLOSE, POST_CLOSE,
086: * DIRTY_CHANGED. Listeners should silently ignore unknown event types since
087: * new event types might be added in the future.
088: *
089: * @return the eventType
090: */
091: public int getEventType() {
092: return eventType;
093: }
094:
095: /**
096: * Returns the affected saveables.
097: *
098: * @return the saveables
099: */
100: public Saveable[] getSaveables() {
101: return saveables;
102: }
103:
104: /**
105: * Returns the veto. This value is ignored for POST_OPEN,POST_CLOSE, and
106: * DIRTY_CHANGED.
107: *
108: * @return Returns the veto.
109: */
110: public boolean isVeto() {
111: return veto;
112: }
113:
114: /**
115: * @param veto
116: * The veto to set.
117: */
118: public void setVeto(boolean veto) {
119: this .veto = veto;
120: }
121:
122: /**
123: * Sets the force flag. This value is ignored for POST_OPEN, POST_CLOSE, and
124: * DIRTY_CHANGED.
125: *
126: * @return Returns the force.
127: */
128: public boolean isForce() {
129: return force;
130: }
131:
132: }
|