Source Code Cross Referenced for CommentDescriptionEditPart.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » ui » componentflow » componentFlowEditor » diagram » edit » parts » 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.componentflow.componentFlowEditor.diagram.edit.parts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts;
002:
003:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.Comment;
004:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.componentflowPackage;
005:
006:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditorPlugin;
007:
008:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.providers.ComponentFlowEditorAbstractParser;
009:
010:        import java.text.MessageFormat;
011:        import java.text.ParseException;
012:
013:        import org.eclipse.draw2d.IFigure;
014:        import org.eclipse.draw2d.Label;
015:
016:        import org.eclipse.draw2d.geometry.Rectangle;
017:
018:        import org.eclipse.emf.ecore.EAttribute;
019:
020:        import org.eclipse.emf.edit.command.SetCommand;
021:
022:        import org.eclipse.emf.transaction.TransactionalEditingDomain;
023:
024:        import org.eclipse.emf.transaction.util.TransactionUtil;
025:
026:        import org.eclipse.gef.EditPart;
027:        import org.eclipse.gef.EditPolicy;
028:        import org.eclipse.gef.Request;
029:        import org.eclipse.gef.RequestConstants;
030:
031:        import org.eclipse.gef.commands.Command;
032:        import org.eclipse.gef.commands.UnexecutableCommand;
033:
034:        import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
035:
036:        import org.eclipse.gef.editpolicies.DirectEditPolicy;
037:
038:        import org.eclipse.gef.requests.DirectEditRequest;
039:
040:        import org.eclipse.gef.tools.CellEditorLocator;
041:        import org.eclipse.gef.tools.DirectEditManager;
042:
043:        import org.eclipse.gmf.runtime.notation.FontStyle;
044:        import org.eclipse.gmf.runtime.notation.NotationPackage;
045:        import org.eclipse.gmf.runtime.notation.View;
046:
047:        import org.eclipse.jface.resource.ImageDescriptor;
048:
049:        import org.eclipse.jface.viewers.CellEditor;
050:        import org.eclipse.jface.viewers.TextCellEditor;
051:
052:        import org.eclipse.swt.SWT;
053:
054:        import org.eclipse.swt.graphics.Color;
055:        import org.eclipse.swt.graphics.Font;
056:        import org.eclipse.swt.graphics.FontData;
057:        import org.eclipse.swt.graphics.Image;
058:
059:        /**
060:         * @generated
061:         */
062:        public class CommentDescriptionEditPart extends
063:                AbstractGraphicalEditPart {
064:
065:            /**
066:             * @generated
067:             */
068:            public static final int VISUAL_ID = 5013;
069:
070:            /**
071:             * @generated
072:             */
073:            private DirectEditManager manager;
074:
075:            /**
076:             * @generated
077:             */
078:            private String defaultText;
079:
080:            /**
081:             * @generated
082:             */
083:            public CommentDescriptionEditPart(View view) {
084:                setModel(view);
085:            }
086:
087:            /**
088:             * @generated NOT
089:             */
090:            protected void createEditPolicies() {
091:                installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE,
092:                        new DirectEditPolicy() {
093:                            protected void showCurrentEditValue(
094:                                    DirectEditRequest request) {
095:                                String value = (String) request.getCellEditor()
096:                                        .getValue();
097:                                getLabel().setText(value);
098:                            }
099:
100:                            protected Command getDirectEditCommand(
101:                                    DirectEditRequest request) {
102:                                String value = (String) request.getCellEditor()
103:                                        .getValue();
104:                                if (value == null) {
105:                                    //Invalid value is transformed into a null by the validator.
106:                                    //XXX: implement validator
107:                                    return UnexecutableCommand.INSTANCE;
108:                                }
109:                                final Object[] parseResult;
110:                                try {
111:                                    parseResult = new MessageFormat(
112:                                            EDIT_PATTERN).parse(value);
113:                                } catch (IllegalArgumentException e) {
114:                                    return UnexecutableCommand.INSTANCE;
115:                                } catch (ParseException e) {
116:                                    return UnexecutableCommand.INSTANCE;
117:                                }
118:                                TransactionalEditingDomain editingDomain = TransactionUtil
119:                                        .getEditingDomain(getUpdatableParent()
120:                                                .getDiagramNode().getDiagram()
121:                                                .getElement());
122:                                if (parseResult.length != 1) {
123:                                    return UnexecutableCommand.INSTANCE;
124:                                }
125:                                org.eclipse.emf.common.command.Command domainModelCommand = createDomainModelCommand(
126:                                        editingDomain, parseResult[0]);
127:                                return new WrappingCommand(editingDomain,
128:                                        domainModelCommand);
129:                            }
130:
131:                            org.eclipse.emf.common.command.Command createDomainModelCommand(
132:                                    TransactionalEditingDomain editingDomain,
133:                                    Object value) {
134:                                Comment element = resolveSemanticElement();
135:                                EAttribute feature = (EAttribute) componentflowPackage.eINSTANCE
136:                                        .getBaseElement_Description();
137:                                Object valueToSet;
138:                                try {
139:                                    valueToSet = ComponentFlowEditorAbstractParser
140:                                            .parseValue(feature, value);
141:                                } catch (IllegalArgumentException e) {
142:                                    return org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
143:                                }
144:                                return SetCommand.create(editingDomain,
145:                                        element, feature, valueToSet);
146:                            }
147:                        });
148:            }
149:
150:            /**
151:             * @generated
152:             */
153:            public void performRequest(Request req) {
154:                if (RequestConstants.REQ_DIRECT_EDIT == req.getType()) {
155:                    performDirectEdit();
156:                } else {
157:                    super .performRequest(req);
158:                }
159:            }
160:
161:            /**
162:             * @generated
163:             */
164:            protected DirectEditManager getManager() {
165:                if (manager == null) {
166:                    manager = new DirectEditManager(this , TextCellEditor.class,
167:                            new CellEditorLocator() {
168:                                public void relocate(CellEditor celleditor) {
169:                                    Rectangle rect = getLabel().getTextBounds();
170:                                    getLabel().translateToAbsolute(rect);
171:                                    celleditor.getControl().setBounds(rect.x,
172:                                            rect.y, rect.width, rect.height);
173:                                }
174:                            }) {
175:                        protected void initCellEditor() {
176:                            getCellEditor().setValue(getLabelEditText());
177:                        }
178:                    };
179:                }
180:                return manager;
181:            }
182:
183:            /**
184:             * @generated NOT
185:             */
186:            protected void performDirectEdit() {
187:                //getManager().show();
188:            }
189:
190:            /**
191:             * @generated
192:             */
193:            protected void refreshVisuals() {
194:                super .refreshVisuals();
195:                refreshLabel();
196:                refreshFont();
197:                refreshFontColor();
198:            }
199:
200:            /**
201:             * @generated
202:             */
203:            protected void refreshLabel() {
204:                getLabel().setText(getLabelText());
205:                getLabel().setIcon(getLabelIcon());
206:            }
207:
208:            /**
209:             * @generated
210:             */
211:            private static final String VIEW_PATTERN = "{0}";
212:
213:            /**
214:             * @generated
215:             */
216:            private static final String EDIT_PATTERN = "{0}";
217:
218:            /**
219:             * @generated
220:             */
221:            protected String getLabelText() {
222:                Comment element = resolveSemanticElement();
223:                if (element == null) {
224:                    return defaultText;
225:                }
226:                return buildTextByPattern(element, VIEW_PATTERN);
227:            }
228:
229:            /**
230:             * @generated
231:             */
232:            protected String getLabelEditText() {
233:                Comment element = resolveSemanticElement();
234:                if (element == null) {
235:                    return defaultText;
236:                }
237:                return buildTextByPattern(element, EDIT_PATTERN);
238:            }
239:
240:            /**
241:             * @generated
242:             */
243:            protected String buildTextByPattern(Comment element, String pattern) {
244:                if (element.getDescription() == null) {
245:                    return defaultText;
246:                }
247:                return MessageFormat.format(pattern, new Object[] { element
248:                        .getDescription() });
249:            }
250:
251:            /**
252:             * @generated
253:             */
254:            protected void refreshFont() {
255:                FontStyle style = (FontStyle) getUpdatableParent()
256:                        .getDiagramNode().getStyle(
257:                                NotationPackage.eINSTANCE.getFontStyle());
258:                Font toDispose = createdFont;
259:                if (style != null) {
260:                    String fontName = style.getFontName();
261:                    int fontHeight = style.getFontHeight();
262:                    int fontStyle = SWT.NORMAL;
263:                    if (style.isBold()) {
264:                        fontStyle |= SWT.BOLD;
265:                    }
266:                    if (style.isItalic()) {
267:                        fontStyle |= SWT.ITALIC;
268:                    }
269:                    Font currentFont = getFigure().getFont();
270:                    if (currentFont != null) {
271:                        FontData currentFontData = currentFont.getFontData()[0];
272:                        if (currentFontData.getName().equals(fontName)
273:                                && currentFontData.getHeight() == fontHeight
274:                                && currentFontData.getStyle() == fontStyle) {
275:                            return;
276:                        }
277:                    }
278:                    createdFont = new Font(null, fontName, fontHeight,
279:                            fontStyle);
280:                    getFigure().setFont(createdFont);
281:                } else {
282:                    //revert to the default font
283:                    getFigure().setFont(getViewer().getControl().getFont());
284:                    createdFont = null;
285:                }
286:                if (toDispose != null) {
287:                    toDispose.dispose();
288:                }
289:            }
290:
291:            /**
292:             * The font (created by {@link #refreshFont()}) currently assigned to the label (unless the default font is assigned).
293:             * Whenever another non-default font is assigned to it, it is safe to dispose the previous one.
294:             * @generated
295:             */
296:            private Font createdFont;
297:
298:            /**
299:             * @generated
300:             */
301:            protected void refreshFontColor() {
302:                FontStyle style = (FontStyle) getUpdatableParent()
303:                        .getDiagramNode().getStyle(
304:                                NotationPackage.eINSTANCE.getFontStyle());
305:                Color toDispose = createdFontColor;
306:                if (style != null) {
307:                    int fontColor = style.getFontColor();
308:                    int red = fontColor & 0x000000FF;
309:                    int green = (fontColor & 0x0000FF00) >> 8;
310:                    int blue = (fontColor & 0x00FF0000) >> 16;
311:                    Color currentColor = getLabel().getForegroundColor();
312:                    if (currentColor != null && currentColor.getRed() == red
313:                            && currentColor.getGreen() == green
314:                            && currentColor.getBlue() == blue) {
315:                        return;
316:                    }
317:                    createdFontColor = new Color(null, red, green, blue);
318:                    getFigure().setForegroundColor(createdFontColor);
319:                } else {
320:                    getFigure().setForegroundColor(
321:                            getViewer().getControl().getForeground());
322:                    createdFontColor = null;
323:                }
324:                if (toDispose != null) {
325:                    toDispose.dispose();
326:                }
327:            }
328:
329:            /**
330:             * The color (created by {@link #refreshFontColor()}) currently assigned to the label.
331:             * Whenever another color is assigned to it, it is safe to dispose the previous one.
332:             * @generated
333:             */
334:            private Color createdFontColor;
335:
336:            /**
337:             * @generated NOT
338:             */
339:            protected Image getLabelIcon() {
340:                /*Comment element = resolveSemanticElement();
341:                 ImageDescriptor imageDescriptor = ComponentFlowEditorDiagramEditorPlugin
342:                 .getInstance().getItemImageDescriptor(element);
343:                 if (imageDescriptor != null) {
344:                 return imageDescriptor.createImage();
345:                 }
346:                 return ImageDescriptor.getMissingImageDescriptor().createImage();*/
347:                return null;
348:            }
349:
350:            /**
351:             * @generated
352:             */
353:            private Comment resolveSemanticElement() {
354:                for (EditPart editPart = this ; editPart != null; editPart = editPart
355:                        .getParent()) {
356:                    View view = (View) editPart.getModel();
357:                    if (view != null && view.getElement() != null) {
358:                        return (Comment) view.getElement();
359:                    }
360:                }
361:                return null;
362:            }
363:
364:            /**
365:             * @generated
366:             */
367:            private CommentEditPart getUpdatableParent() {
368:                for (EditPart editPart = getParent(); editPart != null; editPart = editPart
369:                        .getParent()) {
370:                    if (editPart instanceof  CommentEditPart) {
371:                        return (CommentEditPart) editPart;
372:                    }
373:                }
374:                return null;
375:            }
376:
377:            /**
378:             * @generated
379:             */
380:            public void activate() {
381:                super .activate();
382:                CommentEditPart updatableParent = getUpdatableParent();
383:                if (updatableParent != null) {
384:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
385:                            .getFontStyle_FontColor(), fontColorRefresher);
386:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
387:                            .getFontStyle_FontHeight(), fontRefresher);
388:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
389:                            .getFontStyle_FontName(), fontRefresher);
390:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
391:                            .getFontStyle_Bold(), fontRefresher);
392:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
393:                            .getFontStyle_Italic(), fontRefresher);
394:                    updatableParent.addRefresher(componentflowPackage.eINSTANCE
395:                            .getBaseElement_Description(), labelRefresher);
396:                }
397:            }
398:
399:            /**
400:             * @generated
401:             */
402:            public void deactivate() {
403:                super .deactivate();
404:                CommentEditPart updatableParent = getUpdatableParent();
405:                if (updatableParent != null) {
406:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
407:                            .getFontStyle_FontColor(), fontColorRefresher);
408:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
409:                            .getFontStyle_FontHeight(), fontRefresher);
410:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
411:                            .getFontStyle_FontName(), fontRefresher);
412:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
413:                            .getFontStyle_Bold(), fontRefresher);
414:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
415:                            .getFontStyle_Italic(), fontRefresher);
416:                    updatableParent.removeRefresher(
417:                            componentflowPackage.eINSTANCE
418:                                    .getBaseElement_Description(),
419:                            labelRefresher);
420:                }
421:            }
422:
423:            /**
424:             * @generated
425:             */
426:            private IUpdatableEditPart.Refresher labelRefresher = new IUpdatableEditPart.Refresher() {
427:                public void refresh() {
428:                    refreshLabel();
429:                }
430:            };
431:
432:            /**
433:             * @generated
434:             */
435:            private IUpdatableEditPart.Refresher fontColorRefresher = new IUpdatableEditPart.Refresher() {
436:                public void refresh() {
437:                    refreshFontColor();
438:                }
439:            };
440:
441:            /**
442:             * @generated
443:             */
444:            private IUpdatableEditPart.Refresher fontRefresher = new IUpdatableEditPart.Refresher() {
445:                public void refresh() {
446:                    refreshFont();
447:                }
448:            };
449:
450:            /**
451:             * @generated
452:             */
453:            protected IFigure createFigure() {
454:                // Parent should assign one using setLabel method
455:                return null;
456:            }
457:
458:            /**
459:             * @generated
460:             */
461:            public Label getLabel() {
462:                return (Label) getFigure();
463:            }
464:
465:            /**
466:             * @generated
467:             */
468:            public void setLabel(Label figure) {
469:                unregisterVisuals();
470:                setFigure(figure);
471:                defaultText = figure.getText();
472:                registerVisuals();
473:                refreshVisuals();
474:            }
475:
476:        }
ww___w__.j___a___v__a__2__s__.___c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.