Source Code Cross Referenced for PackageEditor.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » brms » client » packages » 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 » Rule Engine » drolls Rule Engine » org.drools.brms.client.packages 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.brms.client.packages;
002:
003:        /*
004:         * Copyright 2005 JBoss Inc
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *      http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        import org.drools.brms.client.common.FormStyleLayout;
020:        import org.drools.brms.client.common.FormStylePopup;
021:        import org.drools.brms.client.common.GenericCallback;
022:        import org.drools.brms.client.common.ImageButton;
023:        import org.drools.brms.client.common.LoadingPopup;
024:        import org.drools.brms.client.common.StatusChangePopup;
025:        import org.drools.brms.client.common.ValidationMessageWidget;
026:        import org.drools.brms.client.common.YesNoDialog;
027:        import org.drools.brms.client.rpc.PackageConfigData;
028:        import org.drools.brms.client.rpc.RepositoryServiceFactory;
029:        import org.drools.brms.client.rpc.ValidatedResponse;
030:
031:        import com.google.gwt.user.client.Command;
032:        import com.google.gwt.user.client.Timer;
033:        import com.google.gwt.user.client.Window;
034:        import com.google.gwt.user.client.ui.Button;
035:        import com.google.gwt.user.client.ui.ChangeListener;
036:        import com.google.gwt.user.client.ui.ClickListener;
037:        import com.google.gwt.user.client.ui.HTML;
038:        import com.google.gwt.user.client.ui.HorizontalPanel;
039:        import com.google.gwt.user.client.ui.Image;
040:        import com.google.gwt.user.client.ui.Label;
041:        import com.google.gwt.user.client.ui.SimplePanel;
042:        import com.google.gwt.user.client.ui.TextArea;
043:        import com.google.gwt.user.client.ui.TextBox;
044:        import com.google.gwt.user.client.ui.VerticalPanel;
045:        import com.google.gwt.user.client.ui.Widget;
046:
047:        /**
048:         * This is the package editor and viewer for package configuration.
049:         *
050:         * @author Michael Neale
051:         */
052:        public class PackageEditor extends FormStyleLayout {
053:
054:            private Command dirtyCommand;
055:            private Command cleanCommand;
056:
057:            private PackageConfigData conf;
058:            private HTML status;
059:            protected ValidatedResponse previousResponse;
060:            private Command refreshCommand;
061:
062:            public PackageEditor(PackageConfigData data, Command dirtyCommand,
063:                    Command cleanCommand, Command refreshCommand) {
064:                this .conf = data;
065:                this .dirtyCommand = dirtyCommand;
066:                this .cleanCommand = cleanCommand;
067:                this .refreshCommand = refreshCommand;
068:
069:                setStyleName("package-Editor");
070:                setWidth("100%");
071:                refreshWidgets();
072:            }
073:
074:            private void refreshWidgets() {
075:                clear();
076:                //addHeader( "images/package_large.png", this.conf.name );
077:
078:                addRow(warnings());
079:
080:                addAttribute("Description:", description());
081:                addAttribute("Header:", header());
082:                //addAttribute( "External repository sync URI:", externalURI() );
083:                addRow(new HTML("<hr/>"));
084:                addAttribute("Last modified:", new Label(this .conf.lastModified
085:                        .toLocaleString()));
086:                addAttribute("Last contributor:", new Label(
087:                        this .conf.lasContributor));
088:
089:                addRow(new HTML("<hr/>"));
090:
091:                status = new HTML();
092:                HorizontalPanel statusBar = new HorizontalPanel();
093:                Image editState = new ImageButton("images/edit.gif");
094:                editState.setTitle("Change status.");
095:                editState.addClickListener(new ClickListener() {
096:                    public void onClick(Widget w) {
097:                        showStatusChanger(w);
098:                    }
099:
100:                });
101:                statusBar.add(status);
102:
103:                if (!this .conf.isSnapshot) {
104:                    statusBar.add(editState);
105:                }
106:
107:                setState(conf.state);
108:                addAttribute("Status:", statusBar);
109:
110:                if (!conf.isSnapshot) {
111:                    addRow(saveWidgets());
112:                }
113:                addRow(new HTML("<hr/>"));
114:
115:            }
116:
117:            private Widget warnings() {
118:                if (this .previousResponse != null
119:                        && this .previousResponse.hasErrors) {
120:                    Image img = new Image("images/warning.gif");
121:                    HorizontalPanel h = new HorizontalPanel();
122:                    h.add(img);
123:                    HTML msg = new HTML(
124:                            "<b>There were errors validating this package configuration.");
125:                    h.add(msg);
126:                    Button show = new Button("View errors");
127:                    show.addClickListener(new ClickListener() {
128:                        public void onClick(Widget w) {
129:                            ValidationMessageWidget wid = new ValidationMessageWidget(
130:                                    previousResponse.errorHeader,
131:                                    previousResponse.errorMessage);
132:                            wid.setPopupPosition(Window.getClientWidth() / 4, w
133:                                    .getAbsoluteTop());
134:                            wid.show();
135:                        }
136:                    });
137:                    h.add(show);
138:                    return h;
139:                } else {
140:                    return new SimplePanel();
141:                }
142:            }
143:
144:            protected void showStatusChanger(Widget w) {
145:                final StatusChangePopup pop = new StatusChangePopup(conf.uuid,
146:                        true);
147:                pop.setChangeStatusEvent(new Command() {
148:                    public void execute() {
149:                        setState(pop.getState());
150:                    }
151:                });
152:                pop.setPopupPosition(w.getAbsoluteLeft(), w.getAbsoluteTop());
153:                pop.show();
154:
155:            }
156:
157:            private void setState(String state) {
158:                status.setHTML("<b>" + state + "</b>");
159:            }
160:
161:            /**
162:             * This will get the save widgets.
163:             */
164:            private Widget saveWidgets() {
165:
166:                HorizontalPanel horiz = new HorizontalPanel();
167:
168:                Button save = new Button("Save and validate configuration");
169:
170:                save.addClickListener(new ClickListener() {
171:                    public void onClick(Widget w) {
172:                        doSaveAction(null);
173:                    }
174:                });
175:                horiz.add(save);
176:
177:                Button archive = new Button("Archive");
178:                archive.addClickListener(new ClickListener() {
179:                    public void onClick(Widget w) {
180:                        if (Window
181:                                .confirm("Are you sure you want to archive (remove) this package?")) {
182:                            conf.archived = true;
183:                            doSaveAction(refreshCommand);
184:                        }
185:                    }
186:                });
187:                horiz.add(archive);
188:
189:                Button copy = new Button("Copy");
190:                copy.addClickListener(new ClickListener() {
191:                    public void onClick(Widget w) {
192:                        showCopyDialog();
193:                    }
194:                });
195:                horiz.add(copy);
196:
197:                Button rename = new Button("Rename");
198:                rename.addClickListener(new ClickListener() {
199:                    public void onClick(Widget w) {
200:                        showRenameDialog();
201:                    }
202:                });
203:                horiz.add(rename);
204:
205:                return horiz;
206:            }
207:
208:            private void showRenameDialog() {
209:                final FormStylePopup pop = new FormStylePopup(
210:                        "images/new_wiz.gif", "Rename the package");
211:                pop
212:                        .addRow(new HTML(
213:                                "<i>Rename the package. A new unique name is required.</i>"));
214:                final TextBox name = new TextBox();
215:                pop.addAttribute("New package name:", name);
216:                Button ok = new Button("OK");
217:                pop.addAttribute("", ok);
218:
219:                ok.addClickListener(new ClickListener() {
220:                    public void onClick(Widget w) {
221:                        RepositoryServiceFactory.getService().renamePackage(
222:                                conf.uuid, name.getText(),
223:                                new GenericCallback() {
224:                                    public void onSuccess(Object data) {
225:                                        refreshCommand.execute();
226:                                        Window
227:                                                .alert("Package renamed successfully.");
228:                                        pop.hide();
229:                                    }
230:                                });
231:                    }
232:                });
233:
234:                pop.setWidth("40%");
235:                pop.setPopupPosition(Window.getClientWidth() / 3, Window
236:                        .getClientHeight() / 3);
237:                pop.show();
238:            }
239:
240:            /**
241:             * Will show a copy dialog for copying the whole package.
242:             */
243:            private void showCopyDialog() {
244:                final FormStylePopup pop = new FormStylePopup(
245:                        "images/new_wiz.gif", "Copy the package");
246:                pop
247:                        .addRow(new HTML(
248:                                "<i>Copy the package and all its assets. A new unique name is required.</i>"));
249:                final TextBox name = new TextBox();
250:                pop.addAttribute("New package name:", name);
251:                Button ok = new Button("OK");
252:                pop.addAttribute("", ok);
253:
254:                ok.addClickListener(new ClickListener() {
255:                    public void onClick(Widget w) {
256:                        RepositoryServiceFactory.getService().copyPackage(
257:                                conf.name, name.getText(),
258:                                new GenericCallback() {
259:                                    public void onSuccess(Object data) {
260:                                        refreshCommand.execute();
261:                                        Window
262:                                                .alert("Package copied successfully.");
263:                                        pop.hide();
264:                                    }
265:                                });
266:                    }
267:                });
268:
269:                pop.setWidth("40%");
270:                pop.setPopupPosition(Window.getClientWidth() / 3, Window
271:                        .getClientHeight() / 3);
272:                pop.show();
273:
274:            }
275:
276:            protected void doCopyPackage(String name) {
277:
278:            }
279:
280:            private void doSaveAction(final Command refresh) {
281:                LoadingPopup
282:                        .showMessage("Saving package configuration. Please wait ...");
283:                RepositoryServiceFactory.getService().savePackage(this .conf,
284:                        new GenericCallback() {
285:                            public void onSuccess(Object data) {
286:
287:                                cleanCommand.execute();
288:
289:                                previousResponse = (ValidatedResponse) data;
290:
291:                                reload();
292:                                LoadingPopup
293:                                        .showMessage("Package configuration updated successfully, refreshing content cache...");
294:
295:                                SuggestionCompletionCache.getInstance()
296:                                        .refreshPackage(conf.name,
297:                                                new Command() {
298:                                                    public void execute() {
299:                                                        if (refresh != null) {
300:                                                            refresh.execute();
301:                                                        }
302:                                                        LoadingPopup.close();
303:                                                    }
304:                                                });
305:
306:                            }
307:                        });
308:
309:            }
310:
311:            /**
312:             * Will refresh all the data.
313:             */
314:            private void reload() {
315:                LoadingPopup.showMessage("Refreshing package data...");
316:                RepositoryServiceFactory.getService().loadPackageConfig(
317:                        this .conf.uuid, new GenericCallback() {
318:                            public void onSuccess(Object data) {
319:                                LoadingPopup.close();
320:                                conf = (PackageConfigData) data;
321:                                refreshWidgets();
322:                            }
323:                        });
324:            }
325:
326:            private Widget externalURI() {
327:                final TextBox box = new TextBox();
328:                box.setWidth("100%");
329:                box.setText(this .conf.externalURI);
330:                box.addChangeListener(new ChangeListener() {
331:                    public void onChange(Widget w) {
332:                        conf.externalURI = box.getText();
333:                    }
334:                });
335:                return box;
336:            }
337:
338:            private Widget header() {
339:
340:                final TextArea area = new TextArea();
341:                area.setWidth("100%");
342:                area.setVisibleLines(8);
343:
344:                area.setCharacterWidth(100);
345:
346:                area.setText(this .conf.header);
347:                area.addChangeListener(new ChangeListener() {
348:                    public void onChange(Widget w) {
349:                        conf.header = area.getText();
350:                        dirtyCommand.execute();
351:                    }
352:                });
353:
354:                HorizontalPanel panel = new HorizontalPanel();
355:                panel.add(area);
356:
357:                VerticalPanel vert = new VerticalPanel();
358:
359:                Image max = new Image("images/max_min.gif");
360:                max.addClickListener(new ClickListener() {
361:                    public void onClick(Widget w) {
362:                        if (area.getVisibleLines() != 32) {
363:                            area.setVisibleLines(32);
364:                        } else {
365:                            area.setVisibleLines(8);
366:                        }
367:                    }
368:                });
369:                max.setTitle("Increase view area.");
370:                vert.add(max);
371:
372:                Image newImport = new Image("images/new_import.gif");
373:                newImport.addClickListener(new ClickListener() {
374:                    public void onClick(Widget w) {
375:                        area.setText(area.getText() + "\n"
376:                                + "import <your class here>");
377:                        conf.header = area.getText();
378:                    }
379:                });
380:                vert.add(newImport);
381:                newImport
382:                        .setTitle("Add a new Type/Class import to the package.");
383:
384:                Image newGlobal = new Image("images/new_global.gif");
385:                newGlobal.addClickListener(new ClickListener() {
386:                    public void onClick(Widget w) {
387:                        area.setText(area.getText() + "\n"
388:                                + "global <your class here> <variable name>");
389:                        conf.header = area.getText();
390:                    }
391:                });
392:                newGlobal.setTitle("Add a new global variable declaration.");
393:                vert.add(newGlobal);
394:
395:                Image newFactTemplate = new Image("images/fact_template.gif");
396:                newFactTemplate.addClickListener(new ClickListener() {
397:                    public void onClick(Widget w) {
398:                        final FactTemplateWizard wiz = new FactTemplateWizard();
399:                        wiz.setPopupPosition(w.getAbsoluteLeft() - 400, w
400:                                .getAbsoluteTop() - 250);
401:                        wiz.setOKClick(new Command() {
402:                            public void execute() {
403:                                area.setText(area.getText() + "\n"
404:                                        + wiz.getTemplateText());
405:                                conf.header = area.getText();
406:
407:                            }
408:                        });
409:                        wiz.show();
410:                    }
411:                });
412:                newFactTemplate.setTitle("Add a new fact template.");
413:                //vert.add( newFactTemplate );
414:
415:                panel.setWidth("100%");
416:
417:                panel.add(vert);
418:                return panel;
419:            }
420:
421:            private HorizontalPanel expandableTextArea(final TextArea area) {
422:                HorizontalPanel panel = new HorizontalPanel();
423:                panel.add(area);
424:
425:                Image max = new Image("images/max_min.gif");
426:                max.setTitle("Increase view area");
427:
428:                panel.add(max);
429:                max.addClickListener(new ClickListener() {
430:                    public void onClick(Widget w) {
431:                        if (area.getVisibleLines() != 32) {
432:                            area.setVisibleLines(32);
433:                        } else {
434:                            area.setVisibleLines(8);
435:                        }
436:                    }
437:                });
438:                return panel;
439:            }
440:
441:            private Widget description() {
442:                final TextArea area = new TextArea();
443:                area.setWidth("100%");
444:                area.setVisibleLines(8);
445:                area.setText(conf.description);
446:
447:                area.addChangeListener(new ChangeListener() {
448:                    public void onChange(Widget w) {
449:                        conf.description = area.getText();
450:                        dirtyCommand.execute();
451:                    }
452:                });
453:
454:                area.setCharacterWidth(100);
455:
456:                return expandableTextArea(area);
457:            }
458:
459:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.