001 /*
002 * Copyright 2010-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.codehaus.griffon.runtime.core.controller;
018
019 import griffon.core.GriffonController;
020 import griffon.core.controller.GriffonControllerAction;
021 import org.codehaus.griffon.runtime.core.AbstractObservable;
022
023 import java.lang.ref.WeakReference;
024
025 /**
026 * @author Andres Almiray
027 * @since 1.1.0
028 */
029 public abstract class AbstractGriffonControllerAction extends AbstractObservable implements GriffonControllerAction {
030 private String name;
031 private String shortDescription;
032 private String longDescription;
033 private String smallIcon;
034 private String largeIcon;
035 private String accelerator;
036 private String mnemonic;
037 private boolean enabled;
038 private boolean selected;
039 private WeakReference<GriffonController> controller;
040
041 public AbstractGriffonControllerAction(GriffonController controller, String actionName) {
042 this.controller = new WeakReference<GriffonController>(controller);
043 }
044
045 public GriffonController getController() {
046 return controller.get();
047 }
048
049 public String getAccelerator() {
050 return accelerator;
051 }
052
053 @Override
054 public void setAccelerator(String accelerator) {
055 firePropertyChange(KEY_ACCELERATOR, this.accelerator, this.accelerator = accelerator);
056 }
057
058 public boolean isEnabled() {
059 return enabled;
060 }
061
062 @Override
063 public void setEnabled(boolean enabled) {
064 firePropertyChange(KEY_ENABLED, this.enabled, this.enabled = enabled);
065 }
066
067 public String getLargeIcon() {
068 return largeIcon;
069 }
070
071 @Override
072 public void setLargeIcon(String largeIcon) {
073 firePropertyChange(KEY_LARGE_ICON, this.largeIcon, this.largeIcon = largeIcon);
074 }
075
076 public String getLongDescription() {
077 return longDescription;
078 }
079
080 @Override
081 public void setLongDescription(String longDescription) {
082 firePropertyChange(KEY_LONG_DESCRIPTION, this.longDescription, this.longDescription = longDescription);
083 }
084
085 public String getMnemonic() {
086 return mnemonic;
087 }
088
089 @Override
090 public void setMnemonic(String mnemonic) {
091 firePropertyChange(KEY_MNEMONIC, this.mnemonic, this.mnemonic = mnemonic);
092 }
093
094 public String getName() {
095 return name;
096 }
097
098 @Override
099 public void setName(String name) {
100 firePropertyChange(KEY_NAME, this.name, this.name = name);
101 }
102
103 public boolean isSelected() {
104 return selected;
105 }
106
107 @Override
108 public void setSelected(boolean selected) {
109 firePropertyChange(KEY_SELECTED, this.selected, this.selected = selected);
110 }
111
112 public String getShortDescription() {
113 return shortDescription;
114 }
115
116 @Override
117 public void setShortDescription(String shortDescription) {
118 firePropertyChange(KEY_SHORT_DESCRIPTION, this.shortDescription, this.shortDescription = shortDescription);
119 }
120
121 public String getSmallIcon() {
122 return smallIcon;
123 }
124
125 @Override
126 public void setSmallIcon(String smallIcon) {
127 firePropertyChange(KEY_SMALL_ICON, this.smallIcon, this.smallIcon = smallIcon);
128 }
129
130 @Override
131 public final void execute(Object... args) {
132 if (isEnabled()) {
133 doExecute(args);
134 }
135 }
136
137 protected abstract void doExecute(Object[] args);
138 }
|