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;
 
 import java.awt.Color;
 import java.util.Map;
 
 
 import  org.apache.cayenne.map.DbEntity;
 import  org.apache.cayenne.map.Embeddable;
 import  org.apache.cayenne.map.ObjAttribute;
 import  org.apache.cayenne.map.ObjEntity;
 import  org.apache.cayenne.map.ObjRelationship;
 import  org.apache.cayenne.query.SelectQuery;
Swing component displaying results produced by search feature.
 
 public class FindDialogView extends JDialog {
 
     private JButton okButton;
     private static JScrollPane scrollPane;
     private JTable table;
     private static Map LabelAndObjectIndex;
 
     public static Map getLabelAndObjectIndex() {
         return ;
     }
 
     public JTable getTable() {
         return ;
     }
 
     public FindDialogView(Map objEntityNamesMap dbEntityNamesMap attrNames,
             Map relatNamesMap queryNamesMap embeddableNamesMap embeddableAttributeNames) {
 
         JPanel panel = new JPanel();
         panel.setLayout(new BoxLayout(panel.));
 
         if (objEntityNames.isEmpty()
                 && dbEntityNames.isEmpty()
                 && attrNames.isEmpty()
                 && relatNames.isEmpty()
                 && queryNames.isEmpty()
                 && embeddableNames.isEmpty()
                 && embeddableAttributeNames.isEmpty()) {
             panel.add(new JLabel("Nothing found!"));
         }
         else {
 
             int curentLineInTable = 0;
             int sizeDataVector = objEntityNames.size()
                     + dbEntityNames.size()
                     + attrNames.size()
                    + relatNames.size()
                    + queryNames.size()
                    + embeddableNames.size()
                    + embeddableAttributeNames.size();
            Object[][] dataVector = new Object[sizeDataVector][];
            TableModel tableModel = new TableModel();
             = new HashMap<JLabelInteger>();
            dataVector = createResultTable(objEntityNames, CellRenderers
                    .iconForObject(new ObjEntity()), dataVectorcurentLineInTable);
            
            curentLineInTable = objEntityNames.size();            
            dataVector = createResultTable(embeddableNames, CellRenderers
                    .iconForObject(new Embeddable()), dataVectorcurentLineInTable);
            curentLineInTable = curentLineInTable + embeddableNames.size();            
            dataVector = createResultTable(dbEntityNames, CellRenderers
                    .iconForObject(new DbEntity()), dataVectorcurentLineInTable);
            
            curentLineInTable = curentLineInTable + dbEntityNames.size();            
            dataVector = createResultTable(attrNames, CellRenderers
                    .iconForObject(new ObjAttribute()), dataVectorcurentLineInTable);
            
            curentLineInTable = curentLineInTable + attrNames.size();         
            dataVector = createResultTable(embeddableAttributeNames, CellRenderers
                    .iconForObject(new ObjAttribute()), dataVectorcurentLineInTable);
            curentLineInTable = curentLineInTable + embeddableAttributeNames.size();
            dataVector = createResultTable(relatNames, CellRenderers
                    .iconForObject(new ObjRelationship()), dataVectorcurentLineInTable);
            
            curentLineInTable = curentLineInTable + relatNames.size();
            dataVector = createResultTable(queryNames, CellRenderers
                    .iconForObject(new SelectQuery()), dataVectorcurentLineInTable);
            
            tableModel.setDataVector(dataVectornew Object[] {
                ""
            });
             = new JTable(tableModel);
            InputMap im = 
                    .getInputMap(.);
            InputMap imParent = im.getParent();
            imParent.remove(KeyStroke.getKeyStroke(., 0));
            im.setParent(imParent);
            im.remove(KeyStroke.getKeyStroke(., 0));
        }
        JPanel okPanel = new JPanel(new FlowLayout(.));
         = new JButton("OK");
        okPanel.add();
        JComponent contentPane = (JComponentgetContentPane();
        contentPane.setLayout(new BorderLayout());
         = new JScrollPane// panel
                ,
                .,
                .);
        contentPane.add();
        contentPane.add(okPanel.);
        contentPane.setPreferredSize(new Dimension(400, 325));
        setTitle("Search results");
    }
    private Object[][] createResultTable(
            Map names,
            Icon icon,
            Object[][] dataVector,
            int curentLineInTable) {
        Comparator<Stringcomparer = new Comparator<String>() {
            public int compare(String o1String o2) {
                return o1.compareTo(o2);
            }
        };
        Map sortedByNameMap = sortMapByValue(namescomparer);
        Iterator it = sortedByNameMap.keySet().iterator();
        Object[] objectHelper = new Object[] {};
        while (it.hasNext()) {
            Integer index = (Integerit.next();
            JLabel labelIcon = new JLabel();
            labelIcon.setIcon(icon);
            labelIcon.setVisible(true);
            labelIcon.setText((StringsortedByNameMap.get(index));
            objectHelper = new Object[] {
                labelIcon
            };
            dataVector[curentLineInTable] = objectHelper;
            .put(labelIconindex);
            curentLineInTable++;
        }
        return dataVector;
    }
    public JButton getOkButton() {
        return ;
    }
    public <K, V> Map<K, V> sortMapByValue(Map<K, V> inComparator<? super V> compare) {
        Map<V, K> swapped = new TreeMap<V, K>(compare);
        for (Entry<K, V> entry : in.entrySet()) {
            if (entry.getValue() != null) {
                swapped.put(entry.getValue(), entry.getKey());
            }
        }
        LinkedHashMap<K, V> result = new LinkedHashMap<K, V>();
        for (Entry<V, K> entry : swapped.entrySet()) {
            if (entry.getValue() != null) {
                result.put(entry.getValue(), entry.getKey());
            }
        }
        return result;
    }
    public boolean isCellEditable(int rowint col) {
        return false;
    }
New to GrepCode? Check out our FAQ X