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 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.util;
 import java.util.List;
 import java.util.Set;
 import  org.apache.cayenne.access.DataDomain;
 import  org.apache.cayenne.access.DataNode;
 import  org.apache.cayenne.access.types.ExtendedTypeMap;
 import  org.apache.cayenne.reflect.PropertyUtils;
 import  org.apache.cayenne.util.CayenneMapEntry;

Various unorganized utility methods used by CayenneModeler.
 public final class ModelerUtil {

Returns the "name" property of the object.

     public static String getObjectName(Object object) {
         if (object == null) {
             return null;
         else if (object instanceof CayenneMapEntry) {
             return ((CayenneMapEntry) object).getName();
         else if (object instanceof String) {
             return (Stringobject;
         else {
             try {
                 // use reflection
                 return (String) PropertyUtils.getProperty(object"name");
             catch (Exception ex) {
                 return null;

Returns an icon, building it from an image file located at the shared resources folder for the modeler.
     public static ImageIcon buildIcon(String path) {
         ClassLoader cl = ModelerUtil.class.getClassLoader();
         URL url = cl.getResource(. + path);
         return new ImageIcon(url);

Returns array of db attribute names for DbEntity mapped to current ObjEntity.
     public static Collection<StringgetDbAttributeNames(
             ProjectController mediator,
             DbEntity entity) {
         Set<Stringkeys = entity.getAttributeMap().keySet();
         List<Stringlist = new ArrayList<String>(keys.size() + 1);
        return list;
    public static String[] getRegisteredTypeNames() {
        String[] explicitList = new ExtendedTypeMap().getRegisteredTypeNames();
        Set<StringnonPrimitives = new HashSet<String>(Arrays.asList(explicitList));
        // add types that are not mapped explicitly, but nevertheless supported by Cayenne
        String[] nonPrimitivesNames = new String[nonPrimitives.size()];
        String[] primitivesNames = {
        String[] finalList = new String[primitivesNames.length
                + nonPrimitivesNames.length
                + 1];
        finalList[0] = "";
        System.arraycopy(primitivesNames, 0, finalList, 1, primitivesNames.length);
                primitivesNames.length + 1,
        return finalList;
    public static DataNode getNodeLinkedToMap(DataDomain domain, DataMap map) {
        Collection<DataNode> nodes = domain.getDataNodes();
        // go via an iterator in an indexed loop, since
        // we already obtained the size
        // (and index is required to initialize array)
        for (DataNode node : nodes)
            if (node.getDataMaps().contains(map))
                return node;
//        Iterator nodesIt = nodes.iterator();
//        while (nodesIt.hasNext()) {
//            DataNode node = (DataNode);
//            if (node.getDataMaps().contains(map)) {
//                return node;
//            }
//        }
        return null;
Updates MultipleObjectActions' state, depending on number of selected objects (attributes, rel etc.)
    public static void updateActions(int numSelectedString... actionNames) {
        for (String actionName : actionNames) {
            CayenneAction action = Application.getInstance().getAction(actionName);
            if (action instanceof MultipleObjectsAction) {
                action.setEnabled(numSelected > 0);
                action.setName(((MultipleObjectsActionaction).getActionName(numSelected > 1));
New to GrepCode? Check out our FAQ X