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;
 
 
 import  org.apache.cayenne.project.ProjectPath;

An object that manages CayenneModeler actions.
public class ActionManager {
    static final Collection<StringSPECIAL_ACTIONS = Arrays.asList(SaveAction
            .getActionName(), UndoAction.getActionName(), RedoAction.getActionName());
    // search action added to project actions
    static final Collection<StringPROJECT_ACTIONS = Arrays.asList(RevertAction
            .getActionName(), CreateDomainAction.getActionName(), ProjectAction
            .getActionName(), ValidateAction.getActionName(), SaveAsAction
            .getActionName(), FindAction.getActionName());
    static final Collection<StringDOMAIN_ACTIONS = new HashSet<String>();
    static {
        .addAll(Arrays.asList(
                ImportDataMapAction.getActionName(),
                CreateDataMapAction.getActionName(),
                RemoveAction.getActionName(),
                CreateNodeAction.getActionName(),
                ImportDBAction.getActionName(),
                ImportEOModelAction.getActionName(),
                PasteAction.getActionName()));
    }
    
    static final Collection<StringDATA_MAP_ACTIONS = new HashSet<String>();
    static {
        .addAll(Arrays.asList(
                GenerateCodeAction.getActionName(),
                CreateEmbeddableAction.getActionName(),
                CreateObjEntityAction.getActionName(),
                CreateDbEntityAction.getActionName(),
                CreateQueryAction.getActionName(),
                CreateProcedureAction.getActionName(),
                GenerateDBAction.getActionName(),
                MigrateAction.getActionName(),
                InferRelationshipsAction.getActionName(),
                CutAction.getActionName(),
                CopyAction.getActionName()));
    }
    static final Collection<StringOBJ_ENTITY_ACTIONS = new HashSet<String>(
            );
    static {
        .addAll(Arrays.asList(
                ObjEntitySyncAction.getActionName(),
                CreateAttributeAction.getActionName(),
                CreateRelationshipAction.getActionName()));
    }
    static final Collection<StringDB_ENTITY_ACTIONS = new HashSet<String>(
            );
    static {
        .addAll(Arrays.asList(
                CreateAttributeAction.getActionName(),
                CreateRelationshipAction.getActionName(),
                DbEntitySyncAction.getActionName()));
    }
    static final Collection<StringEMBEDDABLE_ACTIONS = new HashSet<String>(
            );
    static {
        .addAll(Arrays.asList(
                CreateAttributeAction.getActionName()));
    }
    
    static final Collection<StringPROCEDURE_ACTIONS = new HashSet<String>(
            );
    static {
        .addAll(Arrays.asList(CreateProcedureParameterAction
                .getActionName()));
    }
    
    static final Collection<StringMULTIPLE_OBJECTS_ACTIONS = new HashSet<String>(
            );
    static {
        .addAll(Arrays.asList(
                RemoveAction.getActionName(),
                CutAction.getActionName(),
                CopyAction.getActionName(),
                PasteAction.getActionName()));
    }
    protected Map<StringActionactionMap;
    public ActionManager(Application application) {
        this. = new HashMap<StringAction>(40);
        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 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));
        // start callback-related actions
        registerAction(new CreateCallbackMethodAction(application)).setAlwaysOn(true);
        registerAction(new CreateCallbackMethodForListenerAction(application));
        registerAction(new RemoveCallbackMethodAction(application));
        registerAction(new RemoveCallbackMethodForListenerAction(application));
        registerAction(new CreateObjEntityListenerAction(application)).setAlwaysOn(true);
                true);
        registerAction(new RemoveEntityListenerAction(application));
        registerAction(new RemoveEntityListenerForDataMapAction(application));
        // end callback-related actions
        registerAction(new DbEntitySyncAction(application));
        registerAction(new ObjEntitySyncAction(application));
        registerAction(new ImportDBAction(application));
        registerAction(new InferRelationshipsAction(application));
        registerAction(new ImportEOModelAction(application));
        registerAction(new GenerateDBAction(application));
        registerAction(new MigrateAction(application));
        registerAction(new AboutAction(application)).setAlwaysOn(true);
        registerAction(new DocumentationAction(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);
        // search action registered
        registerAction(new FindAction(application));
        
        registerAction(new ShowLogConsoleAction(application)).setAlwaysOn(true);
        
        registerAction(new CutAction(application));
        registerAction(new CutAttributeAction(application));
        registerAction(new CutRelationshipAction(application));
        registerAction(new CutProcedureParameterAction(application));
        registerAction(new CopyAction(application));
        registerAction(new CopyAttributeAction(application));
        registerAction(new CopyRelationshipAction(application));
        registerAction(new CopyProcedureParameterAction(application));
        registerAction(new PasteAction(application));
        
        UndoAction undoAction = new UndoAction(application); 
        undoAction.setEnabled(false);
        registerAction(undoAction);
        
        RedoAction redoAction = new RedoAction(application);
        redoAction.setEnabled(false);
        registerAction(redoAction);
        
        registerAction(new CreateEmbeddableAction(application));
    }
    private CayenneAction registerAction(CayenneAction action) {
        .put(action.getKey(), action);
        return action;
    }

    
Returns an action for key.

Parameters:
key action name
Returns:
action
    public CayenneAction getAction(String key) {
        return (CayenneAction.get(key);
    }

    
Updates actions state to reflect an open project.
    public void projectOpened() {
        updateActions("");
    }
    public void projectClosed() {
        updateActions("");
    }

    
Updates actions state to reflect DataDomain selection.
    public void domainSelected() {
        updateActions("DataDomain");
    }
    public void dataNodeSelected() {
        updateActions("DataNode");
    }
    public void dataMapSelected() {
        updateActions("DataMap");
        // reset
        // getAction(CreateAttributeAction.getActionName()).setName("Create Attribute");
    }
    public void objEntitySelected() {
        updateActions("ObjEntity");
    }
    public void dbEntitySelected() {
        updateActions("DbEntity");
    }
    public void derivedDbEntitySelected() {
        updateActions("Derived DbEntity");
    }
    public void procedureSelected() {
        updateActions("Procedure");
    }
    public void querySelected() {
        updateActions("Query");
    }
    
    public void embeddableSelected() {
        updateActions("Embeddable");
    }
    
    
Invoked when several objects were selected in ProjectTree at time
    public void multipleObjectsSelected(ProjectPath[] paths) {
        
        updateActions("Selected Objects");
        
        CayenneAction cutAction = getAction(CutAction.getActionName());
        boolean canCopy = true// cut/copy can be performed if selected objects are on the same level
        
        if (!cutAction.enableForPath(paths[0])) {
            canCopy = false;
        }
        else {
            Object parent = paths[0].getObjectParent();
            
            for (int i = 1; i < paths.length; i++) {
                if (paths[i].getObjectParent() != parent || !cutAction.enableForPath(paths[i])) {
                    canCopy = false;
                    break;
                }
            }
        }
        
        cutAction.setEnabled(canCopy);
        getAction(CopyAction.getActionName()).setEnabled(canCopy);
    }
    
    
Updates Remove, Cut and Copy actions' names
    private void updateActions(String postfix) {
        if (postfix.length() > 0) {
            postfix = " " + postfix;
        }
        
        getAction(RemoveAction.getActionName()).setName("Remove" + postfix);
        getAction(CutAction.getActionName()).setName("Cut" + postfix);
        getAction(CopyAction.getActionName()).setName("Copy" + postfix);
        
        ((PasteActiongetAction(PasteAction.getActionName())).updateState();
    }

    
Sets the state of all controlled actions, flipping it to "enabled" for all actions in provided collection and to "disabled" for the rest.

Parameters:
namesOfEnabled action names
    protected void processActionsState(Collection<StringnamesOfEnabled) {
        for (Map.Entry<StringActionentry : .entrySet()) {
            if (!.contains(entry.getKey())) {
                entry.getValue().setEnabled(namesOfEnabled.contains(entry.getKey()));
            }
        }
    }
    
    
Replaces standard Cut, Copy and Paste action maps, so that accelerators like Ctrl+X, Ctrl+C, Ctrl+V would work
    public void setupCCP(JComponent compString cutNameString copyName) {
        ActionMap map = comp.getActionMap();
        
        map.put(TransferHandler.getCutAction().getValue(.), 
                getAction(cutName));
        map.put(TransferHandler.getCopyAction().getValue(.),
                getAction(copyName));
        map.put(TransferHandler.getPasteAction().getValue(.),
                getAction(PasteAction.getActionName()));
    }
New to GrepCode? Check out our FAQ X