ErrorsTable.java :  » UML » MetaBoss » com » metaboss » applications » designstudio » errorsview » Java Open Source

Java Open Source » UML » MetaBoss 
MetaBoss » com » metaboss » applications » designstudio » errorsview » ErrorsTable.java
// 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.Component;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;

import com.metaboss.applications.designstudio.Application;
import com.metaboss.applications.designstudio.BaseUserObject;
import com.metaboss.applications.designstudio.auxilarydialogs.ErrorDescriptionDialog;

/*    Errors table class    */

public class ErrorsTable extends JTable
{
  public ErrorsTable(AbstractTableModel pModel)
  {
    super(pModel);
  
    setAutoResizeMode(AUTO_RESIZE_OFF);
    setCellSelectionEnabled(true);
    setRowSelectionAllowed(true);
    setColumnSelectionAllowed(false);
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  
    TableColumn lFirstColumn = getColumnModel().getColumn(0);
    TableColumn lSecondColumn = getColumnModel().getColumn(1);
    TableColumn lThirdColumn = getColumnModel().getColumn(2); 

    lFirstColumn.setMinWidth(20);
    lFirstColumn.setPreferredWidth(20);
    lFirstColumn.setCellRenderer(new DefaultTableCellRenderer()
    {
      private JLabel mLabel = new JLabel();
            
      public Component getTableCellRendererComponent(JTable table,
         Object value, boolean isSelected, boolean hasFocus,
         int row, int column)
      {
        mLabel.setText(value.toString());
        mLabel.setHorizontalAlignment(SwingConstants.CENTER);
        return mLabel;        
      }
    }); 
  
    lThirdColumn.setPreferredWidth(200);  

    int lWidth = getWidth() - lThirdColumn.getPreferredWidth() - lFirstColumn.getPreferredWidth();
    if (lWidth<300) lWidth = 300;  
    lSecondColumn.setPreferredWidth(lWidth);
    
    addMouseListener(new MouseHandler());
  }
  
  public void resizeColumns(int pWidth)
  {
    TableColumn lFirstColumn = getColumnModel().getColumn(0);
    TableColumn lSecondColumn = getColumnModel().getColumn(1);
    TableColumn lThirdColumn = getColumnModel().getColumn(2); 

    int lWidth = pWidth - lThirdColumn.getWidth() - lFirstColumn.getWidth();
    if (lWidth<300) lWidth = 300;  
    lSecondColumn.setPreferredWidth(lWidth);
  }
  
  // view error information
  public void viewErrorProperties()
  {
    int lRow = getSelectedRow();
    if (lRow>-1)
    {
      String lError = ((ErrorsModel)getModel()).getErrorInfo(lRow).mFullDescription;
      ErrorDescriptionDialog lDialog = new ErrorDescriptionDialog(lError);
      lDialog.getModalResult(); 
    }
  }
  
    public String getToolTipText(MouseEvent event)
    {
       int lIndex = rowAtPoint(event.getPoint());
       if (lIndex>-1)
       {
      ErrorsModel lModel = (ErrorsModel)getModel();
      return lModel.getErrorInfo(lIndex).mDescription;
       }
        return super.getToolTipText(event);
    }
  
  public Point getToolTipLocation(MouseEvent event)
  {
    int lIndex = rowAtPoint(event.getPoint());
    if (lIndex>-1)
    {
      Rectangle lRect = getCellRect(lIndex, 1, true);
      return new Point(lRect.x, lRect.y);
    }
      return super.getToolTipLocation(event);
  }
  
  /*    Auxilary classes      */
  
  /*    Table Mouse Events Handler    */
    
  public class MouseHandler extends MouseAdapter
  {
    public void mousePressed(MouseEvent e)
    {
      if ((e.getModifiers() & MouseEvent.BUTTON1_MASK)!=0)
      { 
        ErrorsModel lModel = (ErrorsModel)getModel();
        String lID = lModel.getErrorInfo(getSelectedRow()).mMofID;
        if (lID!=null && lID.length()>0)
        {        
          BaseUserObject lObject = Application.getUserObjectByID(lID);
          if (lObject!=null)
          {
            /*if (e.getClickCount()==1)
            {
              Application.fireObjectSelect(lObject);
            }  else*/
            if (e.getClickCount()==2)
            {
              //lObject.getEditAction().run();
              Application.fireObjectSelect(lObject);
              viewErrorProperties();
            }
          }
        }
      }
      super.mousePressed(e);
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.