semorg.gui.util
Class ForeignKeyConstraintSelector

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.ForeignKeyConstraintSelector
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable

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

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


Field Summary
private  boolean controlEnabled
          true if the control is enabled, false otherwise.
private  org.eclipse.swt.widgets.ToolItem deleteItem
          Button to delete the associated object.
private  org.eclipse.swt.widgets.ToolItem disconnectItem
          Button to disconnect the current item and the yet associated item.
static int FK_CLIENT
          Instances from this type allow to manage the association to a Client object.
static int FK_COMPANY
          Instances from this type allow to manage the association to a Company object.
static int FK_COMPANYINTERNALPRESENTATION
          Instances from this type allow to manage the association to a CompanyInternalPresentation object.
static int FK_PUBLICPRESENTATION
          Instances from this type allow to manage the association to a PublicPresentation object.
static int FK_SEMINARTYPE
          Instances from this type allow to manage the association to a SeminarType object.
private  org.eclipse.swt.widgets.ToolItem newItem
          Button to create a new item which gets associated to the current item.
private  int selectedId
          The id of the associated object.
private  org.eclipse.swt.widgets.Text selectedValueText
          A text field to display some information about the associated object.
private  org.eclipse.swt.widgets.ToolItem showListItem
          Button to show the available objects for associating.
private  org.eclipse.swt.widgets.ToolBar toolBar
          SWT ToolBar widget which contains some Buttons to manage the association to a object.
private  int type
          The current type of this control.
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
ForeignKeyConstraintSelector(org.eclipse.swt.widgets.Composite parent, int type)
          Creates an instance of this class using the given parameters.
 
Method Summary
 void addModifyListener(org.eclipse.swt.events.ModifyListener listener)
          Adds a ModifyListener to the text field selectedValueText.
private  boolean deleteFromDB()
          Deletes the record corresponding to selectedId (the associated object) from the database.
private  String determineDeleteMessage()
          This method determines the right deletion dialog hint text against the type of the foreign key of the data record managed by this control.
 int getSelectedId()
           
private  boolean isLockedId(int id)
          Checks whether the given id is locked,i.e. the object to the id is edited elsewhere, or not.
private  void onDelete()
          This method implements the functionality of the deletion button, i.e. it deletes the selected element if it isn't locked.
 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 or disables the disconnectItem, deleteItem and showListItem.
 void setSelectedId(int selectedId)
          Sets the selectedId to the given id and enables the items disconnectItem and deleteItem if necessary.
private  void updateText()
          Updates the text shown in the selectedValueText widget.
 
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, update
 
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

FK_COMPANY

public static final int FK_COMPANY
Instances from this type allow to manage the association to a Company object.

See Also:
Constant Field Values

FK_CLIENT

public static final int FK_CLIENT
Instances from this type allow to manage the association to a Client object.

See Also:
Constant Field Values

FK_SEMINARTYPE

public static final int FK_SEMINARTYPE
Instances from this type allow to manage the association to a SeminarType object.

See Also:
Constant Field Values

FK_COMPANYINTERNALPRESENTATION

public static final int FK_COMPANYINTERNALPRESENTATION
Instances from this type allow to manage the association to a CompanyInternalPresentation object.

See Also:
Constant Field Values

FK_PUBLICPRESENTATION

public static final int FK_PUBLICPRESENTATION
Instances from this type allow to manage the association to a PublicPresentation object.

See Also:
Constant Field Values

selectedValueText

private final org.eclipse.swt.widgets.Text selectedValueText
A text field to display some information about the associated object.


toolBar

private final org.eclipse.swt.widgets.ToolBar toolBar
SWT ToolBar widget which contains some Buttons to manage the association to a object.


showListItem

private final org.eclipse.swt.widgets.ToolItem showListItem
Button to show the available objects for associating.


disconnectItem

private final org.eclipse.swt.widgets.ToolItem disconnectItem
Button to disconnect the current item and the yet associated item.


newItem

private final org.eclipse.swt.widgets.ToolItem newItem
Button to create a new item which gets associated to the current item.


deleteItem

private final org.eclipse.swt.widgets.ToolItem deleteItem
Button to delete the associated object.


type

private final int type
The current type of this control.


selectedId

private int selectedId
The id of the associated object.


controlEnabled

private boolean controlEnabled
true if the control is enabled, false otherwise.

Constructor Detail

ForeignKeyConstraintSelector

public ForeignKeyConstraintSelector(org.eclipse.swt.widgets.Composite parent,
                                    int type)
Creates an instance of this class using the given parameters.

Method Detail

updateText

private void updateText()
Updates the text shown in the selectedValueText widget.


setSelectedId

public void setSelectedId(int selectedId)
Sets the selectedId to the given id and enables the items disconnectItem and deleteItem if necessary.

Parameters:
selectedId - the id of the new associated object.

addModifyListener

public void addModifyListener(org.eclipse.swt.events.ModifyListener listener)
Adds a ModifyListener to the text field selectedValueText.

Parameters:
listener - the listener to add.

setEnabled

public void setEnabled(boolean enabled)
Enables or disables the disconnectItem, deleteItem and showListItem.

The member controlEnabled is also set to the given value. If the items got enabled depends also on the fact, whether there is a object associated or not.

Overrides:
setEnabled in class org.eclipse.swt.widgets.Control
Parameters:
enabled - if true the widgets get enabled, if false disabled.

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

isLockedId

private boolean isLockedId(int id)
Checks whether the given id is locked,i.e. the object to the id is edited elsewhere, or not.

Parameters:
id - the id to check.
Returns:
true if the id is locked, otherwise false.

onDelete

private void onDelete()
This method implements the functionality of the deletion button, i.e. it deletes the selected element if it isn't locked.


determineDeleteMessage

private String determineDeleteMessage()
This method determines the right deletion dialog hint text against the type of the foreign key of the data record managed by this control.

Returns:
String containing the right deletion dialog hint text.

deleteFromDB

private boolean deleteFromDB()
                      throws SQLException
Deletes the record corresponding to selectedId (the associated object) from the database.

Returns:
true if the deletion was successful, false otherwise.
Throws:
SQLException

getSelectedId

public int getSelectedId()