Source Code Cross Referenced for ActionsSupport.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » modules » vmd » api » model » presenters » actions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » vmd.analyzer » org.netbeans.modules.vmd.api.model.presenters.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.vmd.api.model.presenters.actions;
043:
044:        import java.awt.event.ActionEvent;
045:        import java.util.ArrayList;
046:        import java.util.Arrays;
047:        import java.util.Collection;
048:        import java.util.HashSet;
049:        import java.util.List;
050:        import java.util.Map;
051:        import java.util.Set;
052:        import java.util.TreeMap;
053:
054:        import javax.swing.AbstractAction;
055:        import javax.swing.Action;
056:
057:        import org.netbeans.modules.vmd.api.model.DescriptorRegistry;
058:        import org.netbeans.modules.vmd.api.model.DesignComponent;
059:        import org.netbeans.modules.vmd.api.model.DesignDocument;
060:        import org.netbeans.modules.vmd.api.model.Presenter;
061:        import org.netbeans.modules.vmd.api.model.TypeID;
062:        import org.netbeans.modules.vmd.model.actions.ActionsPresenterForwarder;
063:
064:        /**
065:         *
066:         * @author Karol Harezlak
067:         */
068:        public final class ActionsSupport {
069:
070:            static final String SEPERATOR_KEY = "#SEPARATOR#"; //NOI18N
071:            static final Set<Action> actionsToDelete = new HashSet<Action>();
072:
073:            private static final TypeID[] EMPTY_TYPEID_ARRAY = new TypeID[0];
074:
075:            public static synchronized Action[] createAddActionArray(
076:                    final DesignComponent component) {
077:                return createAddActionArray(component, EMPTY_TYPEID_ARRAY);
078:            }
079:
080:            public static synchronized Action[] createAddActionArray(
081:                    final DesignComponent component,
082:                    final TypeID... filtersTypeID) {
083:                final List<Action> actions = new ArrayList<Action>();
084:
085:                component.getDocument().getTransactionManager().readAccess(
086:                        new Runnable() {
087:                            public void run() {
088:                                if (!component.getPresenters(
089:                                        AddActionPresenter.class).isEmpty()) {
090:                                    Map<Integer, Map<String, List<Action>>> sortedMaps = new TreeMap<Integer, Map<String, List<Action>>>();
091:                                    DescriptorRegistry registry = component
092:                                            .getDocument()
093:                                            .getDescriptorRegistry();
094:
095:                                    //Sorting presenters by the order and name of the AddActionPresenter
096:                                    for (AddActionPresenter presenter : component
097:                                            .getPresenters(AddActionPresenter.class)) {
098:                                        AddActionItem[] addActionItems = presenter
099:                                                .getAddActionItems();
100:                                        if (addActionItems == null
101:                                                || addActionItems.length < 1)
102:                                            continue;
103:
104:                                        Integer order = presenter.getOrder() == null ? Integer.MAX_VALUE
105:                                                : presenter.getOrder();
106:
107:                                        if (sortedMaps.get(order) == null) {
108:                                            sortedMaps
109:                                                    .put(
110:                                                            order,
111:                                                            new TreeMap<String, List<Action>>());
112:                                            sortedMaps
113:                                                    .get(order)
114:                                                    .put(
115:                                                            presenter.getName(),
116:                                                            new ArrayList<Action>(
117:                                                                    Arrays
118:                                                                            .asList(addActionItems)));
119:                                        } else if (sortedMaps.get(order) != null
120:                                                && sortedMaps.get(order).get(
121:                                                        presenter.getName()) == null) {
122:                                            sortedMaps
123:                                                    .get(order)
124:                                                    .put(
125:                                                            presenter.getName(),
126:                                                            new ArrayList<Action>(
127:                                                                    Arrays
128:                                                                            .asList(addActionItems)));
129:                                        } else
130:                                            sortedMaps
131:                                                    .get(order)
132:                                                    .get(presenter.getName())
133:                                                    .addAll(
134:                                                            Arrays
135:                                                                    .asList(addActionItems));
136:                                    }
137:                                    // Creating of list of AddActionPresenter action list with separators and filtring it is necessary
138:                                    for (Map<String, List<Action>> sortedMap : sortedMaps
139:                                            .values()) {
140:                                        for (String name : sortedMap.keySet()) {
141:                                            if (filtersTypeID.length == 0) {
142:                                                if (name != null)
143:                                                    actions
144:                                                            .add(new SeperatorAction(
145:                                                                    name));
146:                                                actions.addAll(sortedMap
147:                                                        .get(name));
148:                                            } else {
149:                                                boolean removeCategory = true;
150:                                                if (name != null)
151:                                                    actions
152:                                                            .add(new SeperatorAction(
153:                                                                    name));
154:                                                for (Action action : sortedMap
155:                                                        .get(name)) {
156:                                                    for (TypeID typeID : filtersTypeID) {
157:                                                        TypeID actionTypeID = (TypeID) action
158:                                                                .getValue(AddActionItem.TYPEID_KEY);
159:                                                        if (registry
160:                                                                .isInHierarchy(
161:                                                                        typeID,
162:                                                                        actionTypeID)) {
163:                                                            actions.add(action);
164:                                                            removeCategory = false;
165:                                                        }
166:                                                    }
167:                                                }
168:                                                if (name != null
169:                                                        && removeCategory)
170:                                                    actions.remove(actions
171:                                                            .size() - 1);
172:                                            }
173:                                        }
174:                                    }
175:                                }
176:                            }
177:                        });
178:
179:                return actions.toArray(new Action[actions.size()]);
180:            }
181:
182:            public static synchronized Action[] createActionsArray(
183:                    final DesignComponent component) {
184:                final List<Action> actions = new ArrayList<Action>();
185:
186:                component.getDocument().getTransactionManager().readAccess(
187:                        new Runnable() {
188:                            public void run() {
189:                                Map<Integer, List<Action>> sortedLists = new TreeMap<Integer, List<Action>>();
190:
191:                                DesignDocument document = null;
192:                                Collection<? extends ActionsPresenter> presenters = component
193:                                        .getPresenters(ActionsPresenter.class);
194:                                if (presenters == null)
195:                                    return;
196:                                for (ActionsPresenter presenter : presenters) {
197:                                    List<Action> actions = presenter
198:                                            .getActions();
199:                                    if (actions == null || actions.isEmpty())
200:                                        continue;
201:
202:                                    DesignComponent relatedComponent = presenter
203:                                            .getRelatedComponent();
204:                                    assert relatedComponent != null : "No related component for ActionsPresenter "
205:                                            + presenter;//NOI18N
206:                                    for (Action action : actions) {
207:                                        if (action instanceof  ActionContext)
208:                                            ((ActionContext) action)
209:                                                    .setComponent(relatedComponent);
210:                                    }
211:
212:                                    if (document != null)
213:                                        assert document == relatedComponent
214:                                                .getDocument();
215:                                    else
216:                                        document = relatedComponent
217:                                                .getDocument();
218:
219:                                    Integer order = presenter.getOrder();
220:                                    if (order == null)
221:                                        order = Integer.MAX_VALUE;
222:
223:                                    List<Action> list = sortedLists.get(order);
224:                                    if (list == null)
225:                                        sortedLists.put(order,
226:                                                new ArrayList<Action>(actions));
227:                                    else
228:                                        list.addAll(actions);
229:                                }
230:                                for (List<Action> list : sortedLists.values()) {
231:                                    for (Action action : list) {
232:                                        actions.add(action);
233:                                    }
234:                                    actions.add(null);
235:                                }
236:                            }
237:                        });
238:
239:                return actions.toArray(new Action[actions.size()]);
240:            }
241:
242:            public static synchronized Collection<Presenter> createByReference(
243:                    final String referencePropertyName,
244:                    Class... actionsToInherit) {
245:                HashSet presenters = new HashSet();
246:                for (Class actionClass : actionsToInherit) {
247:                    Presenter presenter = ActionsPresenterForwarder
248:                            .byReference(referencePropertyName, actionClass);
249:                    if (presenter != null)
250:                        presenters.add(presenter);
251:                }
252:                return presenters;
253:            }
254:
255:            public static synchronized Collection<Presenter> createByParent(
256:                    Class... actionsToInherit) {
257:                HashSet presenters = new HashSet();
258:                for (Class actionClass : actionsToInherit) {
259:                    Presenter presenter = ActionsPresenterForwarder
260:                            .byParent(actionClass);
261:                    if (presenter != null)
262:                        presenters.add(presenter);
263:                }
264:                return presenters;
265:            }
266:
267:            private static class SeperatorAction extends AbstractAction {
268:
269:                public SeperatorAction(String name) {
270:                    putValue(Action.NAME, name);
271:                    putValue(SEPERATOR_KEY, SEPERATOR_KEY);
272:                }
273:
274:                public void actionPerformed(ActionEvent e) {
275:                }
276:
277:                @Override
278:                public boolean isEnabled() {
279:                    return false;
280:                }
281:
282:            }
283:
284:        }
w__w__w.__j_a_v___a__2__s.___com_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.