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);
}
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;
}
Aggregations