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.dialog.validator;
 
 
 import  org.apache.cayenne.map.ObjAttribute;
 import  org.apache.cayenne.map.ObjEntity;
 
 
 import java.util.List;
 
 
 import  com.jgoodies.forms.layout.CellConstraints;
 import  com.jgoodies.forms.layout.FormLayout;
 import  com.jgoodies.forms.builder.PanelBuilder;

Dialog for resolving name collision.
 
 public class DuplicatedAttributesDialog extends CayenneDialog {
     
     protected static DuplicatedAttributesDialog instance;
     
     static final String DELETE_ACTION = "delete";
     static final String RENAME_ACTION = "rename";
     
     public static final String CANCEL_RESULT = "cancel";
     public static final String PROCEEDED_RESULT = "proceeded";
     
     static String result = ;
     
     
     protected ObjEntity superEntity;
     protected ObjEntity entity;
     
     protected JTable attributesTable;
     protected JButton cancelButton;
     protected JButton proceedButton;
 
     public static synchronized void showDialog(
             CayenneModelerFrame editor,
             List<ObjAttribute> duplicatedAttributes,
             ObjEntity superEntity,
             ObjEntity entity) {
 
         if ( == null) {
              = new DuplicatedAttributesDialog(editor);
             .centerWindow();
         }
 
         .setSuperEntity(superEntity);
         .setEntity(entity);
         .setDuplicatedAttributes(duplicatedAttributes);
         .updateTable();
         .setVisible(true);
     }
 
     protected DuplicatedAttributesDialog(CayenneModelerFrame editor) {
         super(editor"Duplicated Attributes"true);
 
          = ;
         
         initView();
        initController();
    }
    private void initView() {
         = new JButton("Cancel");
         = new JButton("Continue");
         = new JTable();
        // assemble
        CellConstraints cc = new CellConstraints();
        PanelBuilder builder = new PanelBuilder(new FormLayout(
                "fill:200dlu:grow",
                "pref, 3dlu, top:40dlu:grow"));
        builder.setDefaultDialogBorder();
        builder
                .addLabel(
                        "Select actions for duplicated attributes:",
                        cc.xy(1, 1));
        builder.add(new JScrollPane(), cc.xy(1, 3));
        JPanel buttons = new JPanel(new FlowLayout(.));
        buttons.add();
        buttons.add();
        
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(builder.getPanel(), .);
        getContentPane().add(buttons.);
        // TODO: use preferences
        setSize(450, 350);
    }
    private void initController() {
            public void actionPerformed(ActionEvent e) {
                 = ;
                setVisible(false);
                dispose();
            }
        });
            public void actionPerformed(ActionEvent e) {
                applyChanges();
                 = ;
                setVisible(false);
                dispose();
            }
        });
    }
    public static String getResult() {
        return ;
    }
    private void updateTable() {
        JComboBox actionsCombo = CayenneWidgetFactory.createComboBox(new String[]{}, false);
        actionColumn.setCellEditor(CayenneWidgetFactory.createCellEditor(actionsCombo));
    }
    private void applyChanges() {
        for (DuplicatedAttributeInfo attributeInfo : ) {
            if (attributeInfo.getAction().equals()) {
                .removeAttribute(attributeInfo.getName());
            }
            if (attributeInfo.getAction().equals()) {
                ProjectUtil.setAttributeName(.getAttribute(attributeInfo.getName()), attributeInfo.getNewName());
            }
        }
    }
    
    public void setDuplicatedAttributes(List<ObjAttribute> attributes) {
        if ( == null) {
             = new LinkedList<DuplicatedAttributeInfo>();
        }
        
        .clear();
        
        for (ObjAttribute attribute : attributes) {
            DuplicatedAttributeInfo attributeInfo = new DuplicatedAttributeInfo(attribute.getName(), attribute.getType(),
                    ((ObjAttribute) .getAttribute(attribute.getName())).getType(), );
            .add(attributeInfo);
        }
        
    }
    public void setSuperEntity(ObjEntity superEntity) {
        this. = superEntity;
    }
    public void setEntity(ObjEntity entity) {
        this. = entity;
    }
        
        static final int ATTRIBUTE_NAME = 0;
        static final int PARENT_TYPE = 1;
        static final int TYPE = 2;
        static final int ACTION = 3;

        
Constructor for CayenneTableModel.
        public DuplicatedAttributeTableModel(ProjectController mediatorObject eventSourceList objectList) {
            super(mediatoreventSourceobjectList);
        }
        public void setUpdatedValueAt(Object newValueint rowint column) {
            DuplicatedAttributeInfo attributeInfo = .get(row);
            if(column == ) {
                attributeInfo.setNewName(newValue.toString());
                attributeInfo.setAction();
                //TODO: add warn if new valuew equals the old one or name equals to another attribute name.
                this.fireTableDataChanged();
            }
            if (column == ) {
                attributeInfo.setAction(newValue.toString());
            }
            
        }
        public Class<?> getElementsClass() {
            return DuplicatedAttributeInfo.class;
        }
        public int getColumnCount() {
            return 4;
        }
        public Object getValueAt(int rowint col) {
            DuplicatedAttributeInfo attributeInfo = .get(row);
            switch (col) {
                case :
                    return attributeInfo.getNewName();
                case :
                    return attributeInfo.getParentType();
                case :
                    return attributeInfo.getType();
                case :
                    return attributeInfo.getAction();
                
            }
            return "";
        }
        
        
        public boolean isCellEditable(int rowint column) {
            if (column ==  || column == ) {
                return true;
            }
            return false;
        }
        public String getColumnName(int column) {
            switch (column) {
                case :
                    return "Name";
                case :
                    return "Type in super entity";
                case  :
                    return "Type";
                case :
                    return "Action";
            }
            return " ";
        }
        public Class getColumnClass(int column) {
          return String.class;
        }
    }
    public class DuplicatedAttributeInfo {
        private String name;
        private String newName;
        private String type;
        private String parentType;
        private String action;
        DuplicatedAttributeInfo(String nameString typeString parentTypeString action) {
            this. = name;
            this. = name;
            this. = type;
            this. = parentType;
            this. = action;
        }
        public String getName() {
            return ;
        }
        public String getType() {
            return ;
        }
        public String getParentType() {
            return ;
        }
        public String getAction() {
            return ;
        }
        public void setAction(String action) {
            this. = action;
        }
        public String getNewName() {
            return ;
        }
        public void setNewName(String newName) {
            this. = newName;
        }
    }
    
New to GrepCode? Check out our FAQ X