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;
 
 import java.util.Map;
 
 
An object that manages CayenneModeler actions.

Author(s):
Andrus Adamchik
 
 public class ActionManager {
 
     static final Collection SPECIAL_ACTIONS = new HashSet(Arrays.asList(new String[] {
             SaveAction.getActionName(), RevertAction.getActionName()
     }));
 
     static final Collection PROJECT_ACTIONS = Arrays.asList(new String[] {
             CreateDomainAction.getActionName(), ProjectAction.getActionName(),
             ValidateAction.getActionName(), SaveAsAction.getActionName()
     });
 
     static final Collection DOMAIN_ACTIONS = new HashSet();
     static {
         .addAll(Arrays.asList(new String[] {
                 ImportDataMapAction.getActionName(), CreateDataMapAction.getActionName(),
                 RemoveAction.getActionName(), CreateNodeAction.getActionName(),
                 ImportDBAction.getActionName(), ImportEOModelAction.getActionName()
         }));
     }
 
     static final Collection DATA_MAP_ACTIONS = new HashSet();
     static {
         .addAll(Arrays.asList(new String[] {
                 GenerateCodeAction.getActionName(),
                 CreateObjEntityAction.getActionName(),
                 CreateDbEntityAction.getActionName(),
                CreateDerivedDbEntityAction.getActionName(),
                CreateQueryAction.getActionName(), CreateProcedureAction.getActionName(),
                GenerateDBAction.getActionName()
        }));
    }
    static final Collection OBJ_ENTITY_ACTIONS = new HashSet();
    static {
        .addAll(Arrays.asList(new String[] {
                ObjEntitySyncAction.getActionName(),
                CreateAttributeAction.getActionName(),
                CreateRelationshipAction.getActionName()
        }));
    }
    static final Collection DB_ENTITY_ACTIONS = new HashSet();
    static {
        .addAll(Arrays.asList(new String[] {
                CreateAttributeAction.getActionName(),
                CreateRelationshipAction.getActionName(),
                DbEntitySyncAction.getActionName()
        }));
    }
    static final Collection PROCEDURE_ACTIONS = new HashSet();
    static {
        .addAll(Arrays.asList(new String[] {
            CreateProcedureParameterAction.getActionName()
        }));
    }
    protected Map actionMap;
    public ActionManager(Application application) {
        this. = new HashMap();
        registerAction(new ProjectAction(application));
        registerAction(new NewProjectAction(application)).setAlwaysOn(true);
        registerAction(new OpenProjectAction(application)).setAlwaysOn(true);
        registerAction(new ImportDataMapAction(application));
        registerAction(new SaveAction(application));
        registerAction(new SaveAsAction(application));
        registerAction(new RevertAction(application));
        registerAction(new ValidateAction(application));
        registerAction(new RemoveAction(application));
        registerAction(new CreateDomainAction(application));
        registerAction(new CreateNodeAction(application));
        registerAction(new CreateDataMapAction(application));
        registerAction(new GenerateCodeAction(application));
        registerAction(new CreateObjEntityAction(application));
        registerAction(new CreateDbEntityAction(application));
        registerAction(new CreateDerivedDbEntityAction(application));
        registerAction(new CreateProcedureAction(application));
        registerAction(new CreateProcedureParameterAction(application));
        registerAction(new RemoveProcedureParameterAction(application));
        registerAction(new CreateQueryAction(application));
        registerAction(new CreateAttributeAction(application));
        registerAction(new RemoveAttributeAction(application));
        registerAction(new CreateRelationshipAction(application));
        registerAction(new RemoveRelationshipAction(application));
        registerAction(new DbEntitySyncAction(application));
        registerAction(new ObjEntitySyncAction(application));
        registerAction(new DerivedEntitySyncAction(application));
        registerAction(new ImportDBAction(application));
        registerAction(new ImportEOModelAction(application));
        registerAction(new GenerateDBAction(application));
        registerAction(new AboutAction(application)).setAlwaysOn(true);
        registerAction(new ConfigurePreferencesAction(application)).setAlwaysOn(true);
        registerAction(new ExitAction(application)).setAlwaysOn(true);
        registerAction(new NavigateBackwardAction(application)).setAlwaysOn(true);
        registerAction(new NavigateForwardAction(application)).setAlwaysOn(true);
    }
    private CayenneAction registerAction(CayenneAction action) {
        .put(action.getKey(), action);
        return action;
    }

    
Returns an action for key.
    public CayenneAction getAction(String key) {
        return (CayenneAction.get(key);
    }

    
Updates actions state to reflect an open project.
    public void projectOpened() {
        getAction(RemoveAction.getActionName()).setName("Remove");
    }
    public void projectClosed() {
        getAction(RemoveAction.getActionName()).setName("Remove");
    }

    
Updates actions state to reflect DataDomain selecttion.
    public void domainSelected() {
    }
    public void dataNodeSelected() {
        getAction(RemoveAction.getActionName()).setName("Remove DataNode");
    }
    public void dataMapSelected() {
        getAction(RemoveAction.getActionName()).setName("Remove DataMap");
        // reset
        // getAction(CreateAttributeAction.getActionName()).setName("Create Attribute");
    }
    public void objEntitySelected() {
        getAction(RemoveAction.getActionName()).setName("Remove ObjEntity");
    }
    public void dbEntitySelected() {
        getAction(RemoveAction.getActionName()).setName("Remove DbEntity");
    }
    
    public void derivedDbEntitySelected() {
        getAction(RemoveAction.getActionName()).setName("Remove Derived DbEntity");
    }
    public void procedureSelected() {
        getAction(RemoveAction.getActionName()).setName("Remove Procedure");
    }
    public void querySelected() {
        getAction(RemoveAction.getActionName()).setName("Remove Query");
    }

    
Sets the state of all controlled actions, flipping it to "enabled" for all actions in provided collection and to "disabled" for the rest.
    protected void processActionsState(Collection namesOfEnabled) {
        Iterator it = .entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entryit.next();
            if (!.contains(entry.getKey())) {
                ((Actionentry.getValue()).setEnabled(namesOfEnabled.contains(entry
                        .getKey()));
            }
        }
    }
New to GrepCode? Check out our FAQ X