// THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
// OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright 2000-2005 Softaris Pty.Ltd. All Rights Reserved.
package com.metaboss.applications.designstudio.errorsview;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.AbstractButton;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.metaboss.applications.designstudio.Application;
import com.metaboss.applications.designstudio.BaseAction;
import com.metaboss.applications.designstudio.BaseLogPanel;
import com.metaboss.applications.designstudio.BaseUserObject;
import com.metaboss.applications.designstudio.Application.ObjectChangedEvent;
import com.metaboss.applications.designstudio.Application.OnErrorsFoundEvent;
import com.metaboss.applications.designstudio.Application.OnModelChangedEvent;
import com.metaboss.applications.designstudio.userobjects.ModelUserObject;
/* Errors view panel class */
public class ErrorsViewPanel extends BaseLogPanel
{
private boolean mNew = true;
// UI
private ErrorsModel mModel = new ErrorsModel();
private ErrorsTable mErrorsTable = new ErrorsTable(mModel);
// actions
private EditElementAction mEditElementAction = new EditElementAction();
private ErrorInfoAction mErrorInfoAction = new ErrorInfoAction();
private ErrorFilterAction mErrorFilterAction = new ErrorFilterAction();
// constructor
public ErrorsViewPanel()
{
super();
add(mToolBar, BorderLayout.WEST);
add(new JScrollPane(mErrorsTable));
Application.addOnErrorsFoundListener(new Application.OnErrorsFoundListener()
{
public void errorsFound(OnErrorsFoundEvent event)
{
loadErrors();
}
});
Application.addOnModelChangedListener(new Application.OnModelChangedListener()
{
public void modelChanged(OnModelChangedEvent event)
{
if (event.getEventSource()==OnModelChangedEvent.CURRENT_CHANGED)
loadErrors();
}
});
Application.addObjectChanged(new Application.ObjectChangedListener()
{
public void onObjectChanged(ObjectChangedEvent event)
{
switch (event.getEventSource())
{
case ObjectChangedEvent.ET_SELECTED:
if (Application.sErrorElement==null)
checkActions();
else
loadErrors();
break;
}
}
});
mErrorsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
checkActions();
}
});
Application.addCloseModelListener(new Application.CloseModelListener()
{
public void closeModel(Application.CloseModelEvent event)
{
loadErrors();
}
});
}
protected void fillChildControls()
{
//???
}
// load model errors
public void loadErrors()
{
ModelUserObject lCurrentModelObject = Application.getCurrentPackage();
if (lCurrentModelObject != null)
mModel.loadErrors(lCurrentModelObject.getFileName());
checkActions();
checkErrorsFoundButton();
}
public void setBounds(int x, int y, int width, int height)
{
int lOldWidth = getWidth();
super.setBounds(x, y, width, height);
//if (lOldWidth!=width)
// mErrorsTable.resizeColumns(width-mToolBar.getWidth()-3);
if (lOldWidth!=width)
{
int lWidth = width-mToolBar.getWidth()-3;
if (mNew)
{
lWidth -= 25;
mNew = false;
}
mErrorsTable.resizeColumns(lWidth);
}
}
protected void clearContent()
{
Application.removeModelErrors(Application.getCurrentPackage());
mModel.clearErrorrs();
checkActions();
}
protected void copyToClipboard()
{
String lContenth = "";
for (int i=0; i<mModel.getRowCount(); i++)
{
String lError = mModel.getErrorInfo(i).mFullDescription + "\r\n\r\n";
lContenth += lError;
}
mInformationPane.setText(lContenth);
super.copyToClipboard();
}
// edit error model element
protected void editModelElement()
{
int lRow = mErrorsTable.getSelectedRow();
if (lRow>-1)
{
String lID = mModel.getErrorInfo(lRow).mMofID;
if (lID!=null && lID.length()>0)
{
BaseUserObject lObject = Application.getUserObjectByID(lID);
if (lObject!=null)
{
Application.fireObjectSelect(lObject);
lObject.getEditAction().run();
}
}
}
}
protected void fillActions(ArrayList pList)
{
pList.add(mEditElementAction);
pList.add(mErrorInfoAction);
pList.add(mErrorFilterAction);
super.fillActions(pList);
}
// check Actions activity
protected void checkActions()
{
int lRow = mErrorsTable.getSelectedRow();
mEditElementAction.setEnabled(lRow>-1);
mErrorInfoAction.setEnabled(lRow>-1);
int lCount = mModel.getRowCount();
mCopyToClipBoardAction.setEnabled(lCount>0);
mClearAction.setEnabled(lCount>0);
BaseUserObject lObject = Application.getCurrentUserObject();
mErrorFilterAction.setEnabled(lObject!=null && Application.getErrorsCount()>0);
}
protected void viewErrorProperties()
{
mErrorsTable.viewErrorProperties();
}
protected AbstractButton getFilterButton()
{
for (int i=0; i<mToolBar.getComponentCount(); i++)
{
if (mToolBar.getComponent(i) instanceof AbstractButton)
{
AbstractButton lButton = (AbstractButton)mToolBar.getComponent(i);
if (lButton!=null && lButton.getAction().equals(mErrorFilterAction))
return lButton;
}
}
return null;
}
protected void checkErrorsFoundButton()
{
AbstractButton lButton = getFilterButton();
if (lButton!=null)
{
lButton.setSelected(mErrorFilterAction.isChecked());
if (lButton.isSelected())
{
BaseUserObject lObject = Application.getCurrentUserObject();
if (lObject!=null)
Application.setErrorElementID(lObject.getID());
lButton.setToolTipText("List errors from whole Model");
}
else
{
Application.setErrorElementID(null);
lButton.setToolTipText("List errors from selected Model Element or its children");
}
}
}
/* Auxilary classes */
public class EditElementAction extends BaseAction
{
public EditElementAction()
{
super("Edit Model Element", " Edit Model Element, which is a source of the selected error", Application.EDIT_ICON);
}
public void actionPerformed(ActionEvent arg0)
{
editModelElement();
}
}
public class ErrorInfoAction extends BaseAction
{
public ErrorInfoAction()
{
super("Error Description", "Show full description of the error", Application.DESCRIPTION_ICON);
}
public void actionPerformed(ActionEvent arg0)
{
viewErrorProperties();
}
}
public class ErrorFilterAction extends BaseAction
{
public ErrorFilterAction()
{
super("Current Element Errors", "List errors from selected Model Element or its children", Application.ELEMENTERROR_ICON);
mIsCheck = true;
mSelectedIcon = Application.MODELERROR_ICON;
setChecked(Application.sErrorElement!=null);
}
public void actionPerformed(ActionEvent arg0)
{
super.actionPerformed(arg0);
checkErrorsFoundButton();
}
}
}
|