Search in sources :

Example 1 with DataMapDefaults

use of org.apache.cayenne.modeler.pref.DataMapDefaults in project cayenne by apache.

the class DataMapView method setDataMapName.

void setDataMapName(String newName) {
    if (newName == null || newName.trim().length() == 0) {
        throw new ValidationException("Enter name for DataMap");
    }
    DataMap map = eventController.getCurrentDataMap();
    // search for matching map name across domains, as currently they have to be
    // unique globally
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
    DataMap matchingMap = dataChannelDescriptor.getDataMap(newName);
    if (matchingMap != null && !matchingMap.equals(map)) {
        // there is an entity with the same name
        throw new ValidationException("There is another DataMap named '" + newName + "'. Use a different name.");
    }
    String oldName = map.getName();
    if (Util.nullSafeEquals(newName, oldName)) {
        return;
    }
    // completely new name, set new name for domain
    DataMapDefaults pref = eventController.getDataMapPreferences("");
    DataMapEvent e = new DataMapEvent(this, map, map.getName());
    ProjectUtil.setDataMapName((DataChannelDescriptor) eventController.getProject().getRootNode(), map, newName);
    pref.copyPreferences(newName);
    eventController.fireDataMapEvent(e);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 2 with DataMapDefaults

use of org.apache.cayenne.modeler.pref.DataMapDefaults in project cayenne by apache.

the class ProjectController method getDataMapPreferences.

/**
 * Returns preferences object for the current DataMap. If no preferences
 * exist for the current DataMap, a new Preferences object is created. If no
 * DataMap is currently selected, an exception is thrown. An optional
 * nameSuffix allows to address more than one defaults instance for a single
 * DataMap.
 */
public DataMapDefaults getDataMapPreferences(String nameSuffix) {
    DataMap map = getCurrentDataMap();
    if (map == null) {
        throw new CayenneRuntimeException("No DataMap selected");
    }
    Preferences pref;
    if (nameSuffix == null || nameSuffix.length() == 0) {
        pref = getPreferenceForDataDomain().node("DataMap").node(map.getName());
    } else {
        pref = getPreferenceForDataDomain().node("DataMap").node(map.getName()).node(nameSuffix);
    }
    return (DataMapDefaults) application.getCayenneProjectPreferences().getProjectDetailObject(DataMapDefaults.class, pref);
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) ProjectStatePreferences(org.apache.cayenne.modeler.pref.ProjectStatePreferences) Preferences(java.util.prefs.Preferences) DataMap(org.apache.cayenne.map.DataMap)

Example 3 with DataMapDefaults

use of org.apache.cayenne.modeler.pref.DataMapDefaults in project cayenne by apache.

the class ProjectController method getDataMapPreferences.

public DataMapDefaults getDataMapPreferences(DataMap dataMap) {
    Preferences pref;
    pref = getPreferenceForDataDomain().node("DataMap").node(dataMap.getName());
    return (DataMapDefaults) application.getCayenneProjectPreferences().getProjectDetailObject(DataMapDefaults.class, pref);
}
Also used : DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) ProjectStatePreferences(org.apache.cayenne.modeler.pref.ProjectStatePreferences) Preferences(java.util.prefs.Preferences)

Example 4 with DataMapDefaults

use of org.apache.cayenne.modeler.pref.DataMapDefaults in project cayenne by apache.

the class StandardModeController method createDefaults.

protected void createDefaults() {
    TreeMap<DataMap, DataMapDefaults> treeMap = new TreeMap<DataMap, DataMapDefaults>();
    ArrayList<DataMap> dataMaps = (ArrayList<DataMap>) getParentController().getDataMaps();
    for (DataMap dataMap : dataMaps) {
        DataMapDefaults preferences = getApplication().getFrameController().getProjectController().getDataMapPreferences(dataMap);
        preferences.setSuperclassPackage("");
        preferences.updateSuperclassPackage(dataMap, false);
        treeMap.put(dataMap, preferences);
        if (getOutputPath() == null) {
            setOutputPath(preferences.getOutputPath());
        }
    }
    setMapPreferences(treeMap);
}
Also used : ArrayList(java.util.ArrayList) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) TreeMap(java.util.TreeMap) DataMap(org.apache.cayenne.map.DataMap)

Example 5 with DataMapDefaults

use of org.apache.cayenne.modeler.pref.DataMapDefaults in project cayenne by apache.

the class ClientModeController method createView.

protected GeneratorControllerPanel createView() {
    this.view = new StandardModePanel();
    Set<Entry<DataMap, DataMapDefaults>> entities = getMapPreferences().entrySet();
    for (Entry<DataMap, DataMapDefaults> entry : entities) {
        StandardPanelComponent dataMapLine = createDataMapLineBy(entry.getKey(), entry.getValue());
        dataMapLine.getDataMapName().setText(dataMapLine.getDataMap().getName());
        BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), dataMapLine);
        builder.bindToTextField(dataMapLine.getSuperclassPackage(), "preferences.superclassPackage").updateView();
        this.view.addDataMapLine(dataMapLine);
    }
    return view;
}
Also used : Entry(java.util.Map.Entry) BindingBuilder(org.apache.cayenne.swing.BindingBuilder) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

DataMapDefaults (org.apache.cayenne.modeler.pref.DataMapDefaults)9 DataMap (org.apache.cayenne.map.DataMap)8 Entry (java.util.Map.Entry)3 TreeMap (java.util.TreeMap)3 BindingBuilder (org.apache.cayenne.swing.BindingBuilder)3 ArrayList (java.util.ArrayList)2 Preferences (java.util.prefs.Preferences)2 ProjectStatePreferences (org.apache.cayenne.modeler.pref.ProjectStatePreferences)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)1 ValidationException (org.apache.cayenne.validation.ValidationException)1