001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.fieldstable;
016:
017: import java.awt.BorderLayout;
018: import java.awt.event.ActionEvent;
019:
020: import javax.swing.JPanel;
021: import javax.swing.JScrollPane;
022: import javax.swing.JToolBar;
023: import javax.swing.ListSelectionModel;
024: import javax.swing.border.Border;
025: import javax.swing.event.ListSelectionEvent;
026: import javax.swing.event.ListSelectionListener;
027:
028: import com.metaboss.applications.designstudio.Application;
029: import com.metaboss.applications.designstudio.BaseAction;
030: import com.metaboss.applications.designstudio.BasePropertiesDialog;
031: import com.metaboss.applications.designstudio.BaseUserObject;
032: import com.metaboss.applications.designstudio.components.FieldsTable;
033: import com.metaboss.applications.designstudio.userobjects.EventDataFieldUserObject;
034: import com.metaboss.applications.designstudio.userobjects.EventMessageFieldUserObject;
035: import com.metaboss.applications.designstudio.userobjects.MessageFieldUserObject;
036: import com.metaboss.applications.designstudio.userobjects.OperationInputFieldUserObject;
037: import com.metaboss.applications.designstudio.userobjects.OperationOutputFieldUserObject;
038: import com.metaboss.applications.designstudio.userobjects.OperationOutputMessageUserObject;
039: import com.metaboss.applications.designstudio.userobjects.OperationUserObject;
040: import com.metaboss.applications.designstudio.userobjects.StructureFieldUserObject;
041: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
042: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
043: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Event;
044: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
045: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
046: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
047: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
048:
049: /* Fields Edit Panel */
050:
051: public class FieldsEditPanel extends JPanel {
052: private ModelElement mMaster = null;
053: private int mMode = 0;
054: // fields
055: private FieldsEditTableModel mModel = null;
056: private FieldsTable mTable = null;
057: private JToolBar mToolBar = new JToolBar();
058: // actions
059: private AddFieldAction mAddFieldAction = new AddFieldAction();
060: private EditFieldAction mEditFieldAction = new EditFieldAction();
061: private DeleteFieldAction mDeleteFieldAction = new DeleteFieldAction();
062:
063: public FieldsEditPanel(int pMode) {
064: super ();
065:
066: mMode = pMode;
067: setLayout(new BorderLayout());
068:
069: mModel = (pMode == 4) ? new FieldsEditTableModel("Operation",
070: "Transaction Policy") : new FieldsEditTableModel();
071: mTable = new FieldsTable(mModel);
072:
073: add(new JScrollPane(mTable), BorderLayout.CENTER);
074: add(mToolBar, BorderLayout.SOUTH);
075:
076: mTable.setRowHeight(20);
077: mTable.setCellSelectionEnabled(true);
078: mTable.setRowSelectionAllowed(true);
079: mTable.setColumnSelectionAllowed(false);
080: mTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
081:
082: mToolBar.setBorder(null);
083: mToolBar.add(Application.createButton(mAddFieldAction));
084: mToolBar.add(Application.createButton(mEditFieldAction));
085: mToolBar.add(Application.createButton(mDeleteFieldAction));
086:
087: Border lBorder = BasePropertiesDialog.createEditorBorder();
088: setBorder(lBorder);
089:
090: mTable.getSelectionModel().addListSelectionListener(
091: new ListSelectionListener() {
092: public void valueChanged(ListSelectionEvent e) {
093: checkActions();
094: }
095: });
096: checkActions();
097: }
098:
099: public FieldsEditPanel() {
100: this (0);
101: }
102:
103: // load fields
104: public void loadFields(ModelElement pElement) {
105: mMaster = pElement;
106: mModel.loadFields(pElement, mMode);
107: }
108:
109: // add attribute
110: private void addField() {
111: if (mMaster != null) {
112: try {
113: if (mMaster instanceof Structure)
114: StructureFieldUserObject
115: .addNewStructureField((Structure) mMaster);
116: else if (mMaster instanceof Message)
117: MessageFieldUserObject
118: .addNewMessageField((Message) mMaster);
119: else if (mMaster instanceof Service)
120: OperationUserObject
121: .addNewOperation((Service) mMaster);
122: else if (mMaster instanceof Operation) {
123: switch (mMode) {
124: case 1:
125: OperationInputFieldUserObject
126: .addNewOperationInputField((Operation) mMaster);
127: break;
128: case 2:
129: OperationOutputFieldUserObject
130: .addNewOperationOutputField((Operation) mMaster);
131: break;
132: case 3:
133: OperationOutputMessageUserObject
134: .addNewMessage((Operation) mMaster);
135: break;
136: }
137: } else if (mMaster instanceof EventSubscriptionOperation) {
138: switch (mMode) {
139: case 1:
140: OperationInputFieldUserObject
141: .addNewOperationInputField((EventSubscriptionOperation) mMaster);
142: break;
143: case 2:
144: OperationOutputFieldUserObject
145: .addNewOperationOutputField((EventSubscriptionOperation) mMaster);
146: break;
147: case 3:
148: OperationOutputMessageUserObject
149: .addNewMessage((EventSubscriptionOperation) mMaster);
150: break;
151: }
152: } else if (mMaster instanceof Event) {
153: switch (mMode) {
154: case 1:
155: EventDataFieldUserObject
156: .addNewEventDataFieldField((Event) mMaster);
157: break;
158: case 2:
159: EventMessageFieldUserObject
160: .addNewField((Event) mMaster);
161: break;
162: }
163: }
164: } catch (Exception e) {
165: Application.processError(e);
166: }
167: }
168: }
169:
170: // edit current attribute
171: private void editField() {
172: BaseUserObject lField = mModel.getUserObject(mTable
173: .getSelectedRow());
174: if (lField != null)
175: lField.getEditAction().run();
176: }
177:
178: // delete Attribute
179: private void deleteField() {
180: BaseUserObject lField = mModel.getUserObject(mTable
181: .getSelectedRow());
182: if (lField != null)
183: lField.getDeleteAction().run();
184: }
185:
186: // check edit actins
187: private void checkActions() {
188: boolean lEditOk = mTable != null
189: && mTable.getSelectedRow() > -1;
190:
191: mAddFieldAction.setEnabled(true);
192: mEditFieldAction.setEnabled(lEditOk);
193: mDeleteFieldAction.setEnabled(lEditOk);
194: }
195:
196: /* Auxilary classes */
197:
198: /* Fields table model */
199:
200: public class FieldsEditTableModel extends FieldsTableModel {
201: public FieldsEditTableModel(String pFirstColumn,
202: String pSecondColumn) {
203: super (pFirstColumn, pSecondColumn);
204: }
205:
206: public FieldsEditTableModel() {
207: super ();
208: }
209:
210: public int getColumnCount() {
211: return 3;
212: }
213: }
214:
215: /* Actions */
216:
217: public class AddFieldAction extends BaseAction {
218: public AddFieldAction() {
219: super ("Add New Field", Application.ADDNEW_ICON);
220: }
221:
222: public void actionPerformed(ActionEvent arg0) {
223: addField();
224: }
225: }
226:
227: public class EditFieldAction extends BaseAction {
228: public EditFieldAction() {
229: super ("Edit Field", Application.EDIT_ICON);
230: }
231:
232: public void actionPerformed(ActionEvent arg0) {
233: editField();
234: }
235: }
236:
237: public class DeleteFieldAction extends BaseAction {
238: public DeleteFieldAction() {
239: super ("Delete Attribute", Application.DELETE_ICON);
240: }
241:
242: public void actionPerformed(ActionEvent arg0) {
243: deleteField();
244: }
245: }
246: }
|