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.errorsview;
016:
017: import java.awt.BorderLayout;
018: import java.awt.event.ActionEvent;
019: import java.util.ArrayList;
020:
021: import javax.swing.AbstractButton;
022: import javax.swing.JScrollPane;
023: import javax.swing.event.ListSelectionEvent;
024: import javax.swing.event.ListSelectionListener;
025:
026: import com.metaboss.applications.designstudio.Application;
027: import com.metaboss.applications.designstudio.BaseAction;
028: import com.metaboss.applications.designstudio.BaseLogPanel;
029: import com.metaboss.applications.designstudio.BaseUserObject;
030: import com.metaboss.applications.designstudio.Application.ObjectChangedEvent;
031: import com.metaboss.applications.designstudio.Application.OnErrorsFoundEvent;
032: import com.metaboss.applications.designstudio.Application.OnModelChangedEvent;
033: import com.metaboss.applications.designstudio.userobjects.ModelUserObject;
034:
035: /* Errors view panel class */
036:
037: public class ErrorsViewPanel extends BaseLogPanel {
038: private boolean mNew = true;
039: // UI
040: private ErrorsModel mModel = new ErrorsModel();
041: private ErrorsTable mErrorsTable = new ErrorsTable(mModel);
042: // actions
043: private EditElementAction mEditElementAction = new EditElementAction();
044: private ErrorInfoAction mErrorInfoAction = new ErrorInfoAction();
045: private ErrorFilterAction mErrorFilterAction = new ErrorFilterAction();
046:
047: // constructor
048: public ErrorsViewPanel() {
049: super ();
050:
051: add(mToolBar, BorderLayout.WEST);
052: add(new JScrollPane(mErrorsTable));
053:
054: Application
055: .addOnErrorsFoundListener(new Application.OnErrorsFoundListener() {
056: public void errorsFound(OnErrorsFoundEvent event) {
057: loadErrors();
058: }
059: });
060: Application
061: .addOnModelChangedListener(new Application.OnModelChangedListener() {
062: public void modelChanged(OnModelChangedEvent event) {
063: if (event.getEventSource() == OnModelChangedEvent.CURRENT_CHANGED)
064: loadErrors();
065: }
066: });
067: Application
068: .addObjectChanged(new Application.ObjectChangedListener() {
069: public void onObjectChanged(ObjectChangedEvent event) {
070: switch (event.getEventSource()) {
071: case ObjectChangedEvent.ET_SELECTED:
072: if (Application.sErrorElement == null)
073: checkActions();
074: else
075: loadErrors();
076: break;
077: }
078: }
079: });
080: mErrorsTable.getSelectionModel().addListSelectionListener(
081: new ListSelectionListener() {
082: public void valueChanged(ListSelectionEvent e) {
083: checkActions();
084: }
085: });
086: Application
087: .addCloseModelListener(new Application.CloseModelListener() {
088: public void closeModel(
089: Application.CloseModelEvent event) {
090: loadErrors();
091: }
092: });
093: }
094:
095: protected void fillChildControls() {
096: //???
097: }
098:
099: // load model errors
100: public void loadErrors() {
101: ModelUserObject lCurrentModelObject = Application
102: .getCurrentPackage();
103: if (lCurrentModelObject != null)
104: mModel.loadErrors(lCurrentModelObject.getFileName());
105: checkActions();
106: checkErrorsFoundButton();
107: }
108:
109: public void setBounds(int x, int y, int width, int height) {
110: int lOldWidth = getWidth();
111: super .setBounds(x, y, width, height);
112:
113: //if (lOldWidth!=width)
114: // mErrorsTable.resizeColumns(width-mToolBar.getWidth()-3);
115:
116: if (lOldWidth != width) {
117: int lWidth = width - mToolBar.getWidth() - 3;
118: if (mNew) {
119: lWidth -= 25;
120: mNew = false;
121: }
122: mErrorsTable.resizeColumns(lWidth);
123: }
124: }
125:
126: protected void clearContent() {
127: Application.removeModelErrors(Application.getCurrentPackage());
128: mModel.clearErrorrs();
129: checkActions();
130: }
131:
132: protected void copyToClipboard() {
133: String lContenth = "";
134: for (int i = 0; i < mModel.getRowCount(); i++) {
135: String lError = mModel.getErrorInfo(i).mFullDescription
136: + "\r\n\r\n";
137: lContenth += lError;
138: }
139: mInformationPane.setText(lContenth);
140: super .copyToClipboard();
141: }
142:
143: // edit error model element
144: protected void editModelElement() {
145: int lRow = mErrorsTable.getSelectedRow();
146: if (lRow > -1) {
147: String lID = mModel.getErrorInfo(lRow).mMofID;
148: if (lID != null && lID.length() > 0) {
149: BaseUserObject lObject = Application
150: .getUserObjectByID(lID);
151: if (lObject != null) {
152: Application.fireObjectSelect(lObject);
153: lObject.getEditAction().run();
154: }
155: }
156: }
157: }
158:
159: protected void fillActions(ArrayList pList) {
160: pList.add(mEditElementAction);
161: pList.add(mErrorInfoAction);
162: pList.add(mErrorFilterAction);
163: super .fillActions(pList);
164: }
165:
166: // check Actions activity
167: protected void checkActions() {
168: int lRow = mErrorsTable.getSelectedRow();
169: mEditElementAction.setEnabled(lRow > -1);
170: mErrorInfoAction.setEnabled(lRow > -1);
171:
172: int lCount = mModel.getRowCount();
173: mCopyToClipBoardAction.setEnabled(lCount > 0);
174: mClearAction.setEnabled(lCount > 0);
175:
176: BaseUserObject lObject = Application.getCurrentUserObject();
177: mErrorFilterAction.setEnabled(lObject != null
178: && Application.getErrorsCount() > 0);
179: }
180:
181: protected void viewErrorProperties() {
182: mErrorsTable.viewErrorProperties();
183: }
184:
185: protected AbstractButton getFilterButton() {
186: for (int i = 0; i < mToolBar.getComponentCount(); i++) {
187: if (mToolBar.getComponent(i) instanceof AbstractButton) {
188: AbstractButton lButton = (AbstractButton) mToolBar
189: .getComponent(i);
190: if (lButton != null
191: && lButton.getAction().equals(
192: mErrorFilterAction))
193: return lButton;
194: }
195: }
196: return null;
197: }
198:
199: protected void checkErrorsFoundButton() {
200: AbstractButton lButton = getFilterButton();
201: if (lButton != null) {
202: lButton.setSelected(mErrorFilterAction.isChecked());
203: if (lButton.isSelected()) {
204: BaseUserObject lObject = Application
205: .getCurrentUserObject();
206: if (lObject != null)
207: Application.setErrorElementID(lObject.getID());
208: lButton.setToolTipText("List errors from whole Model");
209: } else {
210: Application.setErrorElementID(null);
211: lButton
212: .setToolTipText("List errors from selected Model Element or its children");
213: }
214: }
215: }
216:
217: /* Auxilary classes */
218:
219: public class EditElementAction extends BaseAction {
220: public EditElementAction() {
221: super (
222: "Edit Model Element",
223: " Edit Model Element, which is a source of the selected error",
224: Application.EDIT_ICON);
225: }
226:
227: public void actionPerformed(ActionEvent arg0) {
228: editModelElement();
229: }
230: }
231:
232: public class ErrorInfoAction extends BaseAction {
233: public ErrorInfoAction() {
234: super ("Error Description",
235: "Show full description of the error",
236: Application.DESCRIPTION_ICON);
237: }
238:
239: public void actionPerformed(ActionEvent arg0) {
240: viewErrorProperties();
241: }
242: }
243:
244: public class ErrorFilterAction extends BaseAction {
245: public ErrorFilterAction() {
246: super (
247: "Current Element Errors",
248: "List errors from selected Model Element or its children",
249: Application.ELEMENTERROR_ICON);
250: mIsCheck = true;
251: mSelectedIcon = Application.MODELERROR_ICON;
252: setChecked(Application.sErrorElement != null);
253: }
254:
255: public void actionPerformed(ActionEvent arg0) {
256: super.actionPerformed(arg0);
257: checkErrorsFoundButton();
258: }
259: }
260: }
|