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.db;
 
 import java.util.List;
 import java.util.Map;
 
 import  org.apache.cayenne.map.DataMap;
 import  org.apache.cayenne.map.DbAttribute;
 import  org.apache.cayenne.map.DbEntity;
 import  org.apache.cayenne.map.DbRelationship;
 import  org.apache.cayenne.map.Entity;
 import  org.apache.cayenne.project.validator.ValidationInfo;
 import  org.apache.cayenne.project.validator.Validator;
 
 public class TableSelectorController extends CayenneController {
 
     protected TableSelectorView view;
     protected ObjectBinding tableBinding;
 
     protected DbEntity table;
     protected List<DbEntity> tables;
     protected int permanentlyExcludedCount;
     protected Map excludedTables;
     protected List<DbEntity> selectableTablesList;
 
     protected Map validationMessages;
   
 
     public TableSelectorController(ProjectController parent) {
         super(parent);
         this. = new TableSelectorView();
         this. = new HashMap();
         this. = new ArrayList();
         this. = new HashMap();
         initController();
     }
 
     // ----- properties -----
 
     public Component getView() {
         return ;
     }

    
Called by table binding script to set current table.
 
     public void setTable(DbEntity table) {
         this. = table;
     }

    
Returns DbEntities that are excluded from DB generation.
 
     public Collection getExcludedTables() {
         return .values();
     }
 
     public List getTables() {
         return ;
     }
 
     public boolean isIncluded() {
         if ( == null) {
             return false;
         }
 
         return !.containsKey(.getName());
     }
    public void setIncluded(boolean b) {
        if ( == null) {
            return;
        }
        if (b) {
            .remove(.getName());
        }
        else {
            .put(.getName(), );
        }
        tableSelectedAction();
    }

    
A callback action that updates the state of Select All checkbox.
    public void tableSelectedAction() {
        int unselectedCount = .size() - ;
        if (unselectedCount == .size()) {
            .getCheckAll().setSelected(false);
        }
        else if (unselectedCount == 0) {
            .getCheckAll().setSelected(true);
        }
    }
    public Object getProblem() {
        return ( != null) ? .get(.getName()) : null;
    }
    // ------ other stuff ------
    protected void initController() {
        BindingBuilder builder = new BindingBuilder(
                getApplication().getBindingFactory(),
                this);
        builder.bindToAction(.getCheckAll(), "checkAllAction()");
        TableBindingBuilder tableBuilder = new TableBindingBuilder(builder);
        tableBuilder.addColumn(
                "",
                "setTable(#item), included",
                Boolean.class,
                true,
                .);
        tableBuilder.addColumn(
                "Table",
                "#item.name",
                String.class,
                false,
                "XXXXXXXXXXXXXXXX");
        tableBuilder.addColumn(
                "Problems",
                "setTable(#item), problem",
                String.class,
                false,
                "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        this. = tableBuilder.bindToTable(.getTables(), "tables");
    }

    
Performs validation of DbEntities in the current DataMap. Returns a collection of ValidationInfo objects describing the problems.
    public void updateTables(DataMap dataMap) {
        this. = new ArrayList(dataMap.getDbEntities());
        .clear();
        .clear();
        // if there were errors, filter out those related to
        // non-derived DbEntities...
        // TODO: this is inefficient.. we need targeted validation
        // instead of doing it on the whole project
        Validator validator = ((ProjectControllergetParent())
                .getProject()
                .getValidator();
        int validationCode = validator.validate();
        if (validationCode >= .) {
            for (ValidationInfo nextProblem : validator.validationResults()) {
                Entity failedEntity = null;
                if (nextProblem.getValidatedObject() instanceof DbAttribute) {
                    DbAttribute failedAttribute = (DbAttribute) nextProblem
                            .getValidatedObject();
                    failedEntity = failedAttribute.getEntity();
                }
                else if (nextProblem.getValidatedObject() instanceof DbRelationship) {
                    DbRelationship failedRelationship = (DbRelationship) nextProblem
                            .getValidatedObject();
                    failedEntity = failedRelationship.getSourceEntity();
                }
                else if (nextProblem.getValidatedObject() instanceof DbEntity) {
                    failedEntity = (Entity) nextProblem.getValidatedObject();
                }
                if (failedEntity == null) {
                    continue;
                }
                .put(failedEntity.getName(), failedEntity);
                .put(failedEntity.getName(), nextProblem.getMessage());
            }
        }
        // Find selectable tables
        .clear();
        for (DbEntity table : ) {
            if (false == .containsKey(table.getName())) {
                .add(table);
            }
        }
        .updateView();
        tableSelectedAction();
    }
    public void checkAllAction() {
        boolean isCheckAllSelected = .getCheckAll().isSelected();
        if (isCheckAllSelected) {
            .clear();
            .addAll();
            .clear();
        }
        else {
            .clear();
            for (DbEntity table : ) {
                .put(table.getName(), table);
            }
            .clear();
        }
        .updateView();
    }
New to GrepCode? Check out our FAQ X