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 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.util;
Superclass of CayenneModeler actions that implements support for some common functionality, exception handling, etc.

Andrei Adamchik
 public abstract class CayenneAction extends AbstractAction {
     protected boolean alwaysOn;
     protected Application application;

Creates a named CayenneAction.
     public CayenneAction(String nameApplication application) {

Creates a named CayenneAction.
     public CayenneAction(String nameApplication applicationString shortDescription) {
         this. = application;
         Icon icon = createIcon();
         if (icon != null) {
         KeyStroke accelerator = getAcceleratorKey();
         if (accelerator != null) {
         if (shortDescription != null && shortDescription.length() > 0) {
     public Application getApplication() {
         return ;
     protected Project getCurrentProject() {

Changes the name of this action, propagating the change to all widgets using this action.
     public void setName(String newName) {
         if (!Util.nullSafeEquals(getValue(.), newName)) {

Returns keyboard shortcut for this action. Default implementation returns null.
    public KeyStroke getAcceleratorKey() {
        return null;

Returns the name of the icon that should be used for buttons. Name will be reolved relative to RESOURCE_PATH. Default implementation returns null.
    public String getIconName() {
        return null;

Creates and returns an ImageIcon that can be used for buttons that rely on this action. Returns null if getIconName returns null.
    public Icon createIcon() {
        String name = getIconName();
        return (name != null) ? ModelerUtil.buildIcon(name) : null;

Returns the key under which this action should be stored in the ActionMap.
    public String getKey() {
        return (Stringsuper.getValue(.);

Subclasses must implement this method instead of actionPerformed to allow for exception handling.
    public abstract void performAction(ActionEvent e);

Returns true if the action is enabled for the specified "project path" - a path on the project tree to a currently selected object. Default implementation simply returns false.
    public boolean enableForPath(ProjectPath obj) {
        return false;

Returns current project controller.

Internally calls performAction. Traps exceptions that ocurred during action processing.
    public void actionPerformed(ActionEvent e) {
        try {
        catch (Throwable th) {

Factory method that creates a menu item hooked up to this action.
    public JMenuItem buildMenu() {
        return new JMenuItem(this);

Factory method that creates a button hooked up to this action.
    public JButton buildButton() {
        return new CayenneToolbarButton(this);

Returns true if this action is always enabled.

    public boolean isAlwaysOn() {
        return ;

Sets the alwaysOn.

alwaysOn The alwaysOn to set
    public void setAlwaysOn(boolean alwaysOn) {
        this. = alwaysOn;
        if (alwaysOn) {

Overrides super implementation to take into account "alwaysOn" flag.
    public void setEnabled(boolean b) {
        if (!isAlwaysOn()) {

On changes in action text, will update toolbar tip instead.
    final class CayenneToolbarButton extends JButton {
        protected boolean showingText;

Constructor for CayenneMenuItem.
        public CayenneToolbarButton(Action a) {

Returns the showingText.
        public boolean isShowingText() {
            return ;

Sets the showingText.
        public void setShowingText(boolean showingText) {
            this. = showingText;

        public String getText() {
            return () ? super.getText() : null;

        public void setText(String text) {
            if () {
            else {
New to GrepCode? Check out our FAQ X