Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 package org.apache.cayenne.modeler.editor.dbentity;
 import  org.apache.cayenne.dba.TypesMapping;
Detail view of the DbEntity attributes.

Michael Misha Shengaout
Andrei Adamchik
 public class DbEntityAttributeTab extends JPanel implements DbEntityDisplayListener,
         ListSelectionListener, DbAttributeListener, ExistingSelectionProcessor,
         ActionListener {
     protected ProjectController mediator;
     protected CayenneTable table;
     protected JButton editParams;
     public DbEntityAttributeTab(ProjectController temp_mediator) {
          = temp_mediator;
         // Create and layout components
     private void init() {
         this.setLayout(new BorderLayout());
         JToolBar toolBar = new JToolBar();
         Application app = Application.getInstance();
          = new JButton();
        .setToolTipText("Edit Parameters");
        // Create table with two columns and no rows.
         = new CayenneTable();
        add(PanelFactory.createTablePanel(null), .);
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == ) {
            int row = .getSelectedRow();
            if (row >= 0) {
                DbAttribute attr = ((DbAttributeTableModel.getModel())
                EditDerivedParamsDialog dialog = new EditDerivedParamsDialog(
                        (DerivedDbAttribute) attr);
    public void valueChanged(ListSelectionEvent e) {

Selects a specified attribute.
    public void selectAttribute(DbAttribute attr) {
        if (attr == null) {
        // enable the remove button
        java.util.List attrs = model.getObjectList();
        int attrPos = attrs.indexOf(attr);
        if (attrPos >= 0) {
    public void processExistingSelection(EventObject e) {
        if (e instanceof ChangeEvent) {
        DbAttribute att = null;
        if (.getSelectedRow() >= 0) {
            DbAttributeTableModel model = (DbAttributeTableModel.getModel();
            att = model.getAttribute(.getSelectedRow());
            .setEnabled(att instanceof DerivedDbAttribute);
            // scroll table
    public void dbAttributeChanged(AttributeEvent e) {
    public void dbAttributeAdded(AttributeEvent e) {
        rebuildTable((DbEntity) e.getEntity());
    public void dbAttributeRemoved(AttributeEvent e) {
        int ind = model.getObjectList().indexOf(e.getAttribute());
    public void currentDbEntityChanged(EntityDisplayEvent e) {
        DbEntity entity = (DbEntity) e.getEntity();
        if (entity != null && e.isEntityChanged()) {
        // if an entity was selected on a tree,
        // unselect currently selected row
        if (e.isUnselectAttributes()) {
    protected void rebuildTable(DbEntity ent) {
        .setVisible(ent instanceof DerivedDbEntity);
        DbAttributeTableModel model = (ent instanceof DerivedDbEntity)
                ? new DerivedDbAttributeTableModel(entthis)
                : new DbAttributeTableModel(entthis);
        TableColumn col = .getColumnModel().getColumn(model.nameColumnInd());
        col = .getColumnModel().getColumn(model.typeColumnInd());
        String[] types = TypesMapping.getDatabaseTypes();
        JComboBox comboBox = CayenneWidgetFactory.createComboBox(typestrue);
        col.setCellEditor(new DefaultCellEditor(comboBox));
New to GrepCode? Check out our FAQ X