Source Code Cross Referenced for SpacePermissionsPage.java in  » Issue-Tracking » jTrac » info » jtrac » wicket » 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 » Issue Tracking » jTrac » info.jtrac.wicket 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2005 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 info.jtrac.wicket;
018:
019:        import info.jtrac.domain.Field;
020:        import info.jtrac.domain.Role;
021:        import info.jtrac.domain.Space;
022:        import info.jtrac.domain.State;
023:        import info.jtrac.domain.WorkflowRenderer;
024:        import java.util.ArrayList;
025:        import java.util.List;
026:        import java.util.Map;
027:        import org.apache.wicket.behavior.SimpleAttributeModifier;
028:        import org.apache.wicket.markup.html.WebMarkupContainer;
029:        import org.apache.wicket.markup.html.WebPage;
030:        import org.apache.wicket.markup.html.basic.Label;
031:        import org.apache.wicket.markup.html.form.Button;
032:        import org.apache.wicket.markup.html.form.Form;
033:        import org.apache.wicket.markup.html.link.Link;
034:        import org.apache.wicket.markup.html.list.ListItem;
035:        import org.apache.wicket.markup.html.list.ListView;
036:
037:        /**
038:         * space roles and workflow form
039:         */
040:        public class SpacePermissionsPage extends BasePage {
041:
042:            private WebPage previous;
043:            private Space space;
044:
045:            public SpacePermissionsPage(Space space, WebPage previous) {
046:                this .space = space;
047:                this .previous = previous;
048:                add(new SpacePermissionsForm("form"));
049:            }
050:
051:            /**
052:             * wicket form
053:             */
054:            private class SpacePermissionsForm extends Form {
055:
056:                private JtracFeedbackMessageFilter filter;
057:
058:                public SpacePermissionsForm(String id) {
059:
060:                    super (id);
061:                    // label / heading =================================================
062:                    add(new Label("label", space.getName() + " ("
063:                            + space.getPrefixCode() + ")"));
064:                    // states colspan ==================================================
065:                    final Map<Integer, String> statesMap = space.getMetadata()
066:                            .getStates();
067:                    SimpleAttributeModifier statesColspan = new SimpleAttributeModifier(
068:                            "colspan", (statesMap.size() - 1) + "");
069:                    add(new WebMarkupContainer("statesColspan")
070:                            .add(statesColspan));
071:                    // fields colspan ==================================================
072:                    final List<Field> fields = space.getMetadata()
073:                            .getFieldList();
074:                    SimpleAttributeModifier fieldsColspan = new SimpleAttributeModifier(
075:                            "colspan", fields.size() + "");
076:                    add(new WebMarkupContainer("fieldsColspan")
077:                            .add(fieldsColspan));
078:                    // add state =======================================================
079:                    add(new Button("addState") {
080:                        @Override
081:                        public void onSubmit() {
082:                            setResponsePage(new SpaceStatePage(space, -1,
083:                                    previous));
084:                        }
085:                    });
086:                    // add state =======================================================
087:                    add(new Button("addRole") {
088:                        @Override
089:                        public void onSubmit() {
090:                            setResponsePage(new SpaceRolePage(space, null,
091:                                    previous));
092:                        }
093:                    });
094:                    // states col headings =============================================
095:                    final List<Integer> stateKeysNoNew = new ArrayList(
096:                            statesMap.keySet());
097:                    stateKeysNoNew.remove(State.NEW);
098:                    add(new ListView("stateHeads", stateKeysNoNew) {
099:                        protected void populateItem(ListItem listItem) {
100:                            Integer stateKey = (Integer) listItem
101:                                    .getModelObject();
102:                            listItem.add(new Label("state", statesMap
103:                                    .get(stateKey)));
104:                        }
105:                    });
106:                    // fields col headings =============================================
107:                    add(new ListView("fieldHeads", fields) {
108:                        protected void populateItem(ListItem listItem) {
109:                            Field f = (Field) listItem.getModelObject();
110:                            listItem.add(new Label("field", f.getLabel()));
111:                        }
112:                    });
113:                    // rows init =======================================================
114:                    List<Integer> stateKeys = new ArrayList(statesMap.keySet());
115:                    final List<Role> roles = new ArrayList(space.getMetadata()
116:                            .getRoleList());
117:                    final SimpleAttributeModifier rowspan = new SimpleAttributeModifier(
118:                            "rowspan", roles.size() + "");
119:                    final SimpleAttributeModifier yes = new SimpleAttributeModifier(
120:                            "src", "../resources/status-green.gif");
121:                    final SimpleAttributeModifier no = new SimpleAttributeModifier(
122:                            "src", "../resources/status-grey.gif");
123:                    final SimpleAttributeModifier readonly = new SimpleAttributeModifier(
124:                            "src", "../resources/field-readonly.gif");
125:                    final SimpleAttributeModifier mandatory = new SimpleAttributeModifier(
126:                            "src", "../resources/field-mandatory.gif");
127:                    final SimpleAttributeModifier optional = new SimpleAttributeModifier(
128:                            "src", "../resources/field-optional.gif");
129:                    final SimpleAttributeModifier hidden = new SimpleAttributeModifier(
130:                            "src", "../resources/field-hidden.gif");
131:                    final SimpleAttributeModifier altClass = new SimpleAttributeModifier(
132:                            "class", "alt");
133:                    //==================================================================
134:                    add(new ListView("states", stateKeys) {
135:                        protected void populateItem(ListItem listItem) {
136:                            final boolean firstState = listItem.getIndex() == 0;
137:                            final String stateClass = listItem.getIndex() % 2 == 1 ? "bdr-bottom alt"
138:                                    : "bdr-bottom";
139:                            final Integer stateKeyRow = (Integer) listItem
140:                                    .getModelObject();
141:                            listItem.add(new ListView("roles", roles) {
142:                                protected void populateItem(ListItem listItem) {
143:                                    String roleClass = listItem.getIndex() % 2 == 1 ? " alt"
144:                                            : "";
145:                                    String lastRole = listItem.getIndex() == roles
146:                                            .size() - 1 ? " bdr-bottom" : "";
147:                                    listItem.add(new SimpleAttributeModifier(
148:                                            "class", "center" + roleClass
149:                                                    + lastRole));
150:                                    final Role role = (Role) listItem
151:                                            .getModelObject();
152:                                    if (listItem.getIndex() == 0) {
153:                                        SimpleAttributeModifier rowClass = new SimpleAttributeModifier(
154:                                                "class", stateClass);
155:                                        listItem.add(new Label("state",
156:                                                statesMap.get(stateKeyRow))
157:                                                .add(rowspan).add(rowClass));
158:                                        WebMarkupContainer editState = new WebMarkupContainer(
159:                                                "editState");
160:                                        editState.add(rowspan).add(rowClass);
161:                                        Button editStateButton = new Button(
162:                                                "editState") {
163:                                            @Override
164:                                            public void onSubmit() {
165:                                                setResponsePage(new SpaceStatePage(
166:                                                        space, stateKeyRow,
167:                                                        previous));
168:                                            }
169:                                        };
170:                                        editState.add(editStateButton);
171:                                        if (stateKeyRow == State.NEW) { // user can customize state names, even for Closed
172:                                            editStateButton.setVisible(false);
173:                                        }
174:                                        listItem.add(editState);
175:                                    } else {
176:                                        listItem.add(new WebMarkupContainer(
177:                                                "state").setVisible(false));
178:                                        listItem.add(new WebMarkupContainer(
179:                                                "editState").setVisible(false));
180:                                    }
181:                                    listItem.add(new Label("role", role
182:                                            .getName()));
183:                                    Button editRoleButton = new Button(
184:                                            "editRole") {
185:                                        @Override
186:                                        public void onSubmit() {
187:                                            setResponsePage(new SpaceRolePage(
188:                                                    space, role.getName(),
189:                                                    previous));
190:                                        }
191:                                    };
192:                                    listItem.add(editRoleButton);
193:                                    if (!firstState) {
194:                                        editRoleButton.setVisible(false);
195:                                    }
196:                                    listItem.add(new ListView("stateHeads",
197:                                            stateKeysNoNew) {
198:                                        protected void populateItem(
199:                                                ListItem listItem) {
200:                                            final Integer stateKeyCol = (Integer) listItem
201:                                                    .getModelObject();
202:                                            Button stateButton = new Button(
203:                                                    "state") {
204:                                                @Override
205:                                                public void onSubmit() {
206:                                                    space
207:                                                            .getMetadata()
208:                                                            .toggleTransition(
209:                                                                    role
210:                                                                            .getName(),
211:                                                                    stateKeyRow,
212:                                                                    stateKeyCol);
213:                                                    setResponsePage(new SpacePermissionsPage(
214:                                                            space, previous));
215:                                                }
216:                                            };
217:                                            if (stateKeyRow == State.NEW
218:                                                    && stateKeyCol != State.OPEN) {
219:                                                stateButton.setVisible(false);
220:                                            }
221:                                            State state = role.getStates().get(
222:                                                    stateKeyRow);
223:                                            if (state != null
224:                                                    && state
225:                                                            .getTransitions()
226:                                                            .contains(
227:                                                                    stateKeyCol)) {
228:                                                stateButton.add(yes);
229:                                            } else {
230:                                                stateButton.add(no);
231:                                            }
232:                                            listItem.add(stateButton);
233:                                        }
234:                                    });
235:                                    listItem.add(new ListView("fieldHeads",
236:                                            fields) {
237:                                        protected void populateItem(
238:                                                ListItem listItem) {
239:                                            if (roles.size() == 1
240:                                                    && listItem.getIndex() % 2 == 0) {
241:                                                listItem.add(altClass);
242:                                            }
243:                                            final Field field = (Field) listItem
244:                                                    .getModelObject();
245:                                            Button fieldButton = new Button(
246:                                                    "field") {
247:                                                @Override
248:                                                public void onSubmit() {
249:                                                    space
250:                                                            .getMetadata()
251:                                                            .switchMask(
252:                                                                    stateKeyRow,
253:                                                                    role
254:                                                                            .getName(),
255:                                                                    field
256:                                                                            .getName()
257:                                                                            .getText());
258:                                                    setResponsePage(new SpacePermissionsPage(
259:                                                            space, previous));
260:                                                }
261:                                            };
262:                                            State state = role.getStates().get(
263:                                                    stateKeyRow);
264:                                            int mask = state.getFields().get(
265:                                                    field.getName());
266:                                            switch (mask) {
267:                                            case State.MASK_MANDATORY:
268:                                                fieldButton.add(mandatory);
269:                                                break;
270:                                            case State.MASK_OPTIONAL:
271:                                                fieldButton.add(optional);
272:                                                break;
273:                                            case State.MASK_READONLY:
274:                                                fieldButton.add(readonly);
275:                                                break;
276:                                            case State.MASK_HIDDEN:
277:                                                fieldButton.add(hidden);
278:                                                break;
279:                                            default: // should never happen
280:                                            }
281:                                            listItem.add(fieldButton);
282:                                        }
283:                                    });
284:                                }
285:                            });
286:                        }
287:                    });
288:                    // back ============================================================
289:                    add(new Button("back") {
290:                        @Override
291:                        public void onSubmit() {
292:                            setResponsePage(new SpaceFieldListPage(space, null,
293:                                    previous));
294:                        }
295:                    });
296:                    // save ============================================================
297:                    add(new Button("save") {
298:                        @Override
299:                        public void onSubmit() {
300:                            boolean isNewSpace = space.getId() == 0;
301:                            getJtrac().storeSpace(space);
302:                            // current user may be allocated to this space, and e.g. name could have changed
303:                            refreshPrincipal();
304:                            if (isNewSpace) {
305:                                setResponsePage(new SpaceAllocatePage(space
306:                                        .getId(), previous));
307:                            } else if (previous == null) {
308:                                setResponsePage(new OptionsPage());
309:                            } else {
310:                                if (previous instanceof  SpaceListPage) {
311:                                    ((SpaceListPage) previous)
312:                                            .setSelectedSpaceId(space.getId());
313:                                }
314:                                setResponsePage(previous);
315:                            }
316:                        }
317:                    });
318:                    // cancel ==========================================================
319:                    add(new Link("cancel") {
320:                        public void onClick() {
321:                            setResponsePage(previous);
322:                        }
323:                    });
324:                    WorkflowRenderer workflow = new WorkflowRenderer(space
325:                            .getMetadata().getRoles(), space.getMetadata()
326:                            .getStates());
327:                    add(new Label("workflow", workflow.getAsHtml())
328:                            .setEscapeModelStrings(false));
329:                }
330:
331:            }
332:
333:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.