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.Set;
 
 
 import  org.apache.cayenne.merge.MergeDirection;
 import  org.apache.cayenne.merge.MergerFactory;
 import  org.apache.cayenne.merge.MergerToken;
 
 
     protected MergerTokenSelectorView view;
     protected ObjectBinding tableBinding;
 
     protected MergerToken token;
     protected int permanentlyExcludedCount;
     protected Set<MergerToken> excludedTokens;
     protected List<MergerToken> selectableTokensList;
     protected MergerFactory mergerFactory;
 
         super(parent);
         this. = new MergerTokenSelectorView();
         this. = new HashSet<MergerToken>();
         this. = new ArrayList<MergerToken>();
         initController();
     }
 
     public void setMergerFactory(MergerFactory mergerFactory) {
         this. = mergerFactory;
     }
 
     public void setTokens(List<MergerToken> tokens) {
         .clear();
         .addAll(tokens);
         .addAll(tokens);
     }
 
     public List<MergerToken> getSelectedTokens() {
         List<MergerToken> t = new ArrayList<MergerToken>();
         t.removeAll();
         return Collections.unmodifiableList(t);
     }
 
     public List<MergerToken> getSelectableTokens() {
         return Collections.unmodifiableList();
     }
     
     public void removeToken(MergerToken token) {
         .remove(token);
         .remove(token);
 
         AbstractTableModel model = (AbstractTableModel.getTokens().getModel();
         model.fireTableDataChanged();
     }
 
     // ----- properties -----
 
     public Component getView() {
         return ;
     }

    
Called by table binding script to set current token.
 
     public void setToken(MergerToken token) {
        this. = token;
    }

    
Returns MergerTokens that are excluded from DB generation.
    /*
     * public Collection getExcludedTokens() { return excludedTokens; }
     */
    public boolean isIncluded() {
        if ( == null) {
            return false;
        }
        return !.contains();
    }
    public void setIncluded(boolean b) {
        if ( == null) {
            return;
        }
        if (b) {
            .remove();
        }
        else {
            .add();
        }
        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);
        }
    }
    // ------ other stuff ------
    protected void initController() {
        BindingBuilder builder = new BindingBuilder(
                getApplication().getBindingFactory(),
                this);
        builder.bindToAction(.getCheckAll(), "checkAllAction()");
        builder.bindToAction(.getReverseAll(), "reverseAllAction()");
        TableModel model = new MergerTokenTableModel(this);
        MergeDirection[] dirs = new MergeDirection[] {
                MergeDirection.TO_DB, MergeDirection.TO_MODEL
        };
        .getTokens().setModel(model);
        TableColumnModel columnModel = .getTokens().getColumnModel();
        
        // dropdown for direction column
        JComboBox directionCombo = CayenneWidgetFactory.createComboBox(dirsfalse);
        directionCombo.setEditable(false);
        TableColumn directionColumn = columnModel.getColumn(
                .);
        directionColumn.setCellEditor(new DefaultCellEditor(directionCombo));
        
        // TODO: correct width for the different columns
        //view.getTokens().setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        columnModel.getColumn(.).setMaxWidth(50);
        columnModel.getColumn(.).setMaxWidth(100);
    }
    public boolean isSelected(MergerToken token) {
        return (.contains(token) && !.contains(token));
    }
    public void select(MergerToken tokenboolean select) {
        if (select) {
            .remove(token);
        }
        else {
            .add(token);
        }
    }
    public void setDirection(MergerToken token, MergeDirection direction) {
        if (token.getDirection().equals(direction)) {
            return;
        }
        int i = .indexOf(token);
        MergerToken reverse = token.createReverse();
        .set(ireverse);
        if (.remove(token)) {
            .add(reverse);
        }
        
        
Repaint, so that "Operation" column updates properly
        .getTokens().repaint();
    }
    public void checkAllAction() {
        boolean isCheckAllSelected = .getCheckAll().isSelected();
        if (isCheckAllSelected) {
            .clear();
        }
        else {
            .addAll();
        }
        model.fireTableDataChanged();
    }
    public void reverseAllAction() {
        
        for (int i = 0; i < .size(); i++) {
            MergerToken token = .get(i);
            MergerToken reverse = token.createReverse();
            .set(ireverse);
            if (.remove(token)) {
                .add(reverse);
            }
        }
        model.fireTableDataChanged();
    }
New to GrepCode? Check out our FAQ X