001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.ui.controls.editcontrol;
043:
044: import org.netbeans.modules.uml.core.eventframework.EventDispatcher;
045: import org.netbeans.modules.uml.core.eventframework.EventFunctor;
046: import org.netbeans.modules.uml.core.eventframework.EventManager;
047: import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
048:
049: /**
050: * @author sumitabhk
051: *
052: */
053: public class EditControlEventDispatcher extends EventDispatcher
054: implements IEditControlEventDispatcher {
055: EventManager<IEditControlEventSink> m_EventManager = null;
056:
057: /**
058: *
059: */
060: public EditControlEventDispatcher() {
061: super ();
062: m_EventManager = new EventManager<IEditControlEventSink>();
063: }
064:
065: /*
066: * Registers a listener for the edit control events.
067: */
068: public void registerEditCtrlEvents(IEditControlEventSink handler) {
069: m_EventManager.addListener(handler, null);
070: }
071:
072: /*
073: * Removes the listener for edit control events.
074: */
075: public void revokeEditCtrlSink(IEditControlEventSink handler) {
076: m_EventManager.removeListener(handler);
077: }
078:
079: /**
080: *
081: * Create a new EditEventPayload for an edit control event
082: *
083: * @param rtCell[out] The new IEditEventPayload.
084: *
085: * @return HRESULT
086: *
087: */
088: public IEditEventPayload createEventPayload() {
089: IEditEventPayload payload = new EditEventPayload();
090: return payload;
091: }
092:
093: /*
094: * nothing to do right now
095: */
096: public boolean firePreInvalidData(String ErrorData,
097: IEditEventPayload payload) {
098: return true;
099: }
100:
101: /*
102: * nothing to do right now
103: */
104: public void fireInvalidData(String ErrorData,
105: IEditEventPayload payload) {
106:
107: }
108:
109: /*
110: * nothing to do right now
111: */
112: public boolean firePreOverstrike(boolean bOverstrike,
113: IEditEventPayload payload) {
114: return true;
115: }
116:
117: /*
118: * nothing to do right now
119: */
120: public void fireOverstrike(boolean bOverstrike,
121: IEditEventPayload payload) {
122:
123: }
124:
125: /*
126: * Fired before the edit control gets activated.
127: */
128: public boolean firePreActivate(IEditControl pControl,
129: IEditEventPayload payload) {
130: boolean proceed = true;
131: if (validateEvent("PreActivate", pControl)) {
132: IResultCell cell = prepareResultCell(payload);
133: EventFunctor preActiveFunc = new EventFunctor(
134: "org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlEventSink",
135: "onPreActivate");
136:
137: Object[] parms = new Object[2];
138: parms[0] = pControl;
139: parms[1] = cell;
140: preActiveFunc.setParameters(parms);
141: m_EventManager
142: .notifyListenersWithQualifiedProceed(preActiveFunc);
143: proceed = cell.canContinue();
144: }
145:
146: return proceed;
147: }
148:
149: /*
150: * Fired after the edit control gets activated.
151: */
152: public void fireActivate(IEditControl pControl,
153: IEditEventPayload payload) {
154: if (validateEvent("Activate", pControl)) {
155: IResultCell cell = prepareResultCell(payload);
156: EventFunctor activeFunc = new EventFunctor(
157: "org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlEventSink",
158: "onActivate");
159:
160: Object[] parms = new Object[2];
161: parms[0] = pControl;
162: parms[1] = cell;
163: activeFunc.setParameters(parms);
164: m_EventManager.notifyListeners(activeFunc);
165: }
166: }
167:
168: /*
169: * Fired after the edit control gets de-activated.
170: */
171: public void fireDeactivate(IEditControl pControl,
172: IEditEventPayload payload) {
173: if (validateEvent("Deactivate", pControl)) {
174: IResultCell cell = prepareResultCell(payload);
175: EventFunctor deactiveFunc = new EventFunctor(
176: "org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlEventSink",
177: "onDeactivate");
178:
179: Object[] parms = new Object[2];
180: parms[0] = pControl;
181: parms[1] = cell;
182: deactiveFunc.setParameters(parms);
183: m_EventManager.notifyListeners(deactiveFunc);
184: }
185: }
186:
187: /*
188: * Fired before the edit control gets committed.
189: */
190: public boolean firePreCommit(IEditEventPayload payload) {
191: boolean proceed = true;
192: if (validateEvent("PreCommit", null)) {
193: IResultCell cell = prepareResultCell(payload);
194: EventFunctor preComitFunc = new EventFunctor(
195: "org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlEventSink",
196: "onPreCommit");
197:
198: Object[] parms = new Object[1];
199: parms[0] = cell;
200: preComitFunc.setParameters(parms);
201: m_EventManager
202: .notifyListenersWithQualifiedProceed(preComitFunc);
203: proceed = cell.canContinue();
204: }
205:
206: return proceed;
207: }
208:
209: /*
210: * Fired after the edit control gets commited.
211: */
212: public void firePostCommit(IEditEventPayload payload) {
213: if (validateEvent("PostCommit", null)) {
214: IResultCell cell = prepareResultCell(payload);
215: EventFunctor postComitFunc = new EventFunctor(
216: "org.netbeans.modules.uml.ui.controls.editcontrol.IEditControlEventSink",
217: "onPostCommit");
218:
219: Object[] parms = new Object[1];
220: parms[0] = cell;
221: postComitFunc.setParameters(parms);
222: m_EventManager
223: .notifyListenersWithQualifiedProceed(postComitFunc);
224: }
225: }
226:
227: public int getNumRegisteredSinks() {
228: return m_EventManager.getNumListeners();
229: }
230:
231: }
|