Source Code Cross Referenced for ExternalSystemNameEditPart.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.ExternalSystem;
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 ExternalSystemNameEditPart extends
063:                AbstractGraphicalEditPart {
064:
065:            /**
066:             * @generated
067:             */
068:            public static final int VISUAL_ID = 5007;
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 ExternalSystemNameEditPart(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:                                ExternalSystem element = resolveSemanticElement();
135:                                EAttribute feature = (EAttribute) componentflowPackage.eINSTANCE
136:                                        .getBaseElement_Name();
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
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:                ExternalSystem 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:                ExternalSystem 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(ExternalSystem element,
244:                    String pattern) {
245:                if (element.getName() == null) {
246:                    return defaultText;
247:                }
248:                return MessageFormat.format(pattern, new Object[] { element
249:                        .getName() });
250:            }
251:
252:            /**
253:             * @generated
254:             */
255:            protected void refreshFont() {
256:                FontStyle style = (FontStyle) getUpdatableParent()
257:                        .getDiagramNode().getStyle(
258:                                NotationPackage.eINSTANCE.getFontStyle());
259:                Font toDispose = createdFont;
260:                if (style != null) {
261:                    String fontName = style.getFontName();
262:                    int fontHeight = style.getFontHeight();
263:                    int fontStyle = SWT.NORMAL;
264:                    if (style.isBold()) {
265:                        fontStyle |= SWT.BOLD;
266:                    }
267:                    if (style.isItalic()) {
268:                        fontStyle |= SWT.ITALIC;
269:                    }
270:                    Font currentFont = getFigure().getFont();
271:                    if (currentFont != null) {
272:                        FontData currentFontData = currentFont.getFontData()[0];
273:                        if (currentFontData.getName().equals(fontName)
274:                                && currentFontData.getHeight() == fontHeight
275:                                && currentFontData.getStyle() == fontStyle) {
276:                            return;
277:                        }
278:                    }
279:                    createdFont = new Font(null, fontName, fontHeight,
280:                            fontStyle);
281:                    getFigure().setFont(createdFont);
282:                } else {
283:                    //revert to the default font
284:                    getFigure().setFont(getViewer().getControl().getFont());
285:                    createdFont = null;
286:                }
287:                if (toDispose != null) {
288:                    toDispose.dispose();
289:                }
290:            }
291:
292:            /**
293:             * The font (created by {@link #refreshFont()}) currently assigned to the label (unless the default font is assigned).
294:             * Whenever another non-default font is assigned to it, it is safe to dispose the previous one.
295:             * @generated
296:             */
297:            private Font createdFont;
298:
299:            /**
300:             * @generated
301:             */
302:            protected void refreshFontColor() {
303:                FontStyle style = (FontStyle) getUpdatableParent()
304:                        .getDiagramNode().getStyle(
305:                                NotationPackage.eINSTANCE.getFontStyle());
306:                Color toDispose = createdFontColor;
307:                if (style != null) {
308:                    int fontColor = style.getFontColor();
309:                    int red = fontColor & 0x000000FF;
310:                    int green = (fontColor & 0x0000FF00) >> 8;
311:                    int blue = (fontColor & 0x00FF0000) >> 16;
312:                    Color currentColor = getLabel().getForegroundColor();
313:                    if (currentColor != null && currentColor.getRed() == red
314:                            && currentColor.getGreen() == green
315:                            && currentColor.getBlue() == blue) {
316:                        return;
317:                    }
318:                    createdFontColor = new Color(null, red, green, blue);
319:                    getFigure().setForegroundColor(createdFontColor);
320:                } else {
321:                    getFigure().setForegroundColor(
322:                            getViewer().getControl().getForeground());
323:                    createdFontColor = null;
324:                }
325:                if (toDispose != null) {
326:                    toDispose.dispose();
327:                }
328:            }
329:
330:            /**
331:             * The color (created by {@link #refreshFontColor()}) currently assigned to the label.
332:             * Whenever another color is assigned to it, it is safe to dispose the previous one.
333:             * @generated
334:             */
335:            private Color createdFontColor;
336:
337:            /**
338:             * @generated NOT
339:             */
340:            protected Image getLabelIcon() {
341:                /*ExternalSystem element = resolveSemanticElement();
342:                 ImageDescriptor imageDescriptor = ComponentFlowEditorDiagramEditorPlugin
343:                 .getInstance().getItemImageDescriptor(element);
344:                 if (imageDescriptor != null) {
345:                 return imageDescriptor.createImage();
346:                 }
347:                 return ImageDescriptor.getMissingImageDescriptor().createImage();*/
348:                return null;
349:            }
350:
351:            /**
352:             * @generated
353:             */
354:            private ExternalSystem resolveSemanticElement() {
355:                for (EditPart editPart = this ; editPart != null; editPart = editPart
356:                        .getParent()) {
357:                    View view = (View) editPart.getModel();
358:                    if (view != null && view.getElement() != null) {
359:                        return (ExternalSystem) view.getElement();
360:                    }
361:                }
362:                return null;
363:            }
364:
365:            /**
366:             * @generated
367:             */
368:            private ExternalSystemEditPart getUpdatableParent() {
369:                for (EditPart editPart = getParent(); editPart != null; editPart = editPart
370:                        .getParent()) {
371:                    if (editPart instanceof  ExternalSystemEditPart) {
372:                        return (ExternalSystemEditPart) editPart;
373:                    }
374:                }
375:                return null;
376:            }
377:
378:            /**
379:             * @generated
380:             */
381:            public void activate() {
382:                super .activate();
383:                ExternalSystemEditPart updatableParent = getUpdatableParent();
384:                if (updatableParent != null) {
385:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
386:                            .getFontStyle_FontColor(), fontColorRefresher);
387:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
388:                            .getFontStyle_FontHeight(), fontRefresher);
389:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
390:                            .getFontStyle_FontName(), fontRefresher);
391:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
392:                            .getFontStyle_Bold(), fontRefresher);
393:                    updatableParent.addRefresher(NotationPackage.eINSTANCE
394:                            .getFontStyle_Italic(), fontRefresher);
395:                    updatableParent.addRefresher(componentflowPackage.eINSTANCE
396:                            .getBaseElement_Name(), labelRefresher);
397:                }
398:            }
399:
400:            /**
401:             * @generated
402:             */
403:            public void deactivate() {
404:                super .deactivate();
405:                ExternalSystemEditPart updatableParent = getUpdatableParent();
406:                if (updatableParent != null) {
407:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
408:                            .getFontStyle_FontColor(), fontColorRefresher);
409:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
410:                            .getFontStyle_FontHeight(), fontRefresher);
411:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
412:                            .getFontStyle_FontName(), fontRefresher);
413:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
414:                            .getFontStyle_Bold(), fontRefresher);
415:                    updatableParent.removeRefresher(NotationPackage.eINSTANCE
416:                            .getFontStyle_Italic(), fontRefresher);
417:                    updatableParent.removeRefresher(
418:                            componentflowPackage.eINSTANCE
419:                                    .getBaseElement_Name(), 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:        }
w__w__w___.j___a_v_a___2__s_.___com__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.