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 http://www.apache.org/licenses/LICENSE-2.0 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;
 
 
 import  org.apache.cayenne.map.Embeddable;
 import  org.apache.cayenne.map.EmbeddableAttribute;
 import  org.apache.cayenne.map.event.EmbeddableAttributeEvent;
 import  org.apache.cayenne.util.Util;
 
 
     private Embeddable embeddable;
 
     // Columns
     static final int OBJ_ATTRIBUTE = 0;
     static final int OBJ_ATTRIBUTE_TYPE = 1;
     static final int DB_ATTRIBUTE = 2;
 
 
     public EmbeddableAttributeTableModel(Embeddable embeddable,
             ProjectController mediatorObject eventSource) {
         super(mediatoreventSourcenew ArrayList<EmbeddableAttribute>(embeddable
                 .getAttributes()));
         this. = embeddable;
 
         // order using local comparator
         Collections.sort(new EmbeddableAttributeComparator());
     }
 
     public EmbeddableAttribute getEmbeddableAttribute(int row) {
         return (row >= 0 && row < .size()) ? (EmbeddableAttribute) 
                 .get(row) : null;
     }
 
     @Override
     public Class<?> getElementsClass() {
         return EmbeddableAttribute.class;
     }
 
     @Override
     public void setUpdatedValueAt(Object valueint rowint col) {
         EmbeddableAttribute attribute = getEmbeddableAttribute(row);
         EmbeddableAttributeEvent event = new EmbeddableAttributeEvent(attribute);
         String path = null;
         Collection<StringnameAttr = null;
         
         if (col == ) {
             event.setOldName(attribute.getName());
             ProjectUtil.setEmbeddableAttributeName(attributevalue != null ? value
              .toString()
              .trim() : null);
 
             fireTableCellUpdated(rowcol);
         }
         else if (col == ) {
             attribute.setType(value != null ? value.toString() : null);
             fireTableCellUpdated(rowcol);
         }
         else if (col == ) {
             attribute.setDbAttributeName(value != null ? value.toString() : null);
             fireTableCellUpdated(rowcol);
         }
         
         .fireEmbeddableAttributeEvent(event);
     }
 
     public int getColumnCount() {
         return 3;
     }
 
     public String getColumnName(int column) {
        switch (column) {
            case :
                return "ObjAttribute";
            case :
                return "Java Type";
            case :
                return "DbAttribute";
            default:
                return "";
        }
    }
    public Object getValueAt(int rowint column) {
        EmbeddableAttribute attribute = getEmbeddableAttribute(row);
        if (column == ) {
            return attribute.getName();
        }
        else if (column == ) {
            return attribute.getType();
        }
        else if (column == ) {
            return attribute.getDbAttributeName();
        }
        else {
            return null;
        }
    }
        this. = new CellEditorForAttributeTable(table, CayenneWidgetFactory.createComboBox(
                nameAttr,
                true));
        return ;
    }
        return ;
    }
    public boolean isCellEditable(int rowint col) {
        return true;
    }
    final class EmbeddableAttributeComparator implements Comparator {
        public int compare(Object o1Object o2) {
            EmbeddableAttribute a1 = (EmbeddableAttribute) o1;
            EmbeddableAttribute a2 = (EmbeddableAttribute) o2;
            int delta = getWeight(a1) - getWeight(a2);
            return (delta != 0) ? delta : Util.nullSafeCompare(truea1.getName(), a2
                    .getName());
        }
        private int getWeight(EmbeddableAttribute a) {
            return a.getEmbeddable() ==  ? 1 : -1;
        }
    }
New to GrepCode? Check out our FAQ X