* @see de.willuhn.jameica.gui.dialogs.AbstractDialog#paint(org.eclipse.swt.widgets.Composite)
*/
protected void paint(Composite parent) throws Exception
{
// Erzeugen der Liste mit den existierenden Elementen
turnusList = new TablePart(Settings.getDBService().createList(Turnus.class), new Action()
{
public void handleAction(Object context) throws ApplicationException
{
try
{
// Bei Doppelklick aktuellen Turnus zuweisen
turnus = (Turnus) context;
}
catch (Exception e)
{
Logger.error("error while choosing turnus",e);
}
// und Dialog schliessen. getData() liefert dann den gerade ausgewaehlten zurueck.
close();
}
});
turnusList.addColumn(i18n.tr("Bezeichnung"),"bezeichnung");
turnusList.setMulti(false);
turnusList.setSummary(false);
// Ein Formatter, der die initialen Turnusse rot markiert
turnusList.setFormatter(new TableFormatter()
{
public void format(TableItem item)
{
try {
Turnus t = (Turnus) item.getData();
if (t.isInitial())
{
item.setForeground(Settings.getBuchungSollForeground());
}
}
catch (Exception e)
{
Logger.error("error while formatting turnus",e);
}
}
});
ContextMenu c = new ContextMenu();
// Einer fuer die Neuanlage
c.addItem(new ContextMenuItem(i18n.tr("Neu..."), new Action()
{
public void handleAction(Object context) throws ApplicationException
{
handleEdit(null);
}
}));
// Ein Contextmenu-Eintrag zum Bearbeiten
c.addItem(new ContextMenuItem(i18n.tr("Bearbeiten..."), new Action()
{
public void handleAction(Object context) throws ApplicationException
{
if (context == null || !(context instanceof Turnus))
return;
handleEdit((Turnus) context);
}
})
{
/**
* @see de.willuhn.jameica.gui.parts.ContextMenuItem#isEnabledFor(java.lang.Object)
*/
public boolean isEnabledFor(Object o)
{
try
{
if (o == null || !(o instanceof Turnus))
return false;
Turnus t = (Turnus) o;
if (t.isInitial())
return false;
}
catch (Exception e)
{
Logger.error("error while checking context menu item",e);
}
return super.isEnabledFor(o);
}
});
// Ein Contextmenu-Eintrag zum Loeschen
c.addItem(new ContextMenuItem(i18n.tr("L�schen..."), new Action()
{
public void handleAction(Object context) throws ApplicationException
{
if (context == null || !(context instanceof Turnus))
return;
try
{
Turnus t = (Turnus) context;
t.delete();
}
catch (Exception e)
{
Logger.error("error while deleting turnus",e);
}
}
})
{
/**
* @see de.willuhn.jameica.gui.parts.ContextMenuItem#isEnabledFor(java.lang.Object)
*/
public boolean isEnabledFor(Object o)
{
try
{
if (o == null || !(o instanceof Turnus))
return false;
Turnus t = (Turnus) o;
if (t.isInitial())
return false;
}
catch (Exception e)
{
Logger.error("error while checking context menu item",e);
}
return super.isEnabledFor(o);
}
});
turnusList.setContextMenu(c);
Container container = new SimpleContainer(parent);
container.addPart(turnusList);
// und noch die Abschicken-Knoepfe
ButtonArea buttonArea = new ButtonArea();
buttonArea.addButton(i18n.tr("Neu"), new Action()
{
public void handleAction(Object context) throws ApplicationException
{
handleEdit(null);
}
},null,false,"document-new.png");
buttonArea.addButton(i18n.tr("�bernehmen"), new Action()
{
public void handleAction(Object context) throws ApplicationException
{
try
{
// aktuell markierten Turnus nehmen
turnus = (Turnus) turnusList.getSelection();
}
catch (Exception e)
{
Logger.error("error while choosing turnus",e);
}
// und Dialog schliessen
close();
}
},null,true,"ok.png");
buttonArea.addButton(i18n.tr("Abbrechen"), new Action()
{
public void handleAction(Object context) throws ApplicationException
{
// Turnus entfernen
turnus = null;