001: package org.enhydra.jawe.base.tooltip;
002:
003: import java.lang.reflect.Method;
004: import java.util.Iterator;
005: import java.util.Map;
006:
007: import org.enhydra.jawe.JaWEComponent;
008: import org.enhydra.jawe.JaWEConstants;
009: import org.enhydra.jawe.JaWEManager;
010: import org.enhydra.jawe.ResourceManager;
011: import org.enhydra.jawe.Settings;
012: import org.enhydra.jawe.base.display.DisplayNameGenerator;
013: import org.enhydra.jawe.base.label.LabelGenerator;
014: import org.enhydra.shark.utilities.SequencedHashMap;
015: import org.enhydra.shark.xpdl.XMLAttribute;
016: import org.enhydra.shark.xpdl.XMLCollection;
017: import org.enhydra.shark.xpdl.XMLCollectionElement;
018: import org.enhydra.shark.xpdl.XMLComplexChoice;
019: import org.enhydra.shark.xpdl.XMLComplexElement;
020: import org.enhydra.shark.xpdl.XMLElement;
021: import org.enhydra.shark.xpdl.XMLEmptyChoiceElement;
022: import org.enhydra.shark.xpdl.XMLSimpleElement;
023: import org.enhydra.shark.xpdl.elements.Activities;
024: import org.enhydra.shark.xpdl.elements.Activity;
025: import org.enhydra.shark.xpdl.elements.ActivitySet;
026: import org.enhydra.shark.xpdl.elements.ActivitySets;
027: import org.enhydra.shark.xpdl.elements.ActivityTypes;
028: import org.enhydra.shark.xpdl.elements.ActualParameter;
029: import org.enhydra.shark.xpdl.elements.ActualParameters;
030: import org.enhydra.shark.xpdl.elements.Application;
031: import org.enhydra.shark.xpdl.elements.ApplicationTypes;
032: import org.enhydra.shark.xpdl.elements.Applications;
033: import org.enhydra.shark.xpdl.elements.ArrayType;
034: import org.enhydra.shark.xpdl.elements.Author;
035: import org.enhydra.shark.xpdl.elements.Automatic;
036: import org.enhydra.shark.xpdl.elements.BasicType;
037: import org.enhydra.shark.xpdl.elements.BlockActivity;
038: import org.enhydra.shark.xpdl.elements.Codepage;
039: import org.enhydra.shark.xpdl.elements.Condition;
040: import org.enhydra.shark.xpdl.elements.ConformanceClass;
041: import org.enhydra.shark.xpdl.elements.Cost;
042: import org.enhydra.shark.xpdl.elements.CostUnit;
043: import org.enhydra.shark.xpdl.elements.Countrykey;
044: import org.enhydra.shark.xpdl.elements.Created;
045: import org.enhydra.shark.xpdl.elements.DataField;
046: import org.enhydra.shark.xpdl.elements.DataFields;
047: import org.enhydra.shark.xpdl.elements.DataType;
048: import org.enhydra.shark.xpdl.elements.DataTypes;
049: import org.enhydra.shark.xpdl.elements.Deadline;
050: import org.enhydra.shark.xpdl.elements.DeadlineCondition;
051: import org.enhydra.shark.xpdl.elements.Deadlines;
052: import org.enhydra.shark.xpdl.elements.DeclaredType;
053: import org.enhydra.shark.xpdl.elements.Description;
054: import org.enhydra.shark.xpdl.elements.Documentation;
055: import org.enhydra.shark.xpdl.elements.Duration;
056: import org.enhydra.shark.xpdl.elements.EnumerationType;
057: import org.enhydra.shark.xpdl.elements.EnumerationValue;
058: import org.enhydra.shark.xpdl.elements.ExceptionName;
059: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
060: import org.enhydra.shark.xpdl.elements.ExtendedAttributes;
061: import org.enhydra.shark.xpdl.elements.ExternalPackage;
062: import org.enhydra.shark.xpdl.elements.ExternalPackages;
063: import org.enhydra.shark.xpdl.elements.ExternalReference;
064: import org.enhydra.shark.xpdl.elements.FinishMode;
065: import org.enhydra.shark.xpdl.elements.FormalParameter;
066: import org.enhydra.shark.xpdl.elements.FormalParameters;
067: import org.enhydra.shark.xpdl.elements.Icon;
068: import org.enhydra.shark.xpdl.elements.Implementation;
069: import org.enhydra.shark.xpdl.elements.ImplementationTypes;
070: import org.enhydra.shark.xpdl.elements.InitialValue;
071: import org.enhydra.shark.xpdl.elements.Join;
072: import org.enhydra.shark.xpdl.elements.Length;
073: import org.enhydra.shark.xpdl.elements.Limit;
074: import org.enhydra.shark.xpdl.elements.ListType;
075: import org.enhydra.shark.xpdl.elements.Manual;
076: import org.enhydra.shark.xpdl.elements.Member;
077: import org.enhydra.shark.xpdl.elements.Namespace;
078: import org.enhydra.shark.xpdl.elements.Namespaces;
079: import org.enhydra.shark.xpdl.elements.No;
080: import org.enhydra.shark.xpdl.elements.PackageHeader;
081: import org.enhydra.shark.xpdl.elements.Participant;
082: import org.enhydra.shark.xpdl.elements.ParticipantType;
083: import org.enhydra.shark.xpdl.elements.Participants;
084: import org.enhydra.shark.xpdl.elements.Performer;
085: import org.enhydra.shark.xpdl.elements.Priority;
086: import org.enhydra.shark.xpdl.elements.PriorityUnit;
087: import org.enhydra.shark.xpdl.elements.ProcessHeader;
088: import org.enhydra.shark.xpdl.elements.RecordType;
089: import org.enhydra.shark.xpdl.elements.RedefinableHeader;
090: import org.enhydra.shark.xpdl.elements.Responsible;
091: import org.enhydra.shark.xpdl.elements.Responsibles;
092: import org.enhydra.shark.xpdl.elements.Route;
093: import org.enhydra.shark.xpdl.elements.SchemaType;
094: import org.enhydra.shark.xpdl.elements.Script;
095: import org.enhydra.shark.xpdl.elements.SimulationInformation;
096: import org.enhydra.shark.xpdl.elements.Split;
097: import org.enhydra.shark.xpdl.elements.StartFinishModes;
098: import org.enhydra.shark.xpdl.elements.StartMode;
099: import org.enhydra.shark.xpdl.elements.SubFlow;
100: import org.enhydra.shark.xpdl.elements.TimeEstimation;
101: import org.enhydra.shark.xpdl.elements.Tool;
102: import org.enhydra.shark.xpdl.elements.Tools;
103: import org.enhydra.shark.xpdl.elements.Transition;
104: import org.enhydra.shark.xpdl.elements.TransitionRef;
105: import org.enhydra.shark.xpdl.elements.TransitionRefs;
106: import org.enhydra.shark.xpdl.elements.TransitionRestriction;
107: import org.enhydra.shark.xpdl.elements.TransitionRestrictions;
108: import org.enhydra.shark.xpdl.elements.Transitions;
109: import org.enhydra.shark.xpdl.elements.TypeDeclaration;
110: import org.enhydra.shark.xpdl.elements.TypeDeclarations;
111: import org.enhydra.shark.xpdl.elements.UnionType;
112: import org.enhydra.shark.xpdl.elements.ValidFrom;
113: import org.enhydra.shark.xpdl.elements.ValidTo;
114: import org.enhydra.shark.xpdl.elements.Vendor;
115: import org.enhydra.shark.xpdl.elements.Version;
116: import org.enhydra.shark.xpdl.elements.WaitingTime;
117: import org.enhydra.shark.xpdl.elements.WorkflowProcess;
118: import org.enhydra.shark.xpdl.elements.WorkflowProcesses;
119: import org.enhydra.shark.xpdl.elements.WorkingTime;
120: import org.enhydra.shark.xpdl.elements.XPDLVersion;
121:
122: /**
123: * Used to generate tooltips for representing XPDL entities.
124: *
125: * @author Sasa Bojanic
126: */
127: public class StandardTooltipGenerator implements TooltipGenerator {
128:
129: /** Used for tooltips */
130: public static final String EMPTY_STRING = "";
131:
132: /** Used for tooltips */
133: public static final String HTML_OPEN = "<html>";
134:
135: /** Used for tooltips */
136: public static final String HTML_CLOSE = "</html>";
137:
138: /** Used for tooltips */
139: public static final String STRONG_OPEN = "<strong>";
140:
141: /** Used for tooltips */
142: public static final String STRONG_CLOSE = "</strong>";
143:
144: /** Used for tooltips */
145: public static final String LINE_BREAK = "<br>";
146:
147: /** Used for tooltips */
148: public static final String COLON_SPACE = ": ";
149:
150: protected TooltipGeneratorSettings settings;
151:
152: public StandardTooltipGenerator() {
153: settings = new TooltipGeneratorSettings();
154: settings.init((JaWEComponent) null);
155: }
156:
157: public StandardTooltipGenerator(TooltipGeneratorSettings settings) {
158: this .settings = settings;
159: this .settings.init((JaWEComponent) null);
160: }
161:
162: public String getTooltip(Activities el) {
163: return generateStandardTooltip(el);
164: }
165:
166: public String getTooltip(Activity el) {
167: LabelGenerator lg = JaWEManager.getInstance()
168: .getLabelGenerator();
169: Map toDisplay = new SequencedHashMap();
170: putKeyValue(toDisplay, el.get("Id"));
171: putKeyValue(toDisplay, el.get("Name"));
172: putKeyValue(toDisplay, el.get("Description"));
173: putKeyValue(toDisplay, el.get("Performer"));
174: putKeyValue(toDisplay, el.getStartMode());
175: putKeyValue(toDisplay, el.getFinishMode());
176: putKeyValue(toDisplay, el.get("Priority"));
177: putKeyValue(toDisplay, el.get("Limit"));
178: if (el.getTransitionRestrictions().size() > 0) {
179: TransitionRestriction tr = (TransitionRestriction) el
180: .getTransitionRestrictions().get(0);
181: putKeyValue(toDisplay, tr.getJoin());
182: putKeyValue(toDisplay, tr.getSplit());
183: } else {
184: toDisplay.put(lg.getLabel(new Join(null)), "");
185: toDisplay.put(lg.getLabel(new Split(null)), "");
186: }
187: fillTypePartOfTooltip(el, toDisplay);
188: return makeTooltip(toDisplay);
189: }
190:
191: protected void fillTypePartOfTooltip(Activity el, Map toDisplay) {
192: LabelGenerator lg = JaWEManager.getInstance()
193: .getLabelGenerator();
194: String label, key;
195: label = lg.getLabel(el.getActivityTypes());
196:
197: String type = JaWEManager.getInstance().getJaWEController()
198: .getTypeResolver().getJaWEType(el).getTypeId();
199: key = settings.getLanguageDependentString(type); // lg.getLabel(tp);
200: if (key == null || key.equals("")) {
201: key = type;
202: }
203: toDisplay.put(label, key);
204:
205: if (type.equals(JaWEConstants.ACTIVITY_TYPE_TOOL)) {
206: label = settings.getLanguageDependentString("NoOfToolsKey");
207: key = String.valueOf(el.getActivityTypes()
208: .getImplementation().getImplementationTypes()
209: .getTools().size());
210: toDisplay.put(label, key);
211: }
212: if (type.equals(JaWEConstants.ACTIVITY_TYPE_SUBFLOW)) {
213: label = settings
214: .getLanguageDependentString("ReferencedProcessKey");
215: key = el.getActivityTypes().getImplementation()
216: .getImplementationTypes().getSubFlow().getId();
217: if (key.equals("")) {
218: key = settings.getLanguageDependentString("NoneKey");
219: }
220: toDisplay.put(label, key);
221: }
222: if (type.equals(JaWEConstants.ACTIVITY_TYPE_ROUTE)) {
223: // tpSpecific=new XMLElement("Condition");
224: // tpSpecific.setValue(getLoop().get("Condition").toString());
225: }
226: if (type.equals(JaWEConstants.ACTIVITY_TYPE_BLOCK)) {
227: label = settings
228: .getLanguageDependentString("ReferencedActivitySetKey");
229: key = el.getActivityTypes().getBlockActivity().getBlockId();
230: if (key.equals("")) {
231: key = settings.getLanguageDependentString("NoneKey");
232: }
233: toDisplay.put(label, key);
234: }
235: }
236:
237: public String getTooltip(ActivitySet el) {
238: return generateStandardTooltip(el);
239: }
240:
241: public String getTooltip(ActivitySets el) {
242: return generateStandardTooltip(el);
243: }
244:
245: public String getTooltip(ActivityTypes el) {
246: return generateStandardTooltip(el);
247: }
248:
249: public String getTooltip(ActualParameter el) {
250: return generateStandardTooltip(el);
251: }
252:
253: public String getTooltip(ActualParameters el) {
254: return generateStandardTooltip(el);
255: }
256:
257: public String getTooltip(Application el) {
258: return generateStandardTooltip(el);
259: }
260:
261: public String getTooltip(Applications el) {
262: return generateStandardTooltip(el);
263: }
264:
265: public String getTooltip(ApplicationTypes el) {
266: return generateStandardTooltip(el);
267: }
268:
269: public String getTooltip(ArrayType el) {
270: return ResourceManager.getLanguageDependentString("SubTypeKey");
271: // return generateStandardLabel(el);
272: }
273:
274: public String getTooltip(Author el) {
275: return generateStandardTooltip(el);
276: }
277:
278: public String getTooltip(Automatic el) {
279: return generateStandardTooltip(el);
280: }
281:
282: public String getTooltip(BasicType el) {
283: return ResourceManager.getLanguageDependentString("SubTypeKey");
284: }
285:
286: public String getTooltip(BlockActivity el) {
287: return generateStandardTooltip(el);
288: }
289:
290: public String getTooltip(Codepage el) {
291: return generateStandardTooltip(el);
292: }
293:
294: public String getTooltip(Condition el) {
295: return generateStandardTooltip(el);
296: }
297:
298: public String getTooltip(ConformanceClass el) {
299: return generateStandardTooltip(el);
300: }
301:
302: public String getTooltip(Cost el) {
303: return generateStandardTooltip(el);
304: }
305:
306: public String getTooltip(CostUnit el) {
307: return generateStandardTooltip(el);
308: }
309:
310: public String getTooltip(Countrykey el) {
311: return generateStandardTooltip(el);
312: }
313:
314: public String getTooltip(Created el) {
315: return generateStandardTooltip(el);
316: }
317:
318: public String getTooltip(DataField el) {
319: return generateStandardTooltip(el);
320: }
321:
322: public String getTooltip(DataFields el) {
323: return generateStandardTooltip(el);
324: }
325:
326: public String getTooltip(DataType el) {
327: return generateStandardTooltip(el);
328: }
329:
330: public String getTooltip(DataTypes el) {
331: return generateStandardTooltip(el);
332: }
333:
334: public String getTooltip(Deadline el) {
335: return generateStandardTooltip(el);
336: }
337:
338: public String getTooltip(DeadlineCondition el) {
339: return generateStandardTooltip(el);
340: }
341:
342: public String getTooltip(Deadlines el) {
343: return generateStandardTooltip(el);
344: }
345:
346: public String getTooltip(DeclaredType el) {
347: return ResourceManager.getLanguageDependentString("SubTypeKey");
348: }
349:
350: public String getTooltip(Description el) {
351: return generateStandardTooltip(el);
352: }
353:
354: public String getTooltip(Documentation el) {
355: return generateStandardTooltip(el);
356: }
357:
358: public String getTooltip(Duration el) {
359: return generateStandardTooltip(el);
360: }
361:
362: public String getTooltip(EnumerationType el) {
363: return generateStandardTooltip(el);
364: }
365:
366: public String getTooltip(EnumerationValue el) {
367: return generateStandardTooltip(el);
368: }
369:
370: public String getTooltip(ExceptionName el) {
371: return generateStandardTooltip(el);
372: }
373:
374: public String getTooltip(ExtendedAttribute el) {
375: return generateStandardTooltip(el);
376: }
377:
378: public String getTooltip(ExtendedAttributes el) {
379: return generateStandardTooltip(el);
380: }
381:
382: public String getTooltip(ExternalPackage el) {
383: return generateStandardTooltip(el);
384: }
385:
386: public String getTooltip(ExternalPackages el) {
387: return generateStandardTooltip(el);
388: }
389:
390: public String getTooltip(ExternalReference el) {
391: return generateStandardTooltip(el);
392: }
393:
394: public String getTooltip(FinishMode el) {
395: return generateStandardTooltip(el);
396: }
397:
398: public String getTooltip(FormalParameter el) {
399: return generateStandardTooltip(el);
400: }
401:
402: public String getTooltip(FormalParameters el) {
403: return generateStandardTooltip(el);
404: }
405:
406: public String getTooltip(Icon el) {
407: return generateStandardTooltip(el);
408: }
409:
410: public String getTooltip(Implementation el) {
411: return generateStandardTooltip(el);
412: }
413:
414: public String getTooltip(ImplementationTypes el) {
415: return generateStandardTooltip(el);
416: }
417:
418: public String getTooltip(InitialValue el) {
419: return generateStandardTooltip(el);
420: }
421:
422: public String getTooltip(Join el) {
423: return ResourceManager
424: .getLanguageDependentString("JoinTypeKey");
425: }
426:
427: public String getTooltip(Length el) {
428: return generateStandardTooltip(el);
429: }
430:
431: public String getTooltip(Limit el) {
432: return generateStandardTooltip(el);
433: }
434:
435: public String getTooltip(ListType el) {
436: return ResourceManager.getLanguageDependentString("SubTypeKey");
437: }
438:
439: public String getTooltip(Manual el) {
440: return generateStandardTooltip(el);
441: }
442:
443: public String getTooltip(Member el) {
444: return generateStandardTooltip(el);
445: }
446:
447: public String getTooltip(Namespace el) {
448: return generateStandardTooltip(el);
449: }
450:
451: public String getTooltip(Namespaces el) {
452: return generateStandardTooltip(el);
453: }
454:
455: public String getTooltip(No el) {
456: return generateStandardTooltip(el);
457: }
458:
459: public String getTooltip(org.enhydra.shark.xpdl.elements.Package el) {
460: Map toDisplay = new SequencedHashMap();
461: putKeyValue(toDisplay, el.get("Id"));
462: putKeyValue(toDisplay, el.get("Name"));
463: putKeyValue(toDisplay, el.getPackageHeader().get("Description"));
464: return makeTooltip(toDisplay);
465: }
466:
467: public String getTooltip(PackageHeader el) {
468: return generateStandardTooltip(el);
469: }
470:
471: public String getTooltip(Participant el) {
472: Map toDisplay = new SequencedHashMap();
473: putKeyValue(toDisplay, el.get("Id"));
474: putKeyValue(toDisplay, el.get("Name"));
475: putKeyValue(toDisplay, el.getParticipantType());
476: putKeyValue(toDisplay, el.get("Description"));
477: return makeTooltip(toDisplay);
478: }
479:
480: public String getTooltip(Participants el) {
481: return generateStandardTooltip(el);
482: }
483:
484: public String getTooltip(ParticipantType el) {
485: return generateStandardTooltip(el);
486: }
487:
488: public String getTooltip(Performer el) {
489: return generateStandardTooltip(el);
490: }
491:
492: public String getTooltip(Priority el) {
493: return generateStandardTooltip(el);
494: }
495:
496: public String getTooltip(PriorityUnit el) {
497: return generateStandardTooltip(el);
498: }
499:
500: public String getTooltip(ProcessHeader el) {
501: return generateStandardTooltip(el);
502: }
503:
504: public String getTooltip(RecordType el) {
505: return generateStandardTooltip(el);
506: }
507:
508: public String getTooltip(RedefinableHeader el) {
509: return generateStandardTooltip(el);
510: }
511:
512: public String getTooltip(Responsible el) {
513: return generateStandardTooltip(el);
514: }
515:
516: public String getTooltip(Responsibles el) {
517: return generateStandardTooltip(el);
518: }
519:
520: public String getTooltip(Route el) {
521: return generateStandardTooltip(el);
522: }
523:
524: public String getTooltip(SchemaType el) {
525: return generateStandardTooltip(el);
526: }
527:
528: public String getTooltip(Script el) {
529: return generateStandardTooltip(el);
530: }
531:
532: public String getTooltip(SimulationInformation el) {
533: return generateStandardTooltip(el);
534: }
535:
536: public String getTooltip(Split el) {
537: return ResourceManager
538: .getLanguageDependentString("SplitTypeKey");
539: }
540:
541: public String getTooltip(StartFinishModes el) {
542: return generateStandardTooltip(el);
543: }
544:
545: public String getTooltip(StartMode el) {
546: return generateStandardTooltip(el);
547: }
548:
549: public String getTooltip(SubFlow el) {
550: return generateStandardTooltip(el);
551: }
552:
553: public String getTooltip(TimeEstimation el) {
554: return generateStandardTooltip(el);
555: }
556:
557: public String getTooltip(Tool el) {
558: return generateStandardTooltip(el);
559: }
560:
561: public String getTooltip(Tools el) {
562: return generateStandardTooltip(el);
563: }
564:
565: public String getTooltip(Transition el) {
566: LabelGenerator lg = JaWEManager.getInstance()
567: .getLabelGenerator();
568: Map toDisplay = new SequencedHashMap();
569: putKeyValue(toDisplay, el.get("Id"));
570: putKeyValue(toDisplay, el.get("Name"));
571: putKeyValue(toDisplay, el.get("Description"));
572: putKeyValue(toDisplay, el.get("From"));
573: putKeyValue(toDisplay, el.get("To"));
574: putKeyValue(toDisplay, el.getCondition().getTypeAttribute());
575: toDisplay.put(lg.getLabel(el.getCondition()), el.getCondition()
576: .toValue());
577: return makeTooltip(toDisplay);
578: }
579:
580: public String getTooltip(TransitionRef el) {
581: return generateStandardTooltip(el);
582: }
583:
584: public String getTooltip(TransitionRefs el) {
585: return generateStandardTooltip(el);
586: }
587:
588: public String getTooltip(TransitionRestriction el) {
589: return generateStandardTooltip(el);
590: }
591:
592: public String getTooltip(TransitionRestrictions el) {
593: return generateStandardTooltip(el);
594: }
595:
596: public String getTooltip(Transitions el) {
597: return generateStandardTooltip(el);
598: }
599:
600: public String getTooltip(TypeDeclaration el) {
601: return generateStandardTooltip(el);
602: }
603:
604: public String getTooltip(TypeDeclarations el) {
605: return generateStandardTooltip(el);
606: }
607:
608: public String getTooltip(UnionType el) {
609: return generateStandardTooltip(el);
610: }
611:
612: public String getTooltip(ValidFrom el) {
613: return generateStandardTooltip(el);
614: }
615:
616: public String getTooltip(ValidTo el) {
617: return generateStandardTooltip(el);
618: }
619:
620: public String getTooltip(Vendor el) {
621: return generateStandardTooltip(el);
622: }
623:
624: public String getTooltip(Version el) {
625: return generateStandardTooltip(el);
626: }
627:
628: public String getTooltip(WaitingTime el) {
629: return generateStandardTooltip(el);
630: }
631:
632: public String getTooltip(WorkflowProcess el) {
633: Map toDisplay = new SequencedHashMap();
634: putKeyValue(toDisplay, el.get("Id"));
635: putKeyValue(toDisplay, el.get("Name"));
636: putKeyValue(toDisplay, el.get("AccessLevel"));
637: putKeyValue(toDisplay, el.getProcessHeader().get("Description"));
638: return makeTooltip(toDisplay);
639: }
640:
641: public String getTooltip(WorkflowProcesses el) {
642: return generateStandardTooltip(el);
643: }
644:
645: public String getTooltip(WorkingTime el) {
646: return generateStandardTooltip(el);
647: }
648:
649: public String getTooltip(XPDLVersion el) {
650: return generateStandardTooltip(el);
651: }
652:
653: public String getTooltip(XMLEmptyChoiceElement el) {
654: return generateStandardTooltip(el);
655: }
656:
657: public String getTooltip(XMLComplexChoice el) {
658: return generateStandardTooltip(el);
659: }
660:
661: public String getTooltip(XMLCollection el) {
662: return generateStandardTooltip(el);
663: }
664:
665: public String getTooltip(XMLCollectionElement el) {
666: return generateStandardTooltip(el);
667: }
668:
669: public String getTooltip(XMLComplexElement el) {
670: return generateStandardTooltip(el);
671: }
672:
673: public String getTooltip(XMLSimpleElement el) {
674: return generateStandardTooltip(el);
675: }
676:
677: public String getTooltip(XMLAttribute el) {
678: return generateStandardTooltip(el);
679: }
680:
681: public String getTooltip(XMLElement el) {
682: try {
683: Class cl = el.getClass();
684: Method m = null;
685: try {
686: m = this .getClass().getMethod("getTooltip",
687: new Class[] { cl });
688: } catch (Exception ex) {
689: if (!(cl == XMLSimpleElement.class
690: || cl == XMLAttribute.class
691: || cl == XMLComplexChoice.class
692: || cl == XMLComplexElement.class
693: || cl == XMLCollectionElement.class || cl == XMLCollection.class)) {
694: if (XMLComplexChoice.class.isAssignableFrom(cl)) {
695: cl = XMLComplexChoice.class;
696: } else if (XMLAttribute.class.isAssignableFrom(cl)) {
697: cl = XMLAttribute.class;
698: } else if (XMLSimpleElement.class
699: .isAssignableFrom(cl)) {
700: cl = XMLSimpleElement.class;
701: } else if (XMLComplexElement.class
702: .isAssignableFrom(cl)) {
703: cl = XMLComplexElement.class;
704: } else if (XMLCollection.class.isAssignableFrom(cl)) {
705: cl = XMLCollection.class;
706: }
707: }
708: }
709: m = this .getClass().getMethod("getTooltip",
710: new Class[] { cl });
711: // System.err.println("calling "+m.toString());
712: return (String) m.invoke(this , new Object[] { el });
713: } catch (Throwable e) {
714: e.printStackTrace();
715: }
716:
717: return generateStandardTooltip(el);
718:
719: }
720:
721: public String generateStandardTooltip(XMLElement el) {
722: // Map toDisplay = new SequencedHashMap();
723: // if (el instanceof XMLCollection) {
724: //
725: // } else if (el instanceof XMLCollectionElement) {
726: //
727: // } else if (el instanceof XMLComplexElement) {
728: //
729: // } else if (el instanceof XMLComplexChoice) {
730: //
731: // } else if (el instanceof XMLAttribute) {
732: //
733: // }
734: return ResourceManager.getLanguageDependentString(el.toName()
735: + "Key");
736: }
737:
738: /**
739: * Neat little thing. Makes HTML formated string for tooltip (made of
740: * property names and coresponding values).
741: */
742: protected static String makeTooltip(Map elements) {
743: if (elements == null)
744: return "";
745: String s = HTML_OPEN;
746: Iterator it = elements.entrySet().iterator();
747: while (it.hasNext()) {
748: Map.Entry me = (Map.Entry) it.next();
749: s += makeAnotherHtmlLine((String) me.getKey(), (String) me
750: .getValue());
751: }
752: s = s.substring(0, s.length() - LINE_BREAK.length());
753: s += HTML_CLOSE;
754: return s;
755: }
756:
757: /** Helps when generating tooltip for some element. */
758: protected static String makeAnotherHtmlLine(String label,
759: String text) {
760: int MAX_LENGTH = 100;
761: int MAX_LINES_PER_TEXT = 15;
762: String textToAppend = "";
763: textToAppend += STRONG_OPEN;
764: textToAppend += label + COLON_SPACE;
765: textToAppend += STRONG_CLOSE;
766: String val = text;
767: val = val.replaceAll("<", "<");
768: val = val.replaceAll(">", ">");
769: int vl = val.length();
770: if (vl > MAX_LENGTH) {
771: String newVal = "";
772: int hm = vl / MAX_LENGTH;
773: for (int i = 0; i <= hm; i++) {
774: int startI = i * MAX_LENGTH;
775: int endI = (i + 1) * MAX_LENGTH;
776: if (endI > vl) {
777: endI = vl;
778: }
779: newVal = newVal + val.substring(startI, endI);
780: if (i == MAX_LINES_PER_TEXT) {
781: newVal = newVal + " ...";
782: break;
783: }
784: if (i < hm) {
785: newVal += LINE_BREAK;
786: newVal += StandardTooltipGenerator
787: .makeEmptyHTMLText((label + COLON_SPACE)
788: .length());
789: }
790: }
791: val = newVal;
792: }
793: textToAppend += val;
794: textToAppend += LINE_BREAK;
795:
796: return textToAppend;
797: }
798:
799: protected static String makeEmptyHTMLText(int length) {
800: if (length < 0)
801: return null;
802: String es = "";
803: for (int i = 0; i < length; i++) {
804: es += " ";
805: }
806: return es;
807: }
808:
809: protected static void putKeyValue(Map toPut, XMLElement el) {
810: LabelGenerator lg = JaWEManager.getInstance()
811: .getLabelGenerator();
812: DisplayNameGenerator dng = JaWEManager.getInstance()
813: .getDisplayNameGenerator();
814: toPut.put(lg.getLabel(el), dng.getDisplayName(el));
815: }
816:
817: public Settings getSettings() {
818: return settings;
819: }
820:
821: }
|