Source Code Cross Referenced for UIPagesPropertiesComposite.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » ui » ide » customcomponent » wizard » 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 » ESB » cbesb 1.2 » com.bostechcorp.cbesb.ui.ide.customcomponent.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bostechcorp.cbesb.ui.ide.customcomponent.wizard;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:
006:        import org.eclipse.jface.action.Action;
007:        import org.eclipse.jface.action.IAction;
008:        import org.eclipse.jface.action.MenuManager;
009:        import org.eclipse.jface.resource.ImageDescriptor;
010:        import org.eclipse.jface.viewers.CellEditor;
011:        import org.eclipse.jface.viewers.CheckboxCellEditor;
012:        import org.eclipse.jface.viewers.ComboBoxCellEditor;
013:        import org.eclipse.jface.viewers.ICellModifier;
014:        import org.eclipse.jface.viewers.ILabelProviderListener;
015:        import org.eclipse.jface.viewers.IStructuredContentProvider;
016:        import org.eclipse.jface.viewers.ITableLabelProvider;
017:        import org.eclipse.jface.viewers.TableViewer;
018:        import org.eclipse.jface.viewers.TextCellEditor;
019:        import org.eclipse.jface.viewers.Viewer;
020:        import org.eclipse.swt.SWT;
021:        import org.eclipse.swt.custom.SashForm;
022:        import org.eclipse.swt.events.ControlAdapter;
023:        import org.eclipse.swt.events.ControlEvent;
024:        import org.eclipse.swt.events.SelectionAdapter;
025:        import org.eclipse.swt.events.SelectionEvent;
026:        import org.eclipse.swt.events.SelectionListener;
027:        import org.eclipse.swt.graphics.Image;
028:        import org.eclipse.swt.graphics.Point;
029:        import org.eclipse.swt.graphics.Rectangle;
030:        import org.eclipse.swt.layout.GridData;
031:        import org.eclipse.swt.layout.GridLayout;
032:        import org.eclipse.swt.widgets.Composite;
033:        import org.eclipse.swt.widgets.Group;
034:        import org.eclipse.swt.widgets.Menu;
035:        import org.eclipse.swt.widgets.Table;
036:        import org.eclipse.swt.widgets.TableColumn;
037:        import org.eclipse.swt.widgets.TableItem;
038:        import org.eclipse.swt.widgets.ToolBar;
039:        import org.eclipse.swt.widgets.ToolItem;
040:        import org.eclipse.ui.ISharedImages;
041:        import org.eclipse.ui.PlatformUI;
042:
043:        import com.bostechcorp.cbesb.common.i18n.I18N;
044:        import com.bostechcorp.cbesb.common.i18n.Messages;
045:        import com.bostechcorp.cbesb.ui.ide.Activator;
046:        import com.bostechcorp.cbesb.ui.util.resource.ESBResourceManager;
047:
048:        public class UIPagesPropertiesComposite extends Composite {
049:
050:            public enum UIErrorsEnum {
051:                NO_ERROR, EMPTY_NAME_PAGE, IDENTICAL_NAME_PAGE, EMPTY_NAME_PROPERTY, IDENTICAL_NAME_PROPERTY
052:            };
053:
054:            private Table table_1;
055:
056:            private Table table;
057:
058:            private TableViewer tableViewer;
059:
060:            private TableViewer table_1Viewer;
061:
062:            private static final String[] TYPE_VALUE_SET = new String[] {
063:                    I18N.getString(Messages.CBCC_UI_PAGES_COMPOSITE_COMBO_TEXT),
064:                    I18N.getString(Messages.CBCC_UI_PAGES_COMPOSITE_COMBO_FILE),
065:                    I18N
066:                            .getString(Messages.CBCC_UI_PAGES_COMPOSITE_COMBO_ENUMERATION),
067:                    I18N
068:                            .getString(Messages.CBCC_UI_PAGES_COMPOSITE_COMBO_BOOLEAN),
069:                    I18N
070:                            .getString(Messages.CBCC_UI_PAGES_COMPOSITE_COMBO_ENDPOINT) };
071:
072:            private static final String NAME_PROPERTY = "name";
073:
074:            private static final String DESCRIPTION_PROPERTY = "description";
075:
076:            private static final String TYPE_PROPERTY = "type";
077:
078:            private static final String REQUIRED_PROPERTY = "required";
079:
080:            private static final String READ_ONLY_PROPERTY = "readOnly";
081:
082:            private List<PagesModelTableItem> pagesModelContent = new ArrayList<PagesModelTableItem>();
083:
084:            private Object[] CONTENT_TABLE = null;/*
085:             * new Object[] { new
086:             * PagesModelTableItem("item 1", "
087:             * some",null), new
088:             * PagesModelTableItem("item 2", "
089:             * some",null) };
090:             */
091:
092:            private Object[] CONTENT_TABLE_1 = null;/*
093:             * new Object[] { new
094:             * PropertiesModelTableItem("item 1", new
095:             * Integer(0),new Boolean(false),
096:             * new Boolean(false)), new
097:             * PropertiesModelTableItem("item 2", new
098:             * Integer(0),new Boolean(false),
099:             * new Boolean(false)) };
100:             */
101:
102:            // Name Editors
103:            TextCellEditor pageNameEditor = null;
104:
105:            TextCellEditor propertyNameEditor = null;
106:
107:            // Actions
108:            private IAction newPropertyAction = new NewRowTable1Action();
109:
110:            private IAction removePropertyAction = new RemoveRowTable1Action();
111:
112:            private IAction newPageAction = new NewRowTableAction();
113:
114:            private IAction removePageAction = new RemoveRowTableAction();
115:
116:            //Toolbar buttons
117:            final ToolItem newItemToolItem;
118:            final ToolItem newItemToolItem_1;
119:            final ToolItem newItemToolItem_2;
120:            final ToolItem newItemToolItem_3;
121:            //
122:            SelectionListener selectionAdapterTable = new SelectionAdapter() {
123:                public void widgetSelected(SelectionEvent e) {
124:                    if (e.item.getData() instanceof  PagesModelTableItem) {
125:                        CONTENT_TABLE_1 = ((PagesModelTableItem) e.item
126:                                .getData()).properties.toArray();
127:                        table_1Viewer.setInput(CONTENT_TABLE_1);
128:                        if (CONTENT_TABLE_1.length != 0) {
129:                            table_1.setSelection(0);
130:                        }
131:                    }
132:                }
133:
134:                public void widgetDefaultSelected(SelectionEvent e) {
135:                }
136:            };
137:
138:            // holds error of the page
139:            public UIErrorsEnum ERROR = UIErrorsEnum.NO_ERROR;
140:
141:            // counters
142:            private static int pagesCounter = 0;
143:
144:            private static int propertyesCounter = 0;
145:
146:            /**
147:             * Create the composite
148:             * 
149:             * @param parent
150:             * @param style
151:             */
152:            public UIPagesPropertiesComposite(Composite parent, int style) {
153:                super (parent, style);
154:                setLayout(new GridLayout());
155:
156:                final ToolBar toolBar = new ToolBar(this , SWT.SHADOW_OUT
157:                        | SWT.FLAT | SWT.WRAP);
158:
159:                newItemToolItem = new ToolItem(toolBar, SWT.PUSH);
160:                newItemToolItem.setImage(ESBResourceManager.getPluginImage(
161:                        Activator.getDefault(), "icons/dialog/add.ico"));
162:                // newItemToolItem.setImage(ResourceManager.getPluginImage(Activator.getDefault(),
163:                // "icons/dialog/add.ico"));
164:                // newItemToolItem.setImage(ResourceManager.getPluginImage(AbstractUIPlugin.getDefault(),
165:                // "icons/dialog/add.ico"));
166:                newItemToolItem.addSelectionListener(new SelectionAdapter() {
167:                    public void widgetSelected(SelectionEvent e) {
168:                        newPageAction.run();
169:                    }
170:                });
171:                newItemToolItem.setText("Add Page");
172:
173:                newItemToolItem_1 = new ToolItem(toolBar, SWT.PUSH);
174:                newItemToolItem_1.addSelectionListener(new SelectionAdapter() {
175:                    public void widgetSelected(SelectionEvent e) {
176:                        removePageAction.run();
177:                    }
178:                });
179:                newItemToolItem_1.setText("Remove Page");
180:                newItemToolItem_1.setImage(PlatformUI.getWorkbench()
181:                        .getSharedImages().getImage(
182:                                ISharedImages.IMG_TOOL_DELETE));
183:                final ToolItem newItemToolItem_4 = new ToolItem(toolBar,
184:                        SWT.SEPARATOR);
185:                newItemToolItem_4.setWidth(0);
186:                newItemToolItem_4.setText("separator");
187:
188:                newItemToolItem_2 = new ToolItem(toolBar, SWT.PUSH);
189:                newItemToolItem_2.setImage(ESBResourceManager.getPluginImage(
190:                        Activator.getDefault(), "icons/dialog/add.ico"));
191:                // newItemToolItem_2.setImage(ResourceManager.getPluginImage(Activator.getDefault(),
192:                // "icons/dialog/add.ico"));
193:                // newItemToolItem_2.setImage(ResourceManager.getPluginImage(Activator.getDefault(),
194:                // "icons/dialog/add.ico"));
195:                newItemToolItem_2.addSelectionListener(new SelectionAdapter() {
196:                    public void widgetSelected(SelectionEvent e) {
197:                        newPropertyAction.run();
198:                    }
199:                });
200:                newItemToolItem_2.setText("Add Property");
201:
202:                newItemToolItem_3 = new ToolItem(toolBar, SWT.PUSH);
203:                newItemToolItem_3.addSelectionListener(new SelectionAdapter() {
204:                    public void widgetSelected(SelectionEvent e) {
205:                        removePropertyAction.run();
206:                    }
207:                });
208:                newItemToolItem_3.setText("Remove Property");
209:                newItemToolItem_3.setImage(PlatformUI.getWorkbench()
210:                        .getSharedImages().getImage(
211:                                ISharedImages.IMG_TOOL_DELETE));
212:                final SashForm sashForm = new SashForm(this , SWT.NONE);
213:
214:                final Group pagesGroup = new Group(sashForm, SWT.NONE);
215:                final GridLayout gridLayout = new GridLayout();
216:                gridLayout.marginWidth = 0;
217:                gridLayout.marginHeight = 0;
218:                pagesGroup.setLayout(gridLayout);
219:                pagesGroup.setText("Pages");
220:
221:                table = new Table(pagesGroup, SWT.FULL_SELECTION | SWT.BORDER);
222:                table.setLinesVisible(true);
223:                table.setHeaderVisible(true);
224:                table
225:                        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
226:                                true));
227:                tableViewer = new TableViewer(table);
228:                table.addSelectionListener(selectionAdapterTable);
229:
230:                final TableColumn newColumnTableColumn = new TableColumn(table,
231:                        SWT.NONE);
232:                newColumnTableColumn.setWidth(100);
233:                newColumnTableColumn.setText("Name");
234:
235:                final TableColumn newColumnTableColumn_1 = new TableColumn(
236:                        table, SWT.NONE);
237:                newColumnTableColumn_1.setWidth(100);
238:                newColumnTableColumn_1.setText("Description");
239:                sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
240:                        true));
241:
242:                final Group propertiesGroup = new Group(sashForm, SWT.NONE);
243:                final GridLayout gridLayout_1 = new GridLayout();
244:                gridLayout_1.marginWidth = 0;
245:                gridLayout_1.marginHeight = 0;
246:                propertiesGroup.setLayout(gridLayout_1);
247:                propertiesGroup.setText("Property");
248:
249:                table_1 = new Table(propertiesGroup, SWT.FULL_SELECTION
250:                        | SWT.BORDER);
251:                table_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
252:                        true));
253:                table_1.setLinesVisible(true);
254:                table_1.setHeaderVisible(true);
255:                table_1Viewer = new TableViewer(table_1);
256:
257:                final TableColumn newColumnTableColumn_2 = new TableColumn(
258:                        table_1, SWT.NONE);
259:                newColumnTableColumn_2.setWidth(75);
260:                newColumnTableColumn_2.setText("Name");
261:
262:                final TableColumn newColumnTableColumn_3 = new TableColumn(
263:                        table_1, SWT.NONE);
264:                newColumnTableColumn_3.setMoveable(true);
265:                newColumnTableColumn_3.setWidth(75);
266:                newColumnTableColumn_3.setText("Type");
267:
268:                final TableColumn newColumnTableColumn_5 = new TableColumn(
269:                        table_1, SWT.NONE);
270:                newColumnTableColumn_5.setMoveable(true);
271:                newColumnTableColumn_5.setWidth(65);
272:                newColumnTableColumn_5.setText("Required");
273:
274:                final TableColumn newColumnTableColumn_4 = new TableColumn(
275:                        table_1, SWT.NONE);
276:                newColumnTableColumn_4.setMoveable(true);
277:                newColumnTableColumn_4.setWidth(65);
278:                newColumnTableColumn_4.setText("ReadOnly");
279:                sashForm.setWeights(new int[] { 30, 70 });
280:
281:                pagesGroup.addControlListener(new ControlAdapter() {
282:                    public void controlResized(ControlEvent e) {
283:                        Rectangle area = pagesGroup.getClientArea();
284:                        Point preferredSize = table.computeSize(SWT.DEFAULT,
285:                                SWT.DEFAULT);
286:                        int width = area.width - 2 * table.getBorderWidth();
287:                        if (preferredSize.y > area.height
288:                                + table.getHeaderHeight()) {
289:                            // Subtract the scrollbar width from the total column width
290:                            // if a vertical scrollbar will be required
291:                            Point vBarSize = table.getVerticalBar().getSize();
292:                            width -= vBarSize.x;
293:                        }
294:                        Point oldSize = table.getSize();
295:                        if (oldSize.x > area.width) {
296:                            // table is getting smaller so make the columns
297:                            // smaller first and then resize the table to
298:                            // match the client area width
299:                            newColumnTableColumn.setWidth(width / 3);
300:                            newColumnTableColumn_1.setWidth(width
301:                                    - newColumnTableColumn.getWidth());
302:                            table.setSize(area.width, area.height);
303:                        } else {
304:                            // table is getting bigger so make the table
305:                            // bigger first and then make the columns wider
306:                            // to match the client area width
307:                            table.setSize(area.width, area.height);
308:                            newColumnTableColumn.setWidth(width / 3);
309:                            newColumnTableColumn_1.setWidth(width
310:                                    - newColumnTableColumn.getWidth());
311:                        }
312:                    }
313:                });
314:
315:                propertiesGroup.addControlListener(new ControlAdapter() {
316:                    public void controlResized(ControlEvent e) {
317:                        Rectangle area = propertiesGroup.getClientArea();
318:                        Point preferredSize = table_1.computeSize(SWT.DEFAULT,
319:                                SWT.DEFAULT);
320:                        int width = area.width - 2 * table_1.getBorderWidth();
321:                        if (preferredSize.y > area.height
322:                                + table_1.getHeaderHeight()) {
323:                            // Subtract the scrollbar width from the total column width
324:                            // if a vertical scrollbar will be required
325:                            Point vBarSize = table_1.getVerticalBar().getSize();
326:                            width -= vBarSize.x;
327:                        }
328:                        Point oldSize = table_1.getSize();
329:                        if (oldSize.x > area.width) {
330:                            // table is getting smaller so make the columns
331:                            // smaller first and then resize the table to
332:                            // match the client area width
333:                            if (width / 4 < 60) {
334:                                newColumnTableColumn_2.setWidth(80);
335:                                newColumnTableColumn_3.setWidth(80);
336:                                newColumnTableColumn_4.setWidth(65);
337:                                newColumnTableColumn_5.setWidth(65);
338:                                table_1.setSize(area.width, area.height);
339:                            } else {
340:                                newColumnTableColumn_2
341:                                        .setWidth((width - 130) / 2);
342:                                newColumnTableColumn_4.setWidth(65);
343:                                newColumnTableColumn_5.setWidth(65);
344:                                newColumnTableColumn_3.setWidth(width - 130
345:                                        - newColumnTableColumn_2.getWidth());
346:                                table_1.setSize(area.width, area.height);
347:
348:                            }
349:                        } else {
350:                            // table is getting bigger so make the table
351:                            // bigger first and then make the columns wider
352:                            // to match the client area width
353:                            table_1.setSize(area.width, area.height);
354:                            newColumnTableColumn_2.setWidth((width - 130) / 2);
355:                            newColumnTableColumn_3.setWidth(width - 130
356:                                    - newColumnTableColumn_2.getWidth());
357:                            newColumnTableColumn_4.setWidth(65);
358:                            newColumnTableColumn_5.setWidth(65);
359:                        }
360:                    }
361:                });
362:                // Extra controls
363:                // ->table
364:                attachContentProvider(tableViewer);
365:                attachLabelProviderTable(tableViewer);
366:                attachCellEditorsTable(tableViewer, table);
367:
368:                // ->table_1;
369:                attachContentProvider(table_1Viewer);
370:                attachLabelProviderTable1(table_1Viewer);
371:                attachCellEditorsTable1(table_1Viewer, table_1);
372:
373:                // setting menu for table
374:                // some images first
375:                ImageDescriptor removeImage = PlatformUI.getWorkbench()
376:                        .getSharedImages().getImageDescriptor(
377:                                ISharedImages.IMG_TOOL_DELETE);
378:                ImageDescriptor addImage = ESBResourceManager
379:                        .getPluginImageDescriptor(Activator.getDefault(),
380:                                "icons/dialog/add.ico");
381:                newPageAction.setImageDescriptor(addImage);
382:                newPropertyAction.setImageDescriptor(addImage);
383:                removePageAction.setImageDescriptor(removeImage);
384:                removePropertyAction.setImageDescriptor(removeImage);
385:                //
386:                MenuManager popupMenu = new MenuManager();
387:                popupMenu.add(newPageAction);
388:                popupMenu.add(removePageAction);
389:                Menu menu = popupMenu.createContextMenu(table);
390:                table.setMenu(menu);
391:                //
392:                // setting menu for table_1
393:                MenuManager popupMenu_1 = new MenuManager();
394:                popupMenu_1.add(newPropertyAction);
395:                popupMenu_1.add(removePropertyAction);
396:                Menu menu_1 = popupMenu_1.createContextMenu(table_1);
397:                table_1.setMenu(menu_1);
398:                // setting content
399:                tableViewer.setInput(CONTENT_TABLE);
400:                table_1Viewer.setInput(CONTENT_TABLE_1);
401:
402:                // table.setSelection(0);
403:            }
404:
405:            @Override
406:            public void dispose() {
407:                super .dispose();
408:            }
409:
410:            @Override
411:            protected void checkSubclass() {
412:                // Disable the check that prevents subclassing of SWT components
413:            }
414:
415:            private void attachCellEditorsTable(final TableViewer viewer,
416:                    Composite parent) {
417:                viewer.setCellModifier(new ICellModifier() {
418:                    public boolean canModify(Object element, String property) {
419:                        return true;
420:                    }
421:
422:                    public Object getValue(Object element, String property) {
423:                        if (NAME_PROPERTY.equals(property))
424:                            return ((PagesModelTableItem) element).name;
425:                        else
426:                            return ((PagesModelTableItem) element).description;
427:                    }
428:
429:                    public void modify(Object element, String property,
430:                            Object value) {
431:                        TableItem tableItem = (TableItem) element;
432:                        PagesModelTableItem data = (PagesModelTableItem) tableItem
433:                                .getData();
434:                        // checkPageError(data);
435:                        if (value != null)
436:                            if (NAME_PROPERTY.equals(property)) {
437:                                data.name = value.toString();
438:                            } else
439:                                data.description = value.toString();
440:                        viewer.refresh();
441:                    }
442:                });
443:
444:                pageNameEditor = new TextCellEditor(parent);
445:
446:                // t.setValidator(new ICellEditorValidator()
447:                // {
448:                // public String isValid(Object value)
449:                // {
450:                // if ( "".equals(value.toString()) )
451:                // {
452:                // return "Name must not be Emplty!!!!";
453:                // }
454:                //                    
455:                // /*
456:                // TableItem[] selection=table.getSelection();
457:                // TableItem[] itemsArray=table.getItems();
458:                // if (table.getSelection().length!=0)
459:                // for (int i = 0; i < itemsArray.length; i++)
460:                // {
461:                // if (itemsArray[i] != table.getSelection()[0])
462:                // {
463:                // if (((PagesModelTableItem) itemsArray[i].getData()).name.equals
464:                // (((PagesModelTableItem) selection[0].getData()).name ))
465:                // {
466:                // return "Identical Name Found";
467:                // }
468:                // }
469:                // }
470:                // */
471:                // return null;
472:                // }}
473:                // );
474:                viewer.setCellEditors(new CellEditor[] { pageNameEditor,
475:                        new TextCellEditor(parent) });
476:
477:                viewer.setColumnProperties(new String[] { NAME_PROPERTY,
478:                        DESCRIPTION_PROPERTY });
479:            }
480:
481:            /*
482:             * protected void checkPageError(PagesModelTableItem value) { if
483:             * (value.name.trim().equals("")) { ERROR=UIErrorsEnum.EMPTY_NAME_PAGE;
484:             * return; } for (PagesModelTableItem page:pagesModelContent) { //check page
485:             * name if (page.name.equalsIgnoreCase(value.name)) if () {
486:             * ERROR=UIErrorsEnum.IDENTICAL_NAME_PAGE; return; } }
487:             * ERROR=UIErrorsEnum.NO_ERROR; }
488:             */
489:            private void attachCellEditorsTable1(final TableViewer viewer,
490:                    Composite parent) {
491:                viewer.setCellModifier(new ICellModifier() {
492:                    public boolean canModify(Object element, String property) {
493:                        return true;
494:                    }
495:
496:                    public Object getValue(Object element, String property) {
497:                        if (NAME_PROPERTY.equals(property))
498:                            return ((PropertiesModelTableItem) element).name;
499:                        if (TYPE_PROPERTY.equals(property))
500:                            return ((PropertiesModelTableItem) element).type;
501:                        if (REQUIRED_PROPERTY.equals(property))
502:                            return ((PropertiesModelTableItem) element).required;
503:                        if (READ_ONLY_PROPERTY.equals(property))
504:                            return ((PropertiesModelTableItem) element).readOnly;
505:                        else
506:                            return null;
507:                    }
508:
509:                    public void modify(Object element, String property,
510:                            Object value) {
511:
512:                        // //
513:                        // TableItem[] selection=table_1.getSelection();
514:                        // TableItem[] itemsArray=table_1.getItems();
515:                        // if (table_1.getSelection().length!=0)
516:                        // for (int i = 0; i < itemsArray.length; i++)
517:                        // {
518:                        // if (itemsArray[i] != table_1.getSelection()[0])
519:                        // {
520:                        // if (((PropertiesModelTableItem)
521:                        // itemsArray[i].getData()).name.equals
522:                        // (((PropertiesModelTableItem) selection[0].getData()).name ))
523:                        // {
524:                        // return;
525:                        // }
526:                        // }
527:                        // }
528:                        // //
529:
530:                        TableItem tableItem = (TableItem) element;
531:                        PropertiesModelTableItem data = (PropertiesModelTableItem) tableItem
532:                                .getData();
533:                        if (NAME_PROPERTY.equals(property))
534:                            data.name = (String) value;
535:                        if (TYPE_PROPERTY.equals(property))
536:                            data.type = (Integer) value;
537:                        if (REQUIRED_PROPERTY.equals(property))
538:                            data.required = (Boolean) value;
539:                        if (READ_ONLY_PROPERTY.equals(property))
540:                            data.readOnly = (Boolean) value;
541:                        viewer.refresh();
542:                        //
543:                    }
544:                });
545:
546:                propertyNameEditor = new TextCellEditor(parent);
547:
548:                // t.setValidator(new ICellEditorValidator()
549:                // {
550:                // public String isValid(Object value)
551:                // {
552:                // if ( "".equals(value.toString()) )
553:                // {
554:                // return "Name must not be Emplty!!!!";
555:                // }
556:                //                    
557:                // /*
558:                // TableItem[] selection=table.getSelection();
559:                // TableItem[] itemsArray=table.getItems();
560:                // if (table.getSelection().length!=0)
561:                // for (int i = 0; i < itemsArray.length; i++)
562:                // {
563:                // if (itemsArray[i] != table.getSelection()[0])
564:                // {
565:                // if (((PagesModelTableItem) itemsArray[i].getData()).name.equals
566:                // (((PagesModelTableItem) selection[0].getData()).name ))
567:                // {
568:                // return "Identical Name Found";
569:                // }
570:                // }
571:                // }
572:                // */
573:                // return null;
574:                // }}
575:                // );
576:
577:                viewer.setCellEditors(new CellEditor[] { propertyNameEditor,
578:                        new ComboBoxCellEditor(parent, TYPE_VALUE_SET),
579:                        new CheckboxCellEditor(parent),
580:                        new CheckboxCellEditor(parent) });
581:
582:                viewer.setColumnProperties(new String[] { NAME_PROPERTY,
583:                        TYPE_PROPERTY, REQUIRED_PROPERTY, READ_ONLY_PROPERTY });
584:            }
585:
586:            private void attachContentProvider(TableViewer viewer) {
587:                viewer.setContentProvider(new IStructuredContentProvider() {
588:                    public Object[] getElements(Object inputElement) {
589:                        return (Object[]) inputElement;
590:                        // return ((List) inputElement).toArray();
591:                    }
592:
593:                    public void dispose() {
594:                    }
595:
596:                    public void inputChanged(Viewer viewer, Object oldInput,
597:                            Object newInput) {
598:                    }
599:                });
600:            }
601:
602:            private void attachLabelProviderTable(TableViewer viewer) {
603:                viewer.setLabelProvider(new ITableLabelProvider() {
604:
605:                    public Image getColumnImage(Object element, int columnIndex) {
606:                        return null;
607:                    }
608:
609:                    public String getColumnText(Object element, int columnIndex) {
610:                        switch (columnIndex) {
611:                        case 0:
612:                            return ((PagesModelTableItem) element).name;
613:                        case 1:
614:                            return ((PagesModelTableItem) element).description;
615:                        default:
616:                            return "Invalid column: " + columnIndex;
617:                        }
618:                    }
619:
620:                    public void addListener(ILabelProviderListener listener) {
621:                    }
622:
623:                    public void dispose() {
624:                    }
625:
626:                    public boolean isLabelProperty(Object element,
627:                            String property) {
628:                        return false;
629:                    }
630:
631:                    public void removeListener(ILabelProviderListener listener) {
632:                    }
633:                });
634:            }
635:
636:            private void attachLabelProviderTable1(TableViewer viewer) {
637:                viewer.setLabelProvider(new ITableLabelProvider() {
638:
639:                    public Image getColumnImage(Object element, int columnIndex) {
640:                        return null;
641:                    }
642:
643:                    public String getColumnText(Object element, int columnIndex) {
644:                        switch (columnIndex) {
645:                        case 0:
646:                            return ((PropertiesModelTableItem) element).name;
647:                        case 1:
648:                            Number index = ((PropertiesModelTableItem) element).type;
649:                            return TYPE_VALUE_SET[index.intValue()];
650:                        case 2:
651:                            return ((PropertiesModelTableItem) element).required
652:                                    .toString();
653:                        case 3:
654:                            return ((PropertiesModelTableItem) element).readOnly
655:                                    .toString();
656:                        default:
657:                            return "Invalid column: " + columnIndex;
658:                        }
659:                    }
660:
661:                    public void addListener(ILabelProviderListener listener) {
662:                    }
663:
664:                    public void dispose() {
665:                    }
666:
667:                    public boolean isLabelProperty(Object element,
668:                            String property) {
669:                        return false;
670:                    }
671:
672:                    public void removeListener(ILabelProviderListener listener) {
673:                    }
674:                });
675:            }
676:
677:            private class NewRowTableAction extends Action {
678:                public NewRowTableAction() {
679:                    super ("Insert New Page");
680:                }
681:
682:                public void run() {
683:                    pagesCounter++;
684:                    PagesModelTableItem newItem = new PagesModelTableItem(
685:                            "page" + pagesCounter, "description",
686:                            new ArrayList<PropertiesModelTableItem>());
687:                    pagesModelContent.add(newItem);
688:                    CONTENT_TABLE = pagesModelContent.toArray();
689:                    tableViewer.setInput(CONTENT_TABLE);
690:                    // tableViewer.add(newItem);
691:                    if (table.getSelection().length == 0) {
692:                        table.select(0);
693:                    }
694:                    checkActionAvailability();
695:                }
696:            }
697:
698:            private class RemoveRowTableAction extends Action {
699:                public RemoveRowTableAction() {
700:                    super ("Remove Page");
701:                }
702:
703:                public void run() {
704:                    if (table.getSelection().length != 0) {
705:                        TableItem[] selectionArray = table.getSelection();
706:
707:                        for (int i = 0; i < selectionArray.length; i++) {
708:                            pagesModelContent.remove(selectionArray[i]
709:                                    .getData());
710:                        }
711:                        CONTENT_TABLE = pagesModelContent.toArray();
712:                        tableViewer.setInput(CONTENT_TABLE);
713:                        CONTENT_TABLE_1 = (new ArrayList<PropertiesModelTableItem>())
714:                                .toArray();
715:                        table_1Viewer.setInput(CONTENT_TABLE_1);
716:
717:                        // table.remove(table.getSelectionIndices());
718:                    }
719:                    checkActionAvailability();
720:                }
721:            }
722:
723:            private class NewRowTable1Action extends Action {
724:                public NewRowTable1Action() {
725:                    super ("Insert New Property");
726:                }
727:
728:                public void run() {
729:                    if (table.getSelection().length != 0) {
730:                        PagesModelTableItem pageItem = (PagesModelTableItem) ((TableItem) table
731:                                .getSelection()[0]).getData();
732:                        propertyesCounter++;
733:                        PropertiesModelTableItem newItem1 = new PropertiesModelTableItem(
734:                                "property" + propertyesCounter, new Integer(0),
735:                                new Boolean(false), new Boolean(false));
736:                        pageItem.properties.add(newItem1);
737:                        CONTENT_TABLE_1 = pageItem.properties.toArray();
738:                        table_1Viewer.setInput(CONTENT_TABLE_1);
739:                    }
740:                    checkActionAvailability();
741:                }
742:            }
743:
744:            private class RemoveRowTable1Action extends Action {
745:                public RemoveRowTable1Action() {
746:                    super ("Remove Property");
747:                }
748:
749:                public void run() {
750:                    // table.remove(table.getSelectionIndices());
751:                    if (table.getSelection().length != 0) {
752:                        PagesModelTableItem pageItem = (PagesModelTableItem) ((TableItem) table
753:                                .getSelection()[0]).getData();
754:
755:                        TableItem[] selectionArray = table_1.getSelection();
756:
757:                        for (int i = 0; i < selectionArray.length; i++) {
758:                            pageItem.properties.remove(selectionArray[i]
759:                                    .getData());
760:                        }
761:
762:                        CONTENT_TABLE_1 = pageItem.properties.toArray();
763:                        table_1Viewer.setInput(CONTENT_TABLE_1);
764:                    }
765:                    checkActionAvailability();
766:                }
767:            }
768:
769:            public List<PagesModelTableItem> getPages() {
770:                return pagesModelContent;
771:            }
772:
773:            /**
774:             * @return the pageNameEditor
775:             */
776:            public TextCellEditor getPageNameEditor() {
777:                return pageNameEditor;
778:            }
779:
780:            /**
781:             * @return the propertyNameEditor
782:             */
783:            public TextCellEditor getPropertyNameEditor() {
784:                return propertyNameEditor;
785:            }
786:
787:            public boolean isTableValid() {
788:                for (PagesModelTableItem pageOne : pagesModelContent) {
789:                    int count = 0;
790:                    for (PagesModelTableItem pageTwo : pagesModelContent) {
791:                        if (pageOne.name.equalsIgnoreCase(pageTwo.name)) {
792:                            count++;
793:                        }
794:                    }
795:                    if (count > 1) {
796:                        ERROR = UIErrorsEnum.IDENTICAL_NAME_PAGE;
797:                        return false;
798:                    }
799:                }
800:                ERROR = UIErrorsEnum.NO_ERROR;
801:                return true;
802:            }
803:
804:            public boolean isTable1Valid() {
805:                List<PropertiesModelTableItem> plist = new ArrayList<PropertiesModelTableItem>();
806:                for (PagesModelTableItem pages : pagesModelContent)
807:                    for (PropertiesModelTableItem prop : pages.properties) {
808:                        plist.add(prop);
809:                    }
810:                //
811:                for (PropertiesModelTableItem propOne : plist) {
812:                    int count = 0;
813:                    for (PropertiesModelTableItem propTwo : plist) {
814:                        if (propOne.name.equalsIgnoreCase(propTwo.name)) {
815:                            count++;
816:                        }
817:                    }
818:                    if (count > 1) {
819:                        ERROR = UIErrorsEnum.IDENTICAL_NAME_PROPERTY;
820:                        return false;
821:                    }
822:                }
823:                ERROR = UIErrorsEnum.NO_ERROR;
824:                return true;
825:            }
826:
827:            private void checkActionAvailability() {
828:                if (CONTENT_TABLE.length == 0) {
829:                    newItemToolItem_1.setEnabled(false);
830:                    newItemToolItem_2.setEnabled(false);
831:                    newItemToolItem_3.setEnabled(false);
832:                } else {
833:                    newItemToolItem_1.setEnabled(true);
834:                    newItemToolItem_2.setEnabled(true);
835:                    if (CONTENT_TABLE_1.length == 0) {
836:                        newItemToolItem_3.setEnabled(false);
837:                    } else {
838:                        newItemToolItem_3.setEnabled(true);
839:                    }
840:                }
841:
842:            }
843:        }
844:
845:        /**
846:         * @author LPS
847:         * This class represents UI data class for PROPERTIES table 
848:         */
849:
850:        class PropertiesModelTableItem {
851:            public String name;
852:
853:            public Integer type;
854:
855:            public Boolean required;
856:
857:            public Boolean readOnly;
858:
859:            public PropertiesModelTableItem(String n, Integer t, Boolean r,
860:                    Boolean ro) {
861:                name = n;
862:                type = t;
863:                required = r;
864:                readOnly = ro;
865:            }
866:
867:            @Override
868:            public boolean equals(Object obj) {
869:                if (obj instanceof  PropertiesModelTableItem) {
870:                    return (((PropertiesModelTableItem) obj).name.equals(name)
871:                            && ((PropertiesModelTableItem) obj).type
872:                                    .equals(type)
873:                            && ((PropertiesModelTableItem) obj).readOnly
874:                                    .equals(readOnly) && ((PropertiesModelTableItem) obj).required
875:                            .equals(required));
876:                }
877:                return super .equals(obj);
878:            }
879:        }
880:
881:        /**
882:         * @author LPS
883:         * This class represents UI data class for PAGES table 
884:         */
885:        class PagesModelTableItem {
886:            public String name;
887:
888:            public String description;
889:
890:            public List<PropertiesModelTableItem> properties;
891:
892:            // public Object[] properties;
893:            public PagesModelTableItem(String n, String d,
894:                    List<PropertiesModelTableItem> p) {
895:                name = n;
896:                description = d;
897:                properties = p;
898:            }
899:
900:            @Override
901:            public boolean equals(Object obj) {
902:                if (obj instanceof  PagesModelTableItem) {
903:                    return (((PagesModelTableItem) obj).name.equals(name)
904:                            && ((PagesModelTableItem) obj).description
905:                                    .equals(description) && ((PagesModelTableItem) obj).properties
906:                            .equals(properties));
907:                }
908:                return super.equals(obj);
909:            }
910:        }
ww__w_.j___ava2__s___._co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.