Search in sources :

Example 1 with ConfigurationNodeParentGetter

use of org.apache.cayenne.project.ConfigurationNodeParentGetter in project cayenne by apache.

the class DefaultActionManager method multipleObjectsSelected.

/**
 * Invoked when several objects were selected in ProjectTree at time
 */
public void multipleObjectsSelected(ConfigurationNode[] objects, Application application) {
    processActionsState(MULTIPLE_OBJECTS_ACTIONS);
    updateActions("Selected Objects");
    CayenneAction cutAction = getAction(CutAction.class);
    // cut/copy can be performed if selected objects are on
    boolean canCopy = true;
    if (!cutAction.enableForPath(objects[0])) {
        canCopy = false;
    } else {
        ConfigurationNodeParentGetter parentGetter = application.getInjector().getInstance(ConfigurationNodeParentGetter.class);
        Object parent = parentGetter.getParent(objects[0]);
        for (int i = 1; i < objects.length; i++) {
            if (parentGetter.getParent(objects[i]) != parent || !cutAction.enableForPath(objects[i])) {
                canCopy = false;
                break;
            }
        }
    }
    cutAction.setEnabled(canCopy);
    getAction(CopyAction.class).setEnabled(canCopy);
}
Also used : ConfigurationNodeParentGetter(org.apache.cayenne.project.ConfigurationNodeParentGetter) CayenneAction(org.apache.cayenne.modeler.util.CayenneAction)

Example 2 with ConfigurationNodeParentGetter

use of org.apache.cayenne.project.ConfigurationNodeParentGetter in project cayenne by apache.

the class ProjectController method getCurrentObject.

/**
 * Returns currently selected object, null if there are none, List if there
 * are several
 */
public Object getCurrentObject() {
    if (getCurrentObjEntity() != null) {
        return getCurrentObjEntity();
    } else if (getCurrentDbEntity() != null) {
        return getCurrentDbEntity();
    } else if (getCurrentEmbeddable() != null) {
        return getCurrentEmbeddable();
    } else if (getCurrentQuery() != null) {
        return getCurrentQuery();
    } else if (getCurrentProcedure() != null) {
        return getCurrentProcedure();
    } else if (getCurrentDataMap() != null) {
        return getCurrentDataMap();
    } else if (getCurrentDataNode() != null) {
        return getCurrentDataNode();
    } else if (getCurrentDataChanel() != null) {
        return getCurrentDataChanel();
    } else if (getCurrentPaths() != null) {
        // multiple objects
        ConfigurationNode[] paths = getCurrentPaths();
        ConfigurationNodeParentGetter parentGetter = getApplication().getInjector().getInstance(ConfigurationNodeParentGetter.class);
        Object parent = parentGetter.getParent(paths[0]);
        List<ConfigurationNode> result = new ArrayList<>();
        result.addAll(Arrays.asList(paths));
        /*
             * Here we sort the list of objects to minimize the risk that
             * objects will be pasted incorrectly. For instance, ObjEntity
             * should go before Query, to increase chances that Query's root
             * would be set.
             */
        Collections.sort(result, parent instanceof DataMap ? Comparators.getDataMapChildrenComparator() : Comparators.getDataDomainChildrenComparator());
        return result;
    }
    return null;
}
Also used : ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) ArrayList(java.util.ArrayList) ConfigurationNodeParentGetter(org.apache.cayenne.project.ConfigurationNodeParentGetter) EventObject(java.util.EventObject) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

ConfigurationNodeParentGetter (org.apache.cayenne.project.ConfigurationNodeParentGetter)2 ArrayList (java.util.ArrayList)1 EventObject (java.util.EventObject)1 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DataMap (org.apache.cayenne.map.DataMap)1 CayenneAction (org.apache.cayenne.modeler.util.CayenneAction)1