semorg.gui.util
Class AssociationTabControl

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by semorg.gui.util.AssociationTabControl
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

public class AssociationTabControl
extends org.eclipse.swt.widgets.Composite

This class provides a SWT composite which allows the user to manage several associations.


Field Summary
private  org.eclipse.swt.widgets.ToolItem chooseItem
          The item "choose" in the toolbar.
private  Vector<DBColumn> columns
          The columns of the GUI table.
private  org.eclipse.swt.widgets.ToolItem configureItem
          The item "configure" in the toolbar.
private  org.eclipse.swt.widgets.ToolItem deleteItem
          The item "delete" in the toolbar.
private  org.eclipse.swt.widgets.ToolItem disconnectItem
          The item "disconnect" in the toolbar.
private  org.eclipse.swt.widgets.ToolItem editItem
          The item "edit" in the toolbar.
private  boolean enabled
          Indicates whether the control is enabled or not.
private  DistinctVector<SimpleIDKey> idsToDelete
          Contains the ids of the items which should be deleted.
private  Set<ItemListener> itemListeners
          A set containing the listeners of the control.
private  org.eclipse.jface.viewers.TableViewer mainTableViewer
          Used to display the several DelayedPaymentItem objects as items of a GUI table.
private  org.eclipse.swt.widgets.ToolItem newItem
          The item "new" in the toolbar.
private  DistinctVector<SimpleIDKey> previouslySelectedIds
          Contains the ids of the previously selected items.
private  int referencedFK
          The id of the actual data record for which the associations get managed.
private  int style
          Indicates which type of association is managed by the instance of this class.
static int TYPE_CLIENTBOOKING_CLIENT
          Instances from this type allow to manage the association between the classes Client and ClientBooking in the ClientWindow.
static int TYPE_CLIENTBOOKING_PRESENTATION
          Instances from this type allow to manage the association between the classes ClientBooking and PublicPresentation in the PublicPresentationWindow.
static int TYPE_COMPANYBOOKING_COMPANY
          Instances from this type allow to manage the association between classes Company and CompanyBooking in the CompanyWindow.
static int TYPE_COMPANYBOOKING_PRESENTATION
          Instances from this type allow to manage association between the classes CompanyBooking and CompanyInternalPresentation in the CompanyInternalPresentationWindow.
static int TYPE_EMPLOYEE
          Instances from this type allow to manage the association between the classes Client and Company in the CompanyWindow.
static int TYPE_LECTURER_CONDUCT
          Instances from this type allow to manage the association Conduct in the SeminarTypeWindow.
static int TYPE_LECTURER_INSTRUCTOR
          Instances from this type allow to manage the association Instructor in the PublicPresentationWindow and CompanyInternalPresentationWindow.
static int TYPE_LECTURER_SUPERVISOR
          Instances from this type allow to manage the association Supervisor in the PublicPresentationWindow and CompanyInternalPresentationWindow.
static int TYPE_PRESENTATION_INSTRUCTOR
          Instances from this type allow to manage the association Instructor in the LecturerWindow.
static int TYPE_PRESENTATION_SEMTYPE
          Instances from this type allow to manage the association between classes Presentation and SeminarType in SeminarTypeWindow.
static int TYPE_PRESENTATION_SUPERVISOR
          Instances from this type allow to manage the association Supervisor in the LecturerWindow.
static int TYPE_SEMINARTYPE_CONDUCT
          Instances from this type allow to manage the association Conduct in the LecturerWindow.
private  DistinctVector<DBTableChangedListener> updateListeners
          These listeners react on changes in the database tables by updating the GUI table.
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
AssociationTabControl(org.eclipse.swt.widgets.Composite parent, int style, org.eclipse.swt.widgets.Shell parentShell)
          Creates an instance of this class by initializing the gui elements and adding some listeners to the elements.
 
Method Summary
 void addItemListener(ItemListener listener)
          Adds a listener to itemListeners.
 void addSelectedIds(SimpleIDKey[] selectedElements, boolean checkAlreadyAssigned)
          This method is called by the editing windows whose are created by this control to update the data of this GUI table.
private  void addUpdateListener()
          Adds listener to the updateListeners vector.
 void commitIntoDB(int generatedId)
          Commits all changes made to the item corresponding to the given id into the database using the methods listed beneath.
private  void configureClassSpecificViewerParts()
          Sets the columns of the GUI table corresponding to type of the association which actually managed by this control.
private  void connectInDB()
          Connects all items whose ids are contained in the previouslySelectedIds Vector, but not in the input of the mainTableViewer.
private  void deleteFromDB()
          Deletes all item whose ids are contained in the idsToDelete Vector.
private  String determineDeleteMessage(DistinctVector<SimpleIDKey> selectedElements)
          This method determines the right deletion dialog hint text against the type of the association managed by this control.
private  void disconnectInDB()
          Disconnects all items whose ids are contained in the previouslySelectedIds Vector, but not in the input of the mainTableViewer.
private  void fireItemChanged()
          Fires all listners in itemListeners.
 DistinctVector<SimpleIDKey> getObjects()
          Returns the items of the GUI table.
private  boolean hasLockedId(SimpleIDKey element)
          Checks if the id of the given element is locked.
protected  void onDelete()
          This method implements the functionality of the deletion button, i.e. it deletes the selected elements if they're not locked.
protected  void onDisconnect()
          This methode implements the functionality of the disconnect button, i.e.
protected  void openEditItemWindow()
          This methode implements the functionality of the edit button, i.e. it opens a window for editing the chosen data record.
protected  void openListWindow()
          Opens a ListWindow corresponding to the style of the current AssociationTabControl instance.
protected  void openNewItemWindow()
          This methode implements the functionality of the new button, i.e. it opens a window for editing the chosen data record.
 void removeItemListener(ItemListener listener)
          Removes a listener from itemListeners.
 void setData(String key, String value)
          Sets a pair of key and value to this control needed for testing with ATOSj.
 void setEnabled(boolean enabled)
          Enables / disables the chooseItem, the disconnectItem, the editItem and the deleteItem.
 void setInput(int referencedFK)
          Fills the GUI table with data records corresponding to type of managed association and the actual data record of the editing window this control is included in.
 void update()
          Updates the GUI table with the actual records from a database query.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, computeSize, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_EMPLOYEE

public static final int TYPE_EMPLOYEE
Instances from this type allow to manage the association between the classes Client and Company in the CompanyWindow.

See Also:
Constant Field Values

TYPE_CLIENTBOOKING_CLIENT

public static final int TYPE_CLIENTBOOKING_CLIENT
Instances from this type allow to manage the association between the classes Client and ClientBooking in the ClientWindow.

See Also:
Constant Field Values

TYPE_COMPANYBOOKING_COMPANY

public static final int TYPE_COMPANYBOOKING_COMPANY
Instances from this type allow to manage the association between classes Company and CompanyBooking in the CompanyWindow.

See Also:
Constant Field Values

TYPE_PRESENTATION_SUPERVISOR

public static final int TYPE_PRESENTATION_SUPERVISOR
Instances from this type allow to manage the association Supervisor in the LecturerWindow.

See Also:
Constant Field Values

TYPE_PRESENTATION_INSTRUCTOR

public static final int TYPE_PRESENTATION_INSTRUCTOR
Instances from this type allow to manage the association Instructor in the LecturerWindow.

See Also:
Constant Field Values

TYPE_SEMINARTYPE_CONDUCT

public static final int TYPE_SEMINARTYPE_CONDUCT
Instances from this type allow to manage the association Conduct in the LecturerWindow.

See Also:
Constant Field Values

TYPE_COMPANYBOOKING_PRESENTATION

public static final int TYPE_COMPANYBOOKING_PRESENTATION
Instances from this type allow to manage association between the classes CompanyBooking and CompanyInternalPresentation in the CompanyInternalPresentationWindow.

See Also:
Constant Field Values

TYPE_LECTURER_INSTRUCTOR

public static final int TYPE_LECTURER_INSTRUCTOR
Instances from this type allow to manage the association Instructor in the PublicPresentationWindow and CompanyInternalPresentationWindow.

See Also:
Constant Field Values

TYPE_LECTURER_SUPERVISOR

public static final int TYPE_LECTURER_SUPERVISOR
Instances from this type allow to manage the association Supervisor in the PublicPresentationWindow and CompanyInternalPresentationWindow.

See Also:
Constant Field Values

TYPE_PRESENTATION_SEMTYPE

public static final int TYPE_PRESENTATION_SEMTYPE
Instances from this type allow to manage the association between classes Presentation and SeminarType in SeminarTypeWindow.

See Also:
Constant Field Values

TYPE_LECTURER_CONDUCT

public static final int TYPE_LECTURER_CONDUCT
Instances from this type allow to manage the association Conduct in the SeminarTypeWindow.

See Also:
Constant Field Values

TYPE_CLIENTBOOKING_PRESENTATION

public static final int TYPE_CLIENTBOOKING_PRESENTATION
Instances from this type allow to manage the association between the classes ClientBooking and PublicPresentation in the PublicPresentationWindow.

See Also:
Constant Field Values

mainTableViewer

private org.eclipse.jface.viewers.TableViewer mainTableViewer
Used to display the several DelayedPaymentItem objects as items of a GUI table.


style

private int style
Indicates which type of association is managed by the instance of this class.


referencedFK

private int referencedFK
The id of the actual data record for which the associations get managed.


enabled

private boolean enabled
Indicates whether the control is enabled or not. true if the control is enabled, false otherwise.


columns

private Vector<DBColumn> columns
The columns of the GUI table.


itemListeners

private Set<ItemListener> itemListeners
A set containing the listeners of the control.


updateListeners

private DistinctVector<DBTableChangedListener> updateListeners
These listeners react on changes in the database tables by updating the GUI table.


disconnectItem

private org.eclipse.swt.widgets.ToolItem disconnectItem
The item "disconnect" in the toolbar.


deleteItem

private org.eclipse.swt.widgets.ToolItem deleteItem
The item "delete" in the toolbar.


configureItem

private org.eclipse.swt.widgets.ToolItem configureItem
The item "configure" in the toolbar.


chooseItem

private org.eclipse.swt.widgets.ToolItem chooseItem
The item "choose" in the toolbar.


editItem

private org.eclipse.swt.widgets.ToolItem editItem
The item "edit" in the toolbar.


newItem

private org.eclipse.swt.widgets.ToolItem newItem
The item "new" in the toolbar.


previouslySelectedIds

private DistinctVector<SimpleIDKey> previouslySelectedIds
Contains the ids of the previously selected items.

This vector is a clone of the mainTableViewer input. If the user disconnects an associated item from the current item, it disappears from the GUI table, but in the db it is still connected to the current object. Thus we've got to hold the ids of the formerly connected items such that we can disconnect them in the db when the user confirm his/her changes.


idsToDelete

private DistinctVector<SimpleIDKey> idsToDelete
Contains the ids of the items which should be deleted.

Constructor Detail

AssociationTabControl

public AssociationTabControl(org.eclipse.swt.widgets.Composite parent,
                             int style,
                             org.eclipse.swt.widgets.Shell parentShell)
Creates an instance of this class by initializing the gui elements and adding some listeners to the elements.

Parameters:
parent - the parent composite of this AssociationTabControl
style - the style of the AssociationTabControl (see style)
Method Detail

hasLockedId

private boolean hasLockedId(SimpleIDKey element)
Checks if the id of the given element is locked.

Parameters:
element - the element to be checked for a locked id
Returns:
true if the id is locked (i.e. element is edited anywhere else) and false otherwise.

onDelete

protected void onDelete()
This method implements the functionality of the deletion button, i.e. it deletes the selected elements if they're not locked.

It just adds the element ids to the idsToDelete vector and calls the function deleteFromDB().


determineDeleteMessage

private String determineDeleteMessage(DistinctVector<SimpleIDKey> selectedElements)
This method determines the right deletion dialog hint text against the type of the association managed by this control.

Returns:
String containing the right deletion dialog hint text.

openEditItemWindow

protected void openEditItemWindow()
This methode implements the functionality of the edit button, i.e. it opens a window for editing the chosen data record.


openNewItemWindow

protected void openNewItemWindow()
This methode implements the functionality of the new button, i.e. it opens a window for editing the chosen data record.


openListWindow

protected void openListWindow()
Opens a ListWindow corresponding to the style of the current AssociationTabControl instance.


onDisconnect

protected void onDisconnect()
This methode implements the functionality of the disconnect button, i.e. it deletes the connection between the actual data record (in the editing window) and the selected one in the GUI table of this control.


configureClassSpecificViewerParts

private void configureClassSpecificViewerParts()
Sets the columns of the GUI table corresponding to type of the association which actually managed by this control.


setInput

public void setInput(int referencedFK)
              throws SQLException
Fills the GUI table with data records corresponding to type of managed association and the actual data record of the editing window this control is included in.

Throws:
SQLException

getObjects

public DistinctVector<SimpleIDKey> getObjects()
Returns the items of the GUI table.

Returns:
a DistinctVector instance containing the the items of the GUI table.

setEnabled

public void setEnabled(boolean enabled)
Enables / disables the chooseItem, the disconnectItem, the editItem and the deleteItem.

Overrides:
setEnabled in class org.eclipse.swt.widgets.Control
Parameters:
enabled - if true the buttons above will be enabled, if false they disabled.

addSelectedIds

public void addSelectedIds(SimpleIDKey[] selectedElements,
                           boolean checkAlreadyAssigned)
This method is called by the editing windows whose are created by this control to update the data of this GUI table.

Parameters:
selectedElements - the elements selected or created the editing windows spawned by this control.
checkAlreadyAssigned - if true this method creates a message dialog which informs the user that the selected item is already assigned and will not be inserted again. Otherwise (false) the dialog will not appear.

commitIntoDB

public void commitIntoDB(int generatedId)
                  throws SQLException
Commits all changes made to the item corresponding to the given id into the database using the methods listed beneath.

Parameters:
generatedId - the id of item which was changed.
Throws:
SQLException - If the creation, manipulation, execution or closing of a PreparedStatement instance used for querying the database fails.
See Also:
deleteFromDB(), disconnectInDB(), connectInDB()

disconnectInDB

private void disconnectInDB()
                     throws SQLException
Disconnects all items whose ids are contained in the previouslySelectedIds Vector, but not in the input of the mainTableViewer.

Throws:
SQLException - If the creation, manipulation, execution or closing of a PreparedStatement instance used for querying the database fails.

connectInDB

private void connectInDB()
                  throws SQLException
Connects all items whose ids are contained in the previouslySelectedIds Vector, but not in the input of the mainTableViewer.

Throws:
SQLException - If the creation, manipulation, execution or closing of a PreparedStatement instance used for querying the database fails.

deleteFromDB

private void deleteFromDB()
                   throws SQLException
Deletes all item whose ids are contained in the idsToDelete Vector.

Throws:
SQLException - If the creation, manipulation, execution or closing of a PreparedStatement instance used for querying the database fails.

setData

public void setData(String key,
                    String value)
Sets a pair of key and value to this control needed for testing with ATOSj.

Parameters:
key - the key (type) of the value set
value - the value set to the control

addItemListener

public void addItemListener(ItemListener listener)
Adds a listener to itemListeners.


removeItemListener

public void removeItemListener(ItemListener listener)
Removes a listener from itemListeners.


fireItemChanged

private void fireItemChanged()
Fires all listners in itemListeners.


addUpdateListener

private void addUpdateListener()
Adds listener to the updateListeners vector. The type of the listener is determined by the type of the association managed by this control.


update

public void update()
Updates the GUI table with the actual records from a database query.

For example if the rows of the GUI table are sorted by a column or a record has been deleted.

Overrides:
update in class org.eclipse.swt.widgets.Control