001: /*******************************************************************************
002: * Copyright (c) 2007 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.jface.viewers;
011:
012: import java.util.EventObject;
013:
014: import org.eclipse.swt.events.KeyEvent;
015: import org.eclipse.swt.events.MouseEvent;
016: import org.eclipse.swt.events.TraverseEvent;
017:
018: /**
019: * This event is passed on when a cell-editor is going to be activated
020: *
021: * @since 3.3
022: *
023: */
024: public class ColumnViewerEditorActivationEvent extends EventObject {
025: /**
026: *
027: */
028: private static final long serialVersionUID = 1L;
029:
030: /**
031: * if a key is pressed on a selected cell
032: */
033: public static final int KEY_PRESSED = 1;
034:
035: /**
036: * if a cell is selected using a single click of the mouse
037: */
038: public static final int MOUSE_CLICK_SELECTION = 2;
039:
040: /**
041: * if a cell is selected using double clicking of the mouse
042: */
043: public static final int MOUSE_DOUBLE_CLICK_SELECTION = 3;
044:
045: /**
046: * if a cell is activated using code like e.g
047: * {@link ColumnViewer#editElement(Object, int)}
048: */
049: public static final int PROGRAMMATIC = 4;
050:
051: /**
052: * is a cell is activated by traversing
053: */
054: public static final int TRAVERSAL = 5;
055:
056: /**
057: * the original event triggered
058: */
059: public EventObject sourceEvent;
060:
061: /**
062: * The time the event is triggered
063: */
064: public int time;
065:
066: /**
067: * The event type triggered:
068: * <ul>
069: * <li>{@link #KEY_PRESSED} if a key is pressed on a selected cell</li>
070: * <li>{@link #MOUSE_CLICK_SELECTION} if a cell is selected using a single
071: * click of the mouse</li>
072: * <li>{@link #MOUSE_DOUBLE_CLICK_SELECTION} if a cell is selected using
073: * double clicking of the mouse</li>
074: * </ul>
075: */
076: public int eventType;
077:
078: /**
079: * <b>Only set for {@link #KEY_PRESSED}</b>
080: */
081: public int keyCode;
082:
083: /**
084: * <b>Only set for {@link #KEY_PRESSED}</b>
085: */
086: public char character;
087:
088: /**
089: * The statemask
090: */
091: public int stateMask;
092:
093: /**
094: * Cancel the event (=> editor is not activated)
095: */
096: public boolean cancel = false;
097:
098: /**
099: * This constructor can be used when no event exists. The type set is
100: * {@link #PROGRAMMATIC}
101: *
102: * @param cell
103: * the cell
104: */
105: public ColumnViewerEditorActivationEvent(ViewerCell cell) {
106: super (cell);
107: eventType = PROGRAMMATIC;
108: }
109:
110: /**
111: * This constructor is used for all types of mouse events. Currently the
112: * type is can be {@link #MOUSE_CLICK_SELECTION} and
113: * {@link #MOUSE_DOUBLE_CLICK_SELECTION}
114: *
115: * @param cell
116: * the cell source of the event
117: * @param event
118: * the event
119: */
120: public ColumnViewerEditorActivationEvent(ViewerCell cell,
121: MouseEvent event) {
122: super (cell);
123:
124: if (event.count >= 2) {
125: eventType = MOUSE_DOUBLE_CLICK_SELECTION;
126: } else {
127: eventType = MOUSE_CLICK_SELECTION;
128: }
129:
130: this .sourceEvent = event;
131: this .time = event.time;
132: }
133:
134: /**
135: * @param cell
136: * the cell source of the event
137: * @param event
138: * the event
139: */
140: public ColumnViewerEditorActivationEvent(ViewerCell cell,
141: KeyEvent event) {
142: super (cell);
143: this .eventType = KEY_PRESSED;
144: this .sourceEvent = event;
145: this .time = 0;
146: this .keyCode = event.keyCode;
147: this .character = event.character;
148: this .stateMask = event.stateMask;
149: }
150:
151: /**
152: * This constructor is used to mark the activation triggered by a traversal
153: *
154: * @param cell
155: * the cell source of the event
156: * @param event
157: * the event
158: */
159: public ColumnViewerEditorActivationEvent(ViewerCell cell,
160: TraverseEvent event) {
161: super(cell);
162: this.eventType = TRAVERSAL;
163: this.sourceEvent = event;
164: }
165: }
|