001: package de.webman.config.eventhandler;
002:
003: import java.util.*;
004: import java.sql.*;
005:
006: import com.teamkonzept.web.*;
007: import com.teamkonzept.lib.*;
008: import com.teamkonzept.db.*;
009: import com.teamkonzept.webman.*;
010: import com.teamkonzept.webman.mainint.*;
011: import com.teamkonzept.webman.mainint.db.queries.*;
012: import com.teamkonzept.webman.mainint.events.*;
013: import de.webman.config.eventhandler.COPropUpdateHandler;
014:
015: /**
016: creates a new property group or updates an existing group with the given name PROPGROUP_NEW_NAME.
017: after that, it displays a frameset with the list of property groups on the left
018: and an empty page to the right.
019:
020: if the given name is NULL, there are no changes and displays a frameset with the list of
021: property groups on the left and an error page to the right.
022: * @author $Author: doehling $
023: * @version $Revision: 1.10 $
024: */
025: public class COPropGroupUpdateHandler extends DefaultEventHandler
026: implements ParameterTypes, DatabaseDefaults, FrameConstants {
027: /** */
028: private COPropGroupUpdateHandler() {
029: }
030:
031: private static COPropGroupUpdateHandler instance = new COPropGroupUpdateHandler();
032:
033: public static COPropGroupUpdateHandler getInstance() {
034: return instance;
035: }
036:
037: public void handleEvent(TKEvent evt) throws TKException {
038: try {
039: WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(),
040: ContextConstants.CUSTOMIZE_PROPERTIES); // check if event is allowed
041: String propGroupId = evt.getParameter(PARAMETER,
042: "PROPGROUP_ID");
043: String propGroupName = evt.getParameter(PARAMETER,
044: "PROPGROUP_NAME");
045: String propGroupNewName = evt.getParameter(PARAMETER,
046: "PROPGROUP_NEW_NAME");
047: boolean newGroup = false;
048: boolean noDuplicateExists = true;
049: boolean nameGiven = true;
050: TKQuery q = TKDBManager.newQuery(TKDBPropGroupGetAll.class);
051:
052: // check, ob es sich um eine neuanzulegende gruppe handelt
053: propGroupId = (propGroupId != null ? propGroupId : "-1");
054: if (propGroupId.equals("-1")) {
055: newGroup = true;
056: }
057:
058: // check, ob ueberhaupt ein name eingegeben wurde
059: if (propGroupNewName == null || propGroupNewName.equals("")) {
060: nameGiven = false;
061: }
062:
063: // nein - ueberpruefung, ob eine gleichnamige gruppe bereits existiert
064: if (nameGiven) {
065: // find all groups - q schon oben definiert
066: q.execute();
067: ResultSet rs = q.fetchResultSet();
068:
069: // check, ob eine andere gleichnamige gruppe bereits existiert
070: while (rs != null && rs.next()) {
071: if (propGroupNewName.equals(rs
072: .getString("PROPGROUP_NAME"))
073: && !propGroupId.equals(rs
074: .getString("PROPGROUP_ID"))) {
075: noDuplicateExists = false;
076: break;
077: }
078: }
079: }
080:
081: // 2x nein - gruppe wird angelegt/geändert
082: if (noDuplicateExists && nameGiven) {
083: // neue gruppe wird angelegt
084: if (newGroup) {
085: q = TKDBManager.newQuery(TKDBPropGroupNew.class);
086: q
087: .setQueryParams("PROPGROUP_NAME",
088: propGroupNewName);
089: q.execute();
090: }
091:
092: // bestehende gruppe wird geändert
093: else {
094: q = TKDBManager.newQuery(TKDBPropGroupUpdate.class);
095: q.setQueryParams("PROPGROUP_ID", new Integer(
096: propGroupId));
097: q
098: .setQueryParams("PROPGROUP_NAME",
099: propGroupNewName);
100: q.execute();
101:
102: // Notify listeners registered with group name.
103: ConfigurationManager.getInstance().notifyListeners(
104: propGroupName);
105: }
106:
107: // Notify listeners registered with *new* group name.
108: ConfigurationManager.getInstance().notifyListeners(
109: propGroupNewName);
110: }
111:
112: // finish
113: TKHTMLTemplate t = evt
114: .getPrepHTMLTemplate("f_co_propgroup.tmpl");
115:
116: // alles ok
117: if (noDuplicateExists && nameGiven) {
118: HTMLUtils.fillFrameSet(t, LEFT_FRAME_WIDTH,
119: "CO_PROPGROUP_LIST", "EMPTY");
120: }
121: // ups, etwas war nicht in ordnung
122: else {
123: HTMLUtils.fillFrameSet(t, LEFT_FRAME_WIDTH,
124: "CO_PROPGROUP_LIST", "CO_ERROR");
125:
126: // EDIT=1 : bestehende gruppe wurde editiert
127: if (!newGroup) {
128: t.set("EDIT", "1");
129: }
130:
131: // NONAME=1 : es wurde keine neuer name angegeben
132: if (!nameGiven) {
133: t.set("NONAME", "1");
134: }
135: }
136:
137: WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t,
138: CUSTOMIZE_PROPERTIES);
139: evt.finishTemplate(t);
140: } catch (Throwable e) {
141: throw WebmanExceptionHandler.getException(e);
142: }
143: }
144:
145: public boolean isHandler(TKEvent evt) {
146: return evt.getName().equalsIgnoreCase("CO_PROPGROUP_UPDATE");
147: }
148:
149: }
|