Source Code Cross Referenced for LocksPanel.java in  » Net » Terracotta » org » terracotta » dso » editors » 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 » Net » Terracotta » org.terracotta.dso.editors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package org.terracotta.dso.editors;
006:
007:        import org.eclipse.core.resources.IProject;
008:        import org.eclipse.swt.SWT;
009:        import org.eclipse.swt.events.SelectionAdapter;
010:        import org.eclipse.swt.events.SelectionEvent;
011:        import org.eclipse.swt.layout.GridData;
012:        import org.eclipse.swt.layout.GridLayout;
013:        import org.eclipse.swt.widgets.Button;
014:        import org.eclipse.swt.widgets.Composite;
015:        import org.eclipse.swt.widgets.Event;
016:        import org.eclipse.swt.widgets.Label;
017:        import org.eclipse.swt.widgets.Listener;
018:        import org.eclipse.swt.widgets.Table;
019:        import org.eclipse.swt.widgets.TableColumn;
020:        import org.eclipse.swt.widgets.TableItem;
021:        import org.terracotta.dso.editors.chooser.ExpressionChooser;
022:        import org.terracotta.dso.editors.chooser.MethodBehavior;
023:        import org.terracotta.dso.editors.chooser.NavigatorBehavior;
024:        import org.terracotta.ui.util.SWTUtil;
025:
026:        import com.tc.util.event.UpdateEvent;
027:        import com.tc.util.event.UpdateEventListener;
028:        import com.terracottatech.config.Autolock;
029:        import com.terracottatech.config.DsoApplication;
030:        import com.terracottatech.config.LockLevel;
031:        import com.terracottatech.config.Locks;
032:        import com.terracottatech.config.NamedLock;
033:
034:        public class LocksPanel extends ConfigurationEditorPanel {
035:            private IProject m_project;
036:            private DsoApplication m_dsoApp;
037:            private Locks m_locks;
038:
039:            private Layout m_layout;
040:
041:            private TableSelectionListener m_tableSelectionListener;
042:            private TableDataListener m_tableDataListener;
043:            private AddLockHandler m_addLockHandler;
044:            private RemoveLockHandler m_removeLockHandler;
045:
046:            public LocksPanel(Composite parent, int style) {
047:                super (parent, style);
048:                m_layout = new Layout(this );
049:                m_tableSelectionListener = new TableSelectionListener();
050:                m_tableDataListener = new TableDataListener();
051:                m_addLockHandler = new AddLockHandler();
052:                m_removeLockHandler = new RemoveLockHandler();
053:            }
054:
055:            public boolean hasAnySet() {
056:                return m_locks != null
057:                        && (m_locks.sizeOfAutolockArray() > 0 || m_locks
058:                                .sizeOfNamedLockArray() > 0);
059:            }
060:
061:            private Locks ensureLocks() {
062:                if (m_locks == null) {
063:                    ensureXmlObject();
064:                }
065:                return m_locks;
066:            }
067:
068:            public void ensureXmlObject() {
069:                super .ensureXmlObject();
070:
071:                if (m_locks == null) {
072:                    removeListeners();
073:                    m_locks = m_dsoApp.addNewLocks();
074:                    updateChildren();
075:                    addListeners();
076:                }
077:            }
078:
079:            private void testRemoveLocks() {
080:                if (!hasAnySet() && m_dsoApp.getLocks() != null) {
081:                    m_dsoApp.unsetLocks();
082:                    m_locks = null;
083:                    fireXmlObjectStructureChanged(m_dsoApp);
084:                }
085:                testDisableRemoveButtons();
086:            }
087:
088:            private void testDisableRemoveButtons() {
089:                m_layout.m_removeAutoLockButton
090:                        .setEnabled(m_layout.m_autoLocksTable
091:                                .getSelectionCount() > 0);
092:                m_layout.m_removeNamedLockButton
093:                        .setEnabled(m_layout.m_namedLocksTable
094:                                .getSelectionCount() > 0);
095:            }
096:
097:            private void addListeners() {
098:                m_layout.m_addAutoLockButton
099:                        .addSelectionListener(m_addLockHandler);
100:                m_layout.m_removeAutoLockButton
101:                        .addSelectionListener(m_removeLockHandler);
102:                m_layout.m_autoLocksTable
103:                        .addSelectionListener(m_tableSelectionListener);
104:                m_layout.m_autoLocksTable.addListener(SWT.SetData,
105:                        m_tableDataListener);
106:
107:                m_layout.m_addNamedLockButton
108:                        .addSelectionListener(m_addLockHandler);
109:                m_layout.m_removeNamedLockButton
110:                        .addSelectionListener(m_removeLockHandler);
111:                m_layout.m_namedLocksTable
112:                        .addSelectionListener(m_tableSelectionListener);
113:                m_layout.m_namedLocksTable.addListener(SWT.SetData,
114:                        m_tableDataListener);
115:            }
116:
117:            private void removeListeners() {
118:                m_layout.m_addAutoLockButton
119:                        .removeSelectionListener(m_addLockHandler);
120:                m_layout.m_removeAutoLockButton
121:                        .removeSelectionListener(m_removeLockHandler);
122:                m_layout.m_autoLocksTable
123:                        .removeSelectionListener(m_tableSelectionListener);
124:                m_layout.m_autoLocksTable.removeListener(SWT.SetData,
125:                        m_tableDataListener);
126:
127:                m_layout.m_addNamedLockButton
128:                        .removeSelectionListener(m_addLockHandler);
129:                m_layout.m_removeNamedLockButton
130:                        .removeSelectionListener(m_removeLockHandler);
131:                m_layout.m_namedLocksTable
132:                        .removeSelectionListener(m_tableSelectionListener);
133:                m_layout.m_namedLocksTable.removeListener(SWT.SetData,
134:                        m_tableDataListener);
135:            }
136:
137:            public void updateChildren() {
138:                initTableItems();
139:                testDisableRemoveButtons();
140:            }
141:
142:            public void updateModel() {
143:                removeListeners();
144:                updateChildren();
145:                addListeners();
146:            }
147:
148:            public void setup(IProject project, DsoApplication dsoApp) {
149:                setEnabled(true);
150:                removeListeners();
151:
152:                m_project = project;
153:                m_dsoApp = dsoApp;
154:                m_locks = m_dsoApp != null ? m_dsoApp.getLocks() : null;
155:
156:                updateChildren();
157:                addListeners();
158:            }
159:
160:            public void tearDown() {
161:                removeListeners();
162:
163:                m_project = null;
164:                m_dsoApp = null;
165:                m_locks = null;
166:
167:                setEnabled(false);
168:            }
169:
170:            private void initTableItems() {
171:                initAutolockTableItems();
172:                initNamedLockTableItems();
173:            }
174:
175:            private void initAutolockTableItems() {
176:                m_layout.m_autoLocksTable.removeAll();
177:
178:                if (m_locks == null)
179:                    return;
180:                String[] autolockLevels = getListDefaults(Autolock.class,
181:                        "lock-level");
182:                SWTUtil.makeTableComboItem(m_layout.m_autoLocksTable,
183:                        Layout.AUTO_LOCK_COLUMN, autolockLevels);
184:                SWTUtil.makeTableComboItem(m_layout.m_autoLocksTable,
185:                        Layout.AUTO_SYNCHRONIZED_COLUMN, new String[] { "true",
186:                                "false" });
187:                Autolock[] autolocks = m_locks.getAutolockArray();
188:                for (int i = 0; i < autolocks.length; i++) {
189:                    createAutolockTableItem(autolocks[i]);
190:                }
191:                if (autolocks.length > 0) {
192:                    m_layout.m_autoLocksTable.setSelection(0);
193:                }
194:            }
195:
196:            private void initNamedLockTableItems() {
197:                m_layout.m_namedLocksTable.removeAll();
198:
199:                if (m_locks == null)
200:                    return;
201:                String[] namedLockLevels = getListDefaults(NamedLock.class,
202:                        "lock-level");
203:                SWTUtil.makeTableComboItem(m_layout.m_namedLocksTable,
204:                        Layout.NAMED_LOCK_COLUMN, namedLockLevels);
205:                NamedLock[] namedLocks = m_locks.getNamedLockArray();
206:                for (int i = 0; i < namedLocks.length; i++) {
207:                    createNamedLockTableItem(namedLocks[i]);
208:                }
209:                if (namedLocks.length > 0) {
210:                    m_layout.m_namedLocksTable.setSelection(0);
211:                }
212:            }
213:
214:            private void initAutolockTableItem(TableItem item, Autolock lock) {
215:                item.setText(Layout.AUTO_METHOD_COLUMN, lock
216:                        .getMethodExpression());
217:                item.setText(Layout.AUTO_LOCK_COLUMN,
218:                        lock.isSetLockLevel() ? lock.getLockLevel().toString()
219:                                : "");
220:                item.setText(Layout.AUTO_SYNCHRONIZED_COLUMN, lock
221:                        .isSetAutoSynchronized() ? Boolean.toString(lock
222:                        .getAutoSynchronized()) : "false");
223:            }
224:
225:            private void updateAutolockTableItem(int index) {
226:                TableItem item = m_layout.m_autoLocksTable.getItem(index);
227:                initAutolockTableItem(item, (Autolock) item.getData());
228:            }
229:
230:            private void createAutolockTableItem(Autolock lock) {
231:                TableItem item = new TableItem(m_layout.m_autoLocksTable,
232:                        SWT.NONE);
233:                initAutolockTableItem(item, lock);
234:                item.setData(lock);
235:            }
236:
237:            private void initNamedLockTableItem(TableItem item, NamedLock lock) {
238:                item.setText(Layout.NAMED_NAME_COLUMN, lock.getLockName());
239:                item.setText(Layout.NAMED_METHOD_COLUMN, lock
240:                        .getMethodExpression());
241:                item.setText(Layout.NAMED_LOCK_COLUMN,
242:                        lock.isSetLockLevel() ? lock.getLockLevel().toString()
243:                                : "");
244:            }
245:
246:            private void updateNamedLockTableItem(int index) {
247:                TableItem item = m_layout.m_namedLocksTable.getItem(index);
248:                initNamedLockTableItem(item, (NamedLock) item.getData());
249:            }
250:
251:            private void createNamedLockTableItem(NamedLock lock) {
252:                TableItem item = new TableItem(m_layout.m_namedLocksTable,
253:                        SWT.NONE);
254:                initNamedLockTableItem(item, lock);
255:                item.setData(lock);
256:            }
257:
258:            private void internalAddAutolock(String expression) {
259:                internalAddAutolock(expression, LockLevel.WRITE);
260:            }
261:
262:            private void internalAddAutolock(String expression,
263:                    LockLevel.Enum level) {
264:                Locks locks = ensureLocks();
265:                Autolock lock = locks.addNewAutolock();
266:
267:                lock.setMethodExpression(expression);
268:                lock.setLockLevel(level);
269:                createAutolockTableItem(lock);
270:
271:                int row = m_layout.m_autoLocksTable.getItemCount() - 1;
272:                m_layout.m_autoLocksTable.select(row);
273:            }
274:
275:            private void internalAddNamedLock(String expression) {
276:                internalAddNamedLock(expression, "NewLock", LockLevel.WRITE);
277:            }
278:
279:            private void internalAddNamedLock(String expression, String name,
280:                    LockLevel.Enum level) {
281:                Locks locks = ensureLocks();
282:                NamedLock lock = locks.addNewNamedLock();
283:
284:                lock.setMethodExpression(expression);
285:                lock.setLockName(name);
286:                lock.setLockLevel(level);
287:                createNamedLockTableItem(lock);
288:
289:                int row = m_layout.m_namedLocksTable.getItemCount() - 1;
290:                m_layout.m_namedLocksTable.select(row);
291:            }
292:
293:            private static class Layout {
294:
295:                private static final String AUTO_LOCKS = "Auto Locks";
296:                private static final String NAMED_LOCKS = "Named Locks";
297:                private static final String LOCK_NAME = "Lock Name";
298:                private static final String METHOD_EXPRESSION = "Method Expression";
299:                private static final String LOCK_LEVEL = "Lock Level";
300:                private static final String AUTO_SYNCHRONIZED = "Auto Synchronized";
301:                private static final String ADD = "Add...";
302:                private static final String REMOVE = "Remove";
303:
304:                private static final int AUTO_METHOD_COLUMN = 0;
305:                private static final int AUTO_LOCK_COLUMN = 1;
306:                private static final int AUTO_SYNCHRONIZED_COLUMN = 2;
307:
308:                private static final int NAMED_NAME_COLUMN = 0;
309:                private static final int NAMED_METHOD_COLUMN = 1;
310:                private static final int NAMED_LOCK_COLUMN = 2;
311:
312:                private Table m_autoLocksTable;
313:                private Button m_addAutoLockButton;
314:                private Button m_removeAutoLockButton;
315:                private Table m_namedLocksTable;
316:                private Button m_addNamedLockButton;
317:                private Button m_removeNamedLockButton;
318:
319:                public void reset() {
320:                    m_removeAutoLockButton.setEnabled(false);
321:                    m_autoLocksTable.removeAll();
322:                    m_removeNamedLockButton.setEnabled(false);
323:                    m_namedLocksTable.removeAll();
324:                }
325:
326:                private Layout(Composite parent) {
327:                    Composite comp = new Composite(parent, SWT.NONE);
328:                    GridLayout gridLayout = new GridLayout();
329:                    gridLayout.marginWidth = gridLayout.marginHeight = 0;
330:                    comp.setLayout(gridLayout);
331:
332:                    createAutoLocksPanel(comp);
333:                    createNamedLocksPanel(comp);
334:                }
335:
336:                private void createAutoLocksPanel(Composite parent) {
337:                    Composite comp = new Composite(parent, SWT.NONE);
338:                    GridLayout gridLayout = new GridLayout(2, false);
339:                    gridLayout.marginWidth = gridLayout.marginHeight = 10;
340:                    comp.setLayout(gridLayout);
341:                    comp.setLayoutData(new GridData(GridData.FILL_BOTH));
342:
343:                    Composite sidePanel = new Composite(comp, SWT.NONE);
344:                    gridLayout = new GridLayout();
345:                    gridLayout.marginWidth = gridLayout.marginHeight = 0;
346:                    sidePanel.setLayout(gridLayout);
347:                    sidePanel.setLayoutData(new GridData(GridData.FILL_BOTH));
348:
349:                    Label label = new Label(sidePanel, SWT.NONE);
350:                    label.setText(AUTO_LOCKS);
351:                    label.setLayoutData(new GridData(
352:                            GridData.VERTICAL_ALIGN_BEGINNING));
353:
354:                    m_autoLocksTable = new Table(sidePanel, SWT.BORDER
355:                            | SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL);
356:                    m_autoLocksTable.setHeaderVisible(true);
357:                    m_autoLocksTable.setLinesVisible(true);
358:                    SWTUtil.makeTableColumnsResizeWeightedWidth(sidePanel,
359:                            m_autoLocksTable, new int[] { 3, 1, 1 });
360:                    SWTUtil.makeTableColumnsEditable(m_autoLocksTable,
361:                            new int[] { AUTO_METHOD_COLUMN,
362:                                    AUTO_SYNCHRONIZED_COLUMN });
363:                    GridData gridData = new GridData(GridData.FILL_BOTH);
364:                    gridData.heightHint = SWTUtil.tableRowsToPixels(
365:                            m_autoLocksTable, 3);
366:                    m_autoLocksTable.setLayoutData(gridData);
367:
368:                    TableColumn methodCol = new TableColumn(m_autoLocksTable,
369:                            SWT.NONE, AUTO_METHOD_COLUMN);
370:                    methodCol.setResizable(true);
371:                    methodCol.setText(METHOD_EXPRESSION);
372:                    methodCol.pack();
373:
374:                    TableColumn lockCol = new TableColumn(m_autoLocksTable,
375:                            SWT.NONE, AUTO_LOCK_COLUMN);
376:                    lockCol.setResizable(true);
377:                    lockCol.setText(LOCK_LEVEL);
378:                    lockCol.pack();
379:
380:                    TableColumn autoSyncCol = new TableColumn(m_autoLocksTable,
381:                            SWT.NONE, AUTO_SYNCHRONIZED_COLUMN);
382:                    autoSyncCol.setResizable(true);
383:                    autoSyncCol.setText(AUTO_SYNCHRONIZED);
384:                    autoSyncCol.pack();
385:
386:                    Composite buttonPanel = new Composite(comp, SWT.NONE);
387:                    gridLayout = new GridLayout();
388:                    gridLayout.marginWidth = gridLayout.marginHeight = 0;
389:                    buttonPanel.setLayout(gridLayout);
390:                    buttonPanel.setLayoutData(new GridData(
391:                            GridData.VERTICAL_ALIGN_BEGINNING));
392:
393:                    new Label(buttonPanel, SWT.NONE); // filler
394:
395:                    m_addAutoLockButton = new Button(buttonPanel, SWT.PUSH);
396:                    m_addAutoLockButton.setText(ADD);
397:                    m_addAutoLockButton.setLayoutData(new GridData(
398:                            GridData.VERTICAL_ALIGN_END));
399:                    SWTUtil.applyDefaultButtonSize(m_addAutoLockButton);
400:
401:                    m_removeAutoLockButton = new Button(buttonPanel, SWT.PUSH);
402:                    m_removeAutoLockButton.setText(REMOVE);
403:                    m_removeAutoLockButton.setEnabled(false);
404:                    m_removeAutoLockButton.setLayoutData(new GridData(
405:                            GridData.VERTICAL_ALIGN_BEGINNING));
406:                    SWTUtil.applyDefaultButtonSize(m_removeAutoLockButton);
407:                }
408:
409:                private void createNamedLocksPanel(Composite parent) {
410:                    Composite comp = new Composite(parent, SWT.NONE);
411:                    GridLayout gridLayout = new GridLayout(2, false);
412:                    gridLayout.marginWidth = gridLayout.marginHeight = 10;
413:                    comp.setLayout(gridLayout);
414:                    comp.setLayoutData(new GridData(GridData.FILL_BOTH));
415:
416:                    Composite sidePanel = new Composite(comp, SWT.NONE);
417:                    gridLayout = new GridLayout();
418:                    gridLayout.marginWidth = gridLayout.marginHeight = 0;
419:                    sidePanel.setLayout(gridLayout);
420:                    sidePanel.setLayoutData(new GridData(GridData.FILL_BOTH));
421:
422:                    Label label = new Label(sidePanel, SWT.NONE);
423:                    label.setText(NAMED_LOCKS);
424:                    label.setLayoutData(new GridData(
425:                            GridData.VERTICAL_ALIGN_BEGINNING));
426:
427:                    m_namedLocksTable = new Table(sidePanel, SWT.BORDER
428:                            | SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL);
429:                    m_namedLocksTable.setHeaderVisible(true);
430:                    m_namedLocksTable.setLinesVisible(true);
431:                    SWTUtil.makeTableColumnsResizeWeightedWidth(sidePanel,
432:                            m_namedLocksTable, new int[] { 1, 2, 1 });
433:                    SWTUtil
434:                            .makeTableColumnsEditable(m_namedLocksTable,
435:                                    new int[] { NAMED_NAME_COLUMN,
436:                                            NAMED_METHOD_COLUMN });
437:                    GridData gridData = new GridData(GridData.FILL_BOTH);
438:                    gridData.heightHint = SWTUtil.tableRowsToPixels(
439:                            m_namedLocksTable, 3);
440:                    m_namedLocksTable.setLayoutData(gridData);
441:
442:                    TableColumn lockNameCol = new TableColumn(
443:                            m_namedLocksTable, SWT.NONE, NAMED_NAME_COLUMN);
444:                    lockNameCol.setResizable(true);
445:                    lockNameCol.setText(LOCK_NAME);
446:                    lockNameCol.pack();
447:
448:                    TableColumn methodCol = new TableColumn(m_namedLocksTable,
449:                            SWT.NONE, NAMED_METHOD_COLUMN);
450:                    methodCol.setResizable(true);
451:                    methodCol.setText(METHOD_EXPRESSION);
452:                    methodCol.pack();
453:
454:                    TableColumn lockLevelCol = new TableColumn(
455:                            m_namedLocksTable, SWT.NONE, NAMED_LOCK_COLUMN);
456:                    lockLevelCol.setResizable(true);
457:                    lockLevelCol.setText(LOCK_LEVEL);
458:                    lockLevelCol.pack();
459:
460:                    Composite buttonPanel = new Composite(comp, SWT.NONE);
461:                    gridLayout = new GridLayout();
462:                    gridLayout.marginWidth = gridLayout.marginHeight = 0;
463:                    buttonPanel.setLayout(gridLayout);
464:                    buttonPanel.setLayoutData(new GridData(
465:                            GridData.VERTICAL_ALIGN_BEGINNING));
466:
467:                    new Label(buttonPanel, SWT.NONE); // filler
468:
469:                    m_addNamedLockButton = new Button(buttonPanel, SWT.PUSH);
470:                    m_addNamedLockButton.setText(ADD);
471:                    m_addNamedLockButton.setLayoutData(new GridData(
472:                            GridData.VERTICAL_ALIGN_END));
473:                    SWTUtil.applyDefaultButtonSize(m_addNamedLockButton);
474:
475:                    m_removeNamedLockButton = new Button(buttonPanel, SWT.PUSH);
476:                    m_removeNamedLockButton.setText(REMOVE);
477:                    m_removeNamedLockButton.setEnabled(false);
478:                    m_removeNamedLockButton.setLayoutData(new GridData(
479:                            GridData.VERTICAL_ALIGN_BEGINNING));
480:                    SWTUtil.applyDefaultButtonSize(m_removeNamedLockButton);
481:                }
482:            }
483:
484:            class AddLockHandler extends SelectionAdapter {
485:                public void widgetSelected(SelectionEvent e) {
486:                    if (e.widget == m_layout.m_addAutoLockButton) {
487:                        m_layout.m_autoLocksTable.forceFocus();
488:                        NavigatorBehavior behavior = new MethodBehavior();
489:                        ExpressionChooser chooser = new ExpressionChooser(
490:                                getShell(), behavior.getTitle(),
491:                                MethodBehavior.ADD_MSG, m_project, behavior);
492:                        chooser.addValueListener(new UpdateEventListener() {
493:                            public void handleUpdate(UpdateEvent updateEvent) {
494:                                String[] items = (String[]) updateEvent.data;
495:                                for (int i = 0; i < items.length; i++) {
496:                                    internalAddAutolock(items[i]);
497:                                }
498:                                fireAutolocksChanged();
499:                            }
500:                        });
501:                        chooser.open();
502:                    } else if (e.widget == m_layout.m_addNamedLockButton) {
503:                        m_layout.m_namedLocksTable.forceFocus();
504:                        NavigatorBehavior behavior = new MethodBehavior();
505:                        ExpressionChooser chooser = new ExpressionChooser(
506:                                getShell(), behavior.getTitle(),
507:                                MethodBehavior.ADD_MSG, m_project, behavior);
508:                        chooser.addValueListener(new UpdateEventListener() {
509:                            public void handleUpdate(UpdateEvent updateEvent) {
510:                                String[] items = (String[]) updateEvent.data;
511:                                for (int i = 0; i < items.length; i++) {
512:                                    internalAddNamedLock(items[i]);
513:                                }
514:                                fireNamedLocksChanged();
515:                            }
516:                        });
517:                        chooser.open();
518:                    }
519:                }
520:            }
521:
522:            class RemoveLockHandler extends SelectionAdapter {
523:                public void widgetSelected(SelectionEvent e) {
524:                    if (e.widget == m_layout.m_removeAutoLockButton) {
525:                        m_layout.m_autoLocksTable.forceFocus();
526:                        int[] selection = m_layout.m_autoLocksTable
527:                                .getSelectionIndices();
528:
529:                        for (int i = selection.length - 1; i >= 0; i--) {
530:                            m_locks.removeAutolock(selection[i]);
531:                        }
532:                        m_layout.m_autoLocksTable.remove(selection);
533:                        fireAutolocksChanged();
534:                    } else if (e.widget == m_layout.m_removeNamedLockButton) {
535:                        m_layout.m_namedLocksTable.forceFocus();
536:                        int[] selection = m_layout.m_namedLocksTable
537:                                .getSelectionIndices();
538:
539:                        for (int i = selection.length - 1; i >= 0; i--) {
540:                            m_locks.removeNamedLock(selection[i]);
541:                        }
542:                        m_layout.m_namedLocksTable.remove(selection);
543:                        fireNamedLocksChanged();
544:                    }
545:                    testRemoveLocks();
546:                }
547:            }
548:
549:            class TableSelectionListener extends SelectionAdapter {
550:                public void widgetSelected(SelectionEvent e) {
551:                    if (e.widget == m_layout.m_autoLocksTable) {
552:                        m_layout.m_removeAutoLockButton.setEnabled(true);
553:                    } else if (e.widget == m_layout.m_namedLocksTable) {
554:                        m_layout.m_removeNamedLockButton.setEnabled(true);
555:                    }
556:                }
557:            }
558:
559:            class TableDataListener implements  Listener {
560:                public void handleEvent(Event e) {
561:                    TableItem item = (TableItem) e.item;
562:                    String text = item.getText(e.index).trim();
563:                    int index = ((Table) e.widget).getSelectionIndex();
564:
565:                    if (e.widget == m_layout.m_autoLocksTable) {
566:                        Autolock lock = (Autolock) item.getData();
567:
568:                        if (e.index == Layout.AUTO_SYNCHRONIZED_COLUMN) {
569:                            boolean autoSync = Boolean.parseBoolean(text);
570:                            if (autoSync)
571:                                lock.setAutoSynchronized(true);
572:                            else
573:                                lock.unsetAutoSynchronized();
574:                        } else if (e.index == Layout.AUTO_METHOD_COLUMN) {
575:                            if (text.length() == 0) {
576:                                item.setText(lock.getMethodExpression());
577:                                removeAutolockLater(index);
578:                                return;
579:                            } else {
580:                                lock.setMethodExpression(text);
581:                            }
582:                        } else {
583:                            lock.xgetLockLevel().setStringValue(text);
584:                        }
585:                        fireAutolockChanged(index);
586:                    } else if (e.widget == m_layout.m_namedLocksTable) {
587:                        NamedLock lock = (NamedLock) item.getData();
588:
589:                        if (e.index == Layout.NAMED_NAME_COLUMN) {
590:                            if (text.length() == 0) {
591:                                item.setText(lock.getLockName());
592:                                removeNamedLockLater(index);
593:                                return;
594:                            } else {
595:                                lock.setLockName(text);
596:                            }
597:                        } else if (e.index == Layout.NAMED_METHOD_COLUMN) {
598:                            if (text.length() == 0) {
599:                                item.setText(lock.getMethodExpression());
600:                                removeNamedLockLater(index);
601:                                return;
602:                            } else {
603:                                lock.setMethodExpression(text);
604:                            }
605:                        } else {
606:                            lock.xgetLockLevel().setStringValue(text);
607:                        }
608:                        fireNamedLockChanged(index);
609:                    }
610:                }
611:            }
612:
613:            private void removeAutolockLater(final int index) {
614:                getDisplay().asyncExec(new Runnable() {
615:                    public void run() {
616:                        m_locks.removeAutolock(index);
617:                        m_layout.m_autoLocksTable.remove(index);
618:                        fireAutolocksChanged();
619:                        testRemoveLocks();
620:                    }
621:                });
622:            }
623:
624:            private void removeNamedLockLater(final int index) {
625:                getDisplay().asyncExec(new Runnable() {
626:                    public void run() {
627:                        m_locks.removeNamedLock(index);
628:                        m_layout.m_namedLocksTable.remove(index);
629:                        fireAutolocksChanged();
630:                        testRemoveLocks();
631:                    }
632:                });
633:            }
634:
635:            public void namedLockChanged(IProject project, int index) {
636:                if (project.equals(getProject())) {
637:                    updateNamedLockTableItem(index);
638:                }
639:            }
640:
641:            public void autolockChanged(IProject project, int index) {
642:                if (project.equals(getProject())) {
643:                    updateAutolockTableItem(index);
644:                }
645:            }
646:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.