| /* |
| * 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.netbeans.modules.form; |
| |
| import org.openide.nodes.*; |
| import org.openide.util.HelpCtx; |
| import org.openide.util.actions.CookieAction; |
| |
| /** This action installs new bean into the system. |
| * |
| * @author Ian Formanek |
| */ |
| |
| public class DefaultRADAction extends CookieAction { |
| |
| /** Human presentable name of the action. This should be |
| * presented as an item in a menu. |
| * @return the name of the action |
| */ |
| @Override |
| public String getName() { |
| return "DefaultRADAction"; // NOI18N |
| } |
| |
| /** Get a help context for the action. |
| * @return the help context for this action |
| */ |
| @Override |
| public HelpCtx getHelpCtx() { |
| return new HelpCtx(DefaultRADAction.class); |
| } |
| |
| /** @return the mode of action. Possible values are disjunctions of MODE_XXX |
| * constants. */ |
| @Override |
| protected int mode() { |
| return MODE_EXACTLY_ONE; |
| } |
| |
| /** Creates new set of classes that are tested by the cookie. |
| * |
| * @return list of classes the that the cookie tests |
| */ |
| @Override |
| protected Class[] cookieClasses() { |
| return new Class[] { RADComponentCookie.class }; |
| } |
| |
| @Override |
| protected boolean asynchronous() { |
| return false; |
| } |
| |
| /** Test for enablement based on the cookies of selected nodes. |
| * Generally subclasses should not override this except for strange |
| * purposes, and then only calling the super method and adding a check. |
| * Just use {@link #cookieClasses} and {@link #mode} to specify |
| * the enablement logic. |
| * @param activatedNodes the set of activated nodes |
| * @return <code>true</code> to enable |
| */ |
| @Override |
| protected boolean enable(Node[] activatedNodes) { |
| if (activatedNodes != null && activatedNodes.length == 1) { |
| RADComponentCookie radCookie = activatedNodes[0].getCookie(RADComponentCookie.class); |
| if (radCookie != null) { |
| return radCookie.getRADComponent().getDefaultEvent() != null; |
| } |
| } |
| return false; |
| } |
| |
| /** |
| * Standard perform action extended by actually activated nodes. |
| * |
| * @param activatedNodes gives array of actually activated nodes. |
| */ |
| @Override |
| protected void performAction(Node[] activatedNodes) { |
| if (activatedNodes != null && activatedNodes.length == 1) { |
| RADComponentCookie radCookie = activatedNodes[0].getCookie(RADComponentCookie.class); |
| if (radCookie != null) { |
| radCookie.getRADComponent().attachDefaultEvent(); |
| } |
| } |
| } |
| } |