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.propertiesdialogs;
016:
017: import java.awt.BorderLayout;
018: import java.awt.Dimension;
019: import java.awt.event.ActionEvent;
020:
021: import javax.swing.JPanel;
022: import javax.swing.JScrollPane;
023: import javax.swing.JTabbedPane;
024: import javax.swing.JToolBar;
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.Application.ObjectChangedEvent;
033: import com.metaboss.applications.designstudio.propertiesview.PropertiesTable;
034: import com.metaboss.applications.designstudio.tagstable.TagsEditModel;
035: import com.metaboss.applications.designstudio.userobjects.ModelElementTagUserObject;
036: import com.metaboss.applications.designstudio.userobjects.UserObjectFactory;
037: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
038: import com.metaboss.sdlctools.models.metabossmodel.ModelElementTag;
039:
040: /* Model Element Properties Dialog */
041:
042: public class ModelElementPropertiesDialog extends BasePropertiesDialog {
043: // static members
044: public static final String TABINDEX_POSITION = "TabIndex";
045:
046: protected ModelElement mModelElement = null;
047: //protected int mLoadTabIndex;
048: //ui
049: protected JTabbedPane mTabControl = new JTabbedPane();
050: protected JPanel mPropertiesPanel = new JPanel();
051: protected JPanel mTagsPanel = new JPanel();
052: protected TagsEditModel mTagModel = new TagsEditModel();
053: protected PropertiesTable mTagTable = new PropertiesTable(mTagModel);
054: protected JToolBar mToolBar = new JToolBar();
055: //actions
056: protected AddTagAction mAddTagAction = new AddTagAction();
057: protected DeleteTagAction mDeleteTagAction = new DeleteTagAction();
058: //listeners
059: private Application.ObjectChangedListener mObjectChangedListener = null;
060:
061: public ModelElementPropertiesDialog(String pCaption,
062: Dimension pDimension) {
063: super (pCaption, true, pDimension);
064:
065: setResizable(true);
066:
067: mClient.setLayout(new BorderLayout());
068: mButtonBar.setBorder(null);
069:
070: mPropertiesPanel.setLayout(mClientGridBagLayout);
071: mTagsPanel.setLayout(new BorderLayout());
072: mTagsPanel.setBorder(createEditorBorder());
073:
074: mTagsPanel.add(new JScrollPane(mTagTable), BorderLayout.CENTER);
075: mTagsPanel.add(mToolBar, BorderLayout.SOUTH);
076:
077: mTagTable.setCellSelectionEnabled(true);
078: mTagTable.setRowSelectionAllowed(true);
079:
080: mToolBar.setBorder(null);
081: mToolBar.add(Application.createButton(mAddTagAction));
082: mToolBar.add(Application.createButton(mDeleteTagAction));
083:
084: mTabControl.addTab("Properties", mPropertiesPanel);
085: mTabControl.addTab("Tags", mTagsPanel);
086: mTabControl.setBorder(null);
087: mTabControl.setFont(Application.DEFAULT_FONT);
088:
089: mClient.add(mTabControl);
090:
091: mObjectChangedListener = new Application.ObjectChangedListener() {
092: public void onObjectChanged(ObjectChangedEvent event) {
093: switch (event.getEventSource()) {
094: case ObjectChangedEvent.ET_INSERTED:
095: processTagObjectAdded(event.getUserObject());
096: break;
097: case ObjectChangedEvent.ET_DELETED:
098: processTagObjectDeleted(event.getObjectID());
099: break;
100: }
101: }
102: };
103: Application.addObjectChanged(mObjectChangedListener);
104: checkTagActions();
105: }
106:
107: protected void removeListeneres() {
108: super .removeListeneres();
109: Application.removeObjectChanged(mObjectChangedListener);
110: }
111:
112: // load service module properties
113: public void loadProperties(ModelElement pObject) throws Exception {
114: //setLoadedTabIndex();
115: mModelElement = pObject;
116: if (pObject != null) {
117: mTagModel.loadTags(pObject.getTags().toArray());
118: checkTagActions();
119: mTagTable.getSelectionModel().addListSelectionListener(
120: new ListSelectionListener() {
121: public void valueChanged(ListSelectionEvent e) {
122: checkTagActions();
123: }
124: });
125: }
126: super .loadProperties(pObject);
127: }
128:
129: // save service module proeprties
130: public void saveProperties(ModelElement pObject) throws Exception {
131: if (mTagTable.getCellEditor() != null)
132: mTagTable.getCellEditor().stopCellEditing();
133: mModelElement = pObject;
134: super .saveProperties(pObject);
135: if (pObject != null) {
136: //???
137: }
138: }
139:
140: // add ModelElement tag
141: protected void addNewTag() {
142: try {
143: ModelElementTagUserObject.createNewTag(mModelElement);
144: } catch (Exception e) {
145: Application.processError(e);
146: }
147: }
148:
149: protected void deleteCurrentTag() {
150: ModelElementTag lTag = mTagModel.getTag(mTagTable
151: .getSelectedRow());
152: if (lTag != null) {
153: try {
154: UserObjectFactory.createUserObject(lTag)
155: .getDeleteAction().run();
156: } catch (Exception e) {
157: Application.processError(e);
158: }
159: }
160: }
161:
162: // process new object added
163: protected void processTagObjectAdded(BaseUserObject pObject) {
164: if (pObject != null
165: && pObject instanceof ModelElementTagUserObject) {
166: ModelElementTagUserObject pTag = (ModelElementTagUserObject) pObject;
167: if (pTag.getTag().getElement().equals(mModelElement)) {
168: mTagModel.addTag(pTag.getTag());
169: checkTagActions();
170: int lIndex = mTagModel.getRowCount() - 1;
171: mTagTable.getSelectionModel().setLeadSelectionIndex(
172: lIndex);
173: mTagTable.editCellAt(lIndex, 0);
174: }
175: }
176: }
177:
178: // process object deleted
179: protected void processTagObjectDeleted(String pID) {
180: int lIndex = mTagModel.getIDIndex(pID);
181: if (lIndex > -1) {
182: mTagModel.deleteProperty(lIndex);
183: checkTagActions();
184: }
185: }
186:
187: // check Tag panel buttons
188: protected void checkTagActions() {
189: int lIndex = mTagTable.getSelectedRow();
190: mDeleteTagAction.setEnabled(lIndex > -1);
191: }
192:
193: // load dialog properties
194: /*protected void loadPreferences()
195: {
196: super.loadPreferences();
197: String lTabIndexSetting = getProperty(TABINDEX_POSITION);
198: if (lTabIndexSetting!=null)
199: mLoadTabIndex = Integer.parseInt(lTabIndexSetting);
200: else
201: setPropertyNoModified(TABINDEX_POSITION, new Integer(mLoadTabIndex).toString());
202: }
203:
204: // save dialog properties
205: protected void savePreferences()
206: {
207: super.savePreferences();
208: setProperty(TABINDEX_POSITION, new Integer(mTabControl.getSelectedIndex()).toString());
209: }
210:
211: // set loaded tab indx to the tab control
212: protected void setLoadedTabIndex()
213: {
214: if (mLoadTabIndex>=0 && mLoadTabIndex<mTabControl.getTabCount())
215: {
216: try
217: {
218: mTabControl.setSelectedIndex(mLoadTabIndex);
219: }
220: catch (Exception e)
221: {
222: e.printStackTrace();
223: }
224: }
225: }*/
226:
227: /* Auxilary classes */
228:
229: /* Actions */
230:
231: public class AddTagAction extends BaseAction {
232: public AddTagAction() {
233: super ("Add New Tag", Application.ADDNEW_ICON);
234: }
235:
236: public void actionPerformed(ActionEvent arg0) {
237: addNewTag();
238: }
239: }
240:
241: public class DeleteTagAction extends BaseAction {
242: public DeleteTagAction() {
243: super ("Delete Tag", Application.DELETE_ICON);
244: }
245:
246: public void actionPerformed(ActionEvent arg0) {
247: deleteCurrentTag();
248: }
249: }
250: }
|