/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
** GNU General Public License version 2.0 (GPL)
**
** as published by the Free Software Foundation
** http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
** LICENSE.GPL included in the packaging of this file.
**
** or the
**
** Agreement for Purchase and Licensing
**
** as offered by Software- und Organisations-Service GmbH
** in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
********************************************************** end of preamble*/
package net.cwroethel.swt.popupcalendar;
import java.util.Vector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
/*******************************************************************************
* Copyright (c) 2005 Will Roethel. All rights reserved. This program and the
* accompanying materials are made available under the terms of the Eclipse
* Public License v1.0 which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html Contributors: Will Roethel -
* initial API and implementation
******************************************************************************/
/**
* DateChooserPanel is an abstract class used as container for the three
* DateChooser component classes. If the components are used by DateChooser,
* they are registered with an SelectionListener and, depending on the
* SelectionEvent detail (event.detail), the corresponding actions are taken.
*
* <pre>
* daySelector = new DaySelector(shell);
* daySelector.addSelectionListener(new SelectionAdapter() {
* public void widgetSelected(SelectionEvent e) {
* ... do something...
* }
* });
* </pre>
*
* @author Will Roethel, http://www.cwroethel.net
* @version $Revision: 1.2 $
*/
public abstract class DateChooserPanel extends Composite {
protected Vector selectionListeners = new Vector();
/**
* Default constructor.
*
* @param parent
* @param style
*/
public DateChooserPanel(Composite parent, int style) {
super(parent, style);
}
/**
* Add a SelectionListener.
*
* @param listener
*/
public void addSelectionListener(SelectionListener listener) {
if (listener == null)
error(SWT.ERROR_NULL_ARGUMENT);
selectionListeners.addElement(listener);
}
/**
* Copy of the generic error method defined in
* org.eclipse.swt.widgets.Widget.
*/
protected void error(int code) {
SWT.error(code);
}
/**
* Remove a SelectionListener.
*
* @param listener
*/
public void removeSelectionListener(SelectionListener listener) {
selectionListeners.removeElement(listener);
}
/**
* Notify all listeners of a selection.
*
* @param selectionEvent
*/
protected void sendSelectionEvent(SelectionEvent selectionEvent) {
if (selectionListeners == null) {
return;
}
if (selectionEvent == null) {
Event event = new Event();
event.type = SWT.Selection;
Display display = Display.getCurrent();
event.display = display;
event.widget = this;
selectionEvent = new SelectionEvent(event);
}
for (int i = 0; i < selectionListeners.size(); i++) {
SelectionListener listener = (SelectionListener) selectionListeners.elementAt(i);
if (listener != null)
listener.widgetSelected(selectionEvent);
}
}
}