Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3517c36eee8087f2e8199ef0114fe0e6700ad1f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
/*****************************************************************************
< * Copyright (c) 2008 CEA LIST.
 *
 *    
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
 *  Atos Origin - Enable extending with a composite figure, by adding overrideable methods.
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.figure.node;

import java.util.Iterator;
import java.util.StringTokenizer;

import org.eclipse.draw2d.Border;
import org.eclipse.draw2d.FigureListener;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
import org.eclipse.papyrus.uml.diagram.common.figure.layout.PropertiesCompartmentLayoutManager;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

/**
 * This class is top graphNode figure. It contains: 1 icon label + 1 stereotype
 * label + 1 qualified name label + 1 name label
 */
public class NodeNamedElementFigure extends PapyrusNodeFigure implements IPapyrusNodeNamedElementFigure, IPapyrusNodeUMLElementFigure {

	protected boolean noBorder = false;

	private static final String CHEVRON = String.valueOf("\u00AB") + String.valueOf("\u00BB");

	private Label taggedLabel;

	/** the depth of the qualified name **/
	private int depth = 0;

	/**
	 * The icon label.
	 */
	protected Label iconLabel;

	/**
	 * The name label.
	 */
	protected WrappingLabel nameLabel;

	protected Image nameLabelIcon = null;

	/**
	 * The qualified label.
	 */
	protected Label qualifiedLabel;

	/**
	 * Added for stereptypes properties
	 */
	private RectangleFigure stereotypePropertiesContent;

	/**
	 * Added for stereotypes properties, displayed in the InBrace location
	 */
	protected Label stereotypePropertiesInBraceContent;

	/**
	 * The stereotypes label.
	 */
	protected Label stereotypesLabel;

	/**
	 * Create a basic figure.
	 */
	public NodeNamedElementFigure() {
		this(null);

	}

	@Override
	public void setBorder(Border border) {
		if(border == null) {
			noBorder = true;
		} else {
			noBorder = false;
		}
		super.setBorder(border);
	}

	@Override
	protected Border getDefaultBorder(Color borderColor) {
		if(noBorder) {
			return null;
		} else {
			return super.getDefaultBorder(borderColor);
		}
	}

	@Override
	public void remove(IFigure figure) {
		if(figure instanceof AppliedStereotypeCompartmentFigure) {
			if(stereotypePropertiesContent == null) {
				this.createStereotypePropertiesContent();
			}
			stereotypePropertiesContent.remove(figure);
		} else {

			super.remove(figure);
		}

	}

	@Override
	public void add(IFigure figure, Object constraint, int index) {
		if(figure instanceof AppliedStereotypeCompartmentFigure) {
			if(stereotypePropertiesContent == null) {
				this.createStereotypePropertiesContent();
			}
			stereotypePropertiesContent.add(figure);
		} else {

			super.add(figure, constraint, index);
		}
	}


	public void setStereotypeDisplay(String stereotypes, Image image) {

		// Set stereotype text on figure
		if(!"".equals(stereotypes)) {
			setStereotypes(stereotypes);
		} else {
			setStereotypes(null);
		}

		setAppliedStereotypeIcon(image);
	}

	public NodeNamedElementFigure(String taggedLabelValue) {
		super();

		// creation of the nameLabel
		createNameLabel();

		initTagLabel(taggedLabelValue);
	}

	/**
	 * Create a label that contains the name of the element.
	 */
	protected void createNameLabel() {
		nameLabel = new WrappingLabel();

		nameLabel.setOpaque(false);
		nameLabel.setAlignment(PositionConstants.MIDDLE);
		getNameLabelContainer().add(nameLabel, getNameLabelConstraint(), -1);
	}

	public void restoreNameLabel() {
		nameLabel.setOpaque(false);
		nameLabel.setAlignment(PositionConstants.MIDDLE);
		getNameLabelContainer().add(nameLabel, getNameLabelConstraint(), getNameLabelPosition());
	}


	/**
	 * Create a label that contains the name of the element.
	 */
	public void removeNameLabel() {
		if(getNameLabelContainer().getChildren().contains(nameLabel)) {
			getNameLabelContainer().remove(nameLabel);
		}
	}

	/**
	 * Get the constraint for adding the name label. Children should override
	 * and implement this method in case the label must be drawn with a specific
	 * constraint.
	 * 
	 * @return figure containing the name label
	 * @see #getNameLabelContainer()
	 * @see #getDefaultLabelsConstraint()
	 */
	protected Object getNameLabelConstraint() {
		return getDefaultLabelsConstraint();
	}

	/**
	 * Get the constraint for adding the icon label. Children should override
	 * and implement this method in case the label must be drawn with a specific
	 * constraint.
	 * 
	 * @return figure containing the icon label
	 * @see #getIconLabelContainer()
	 * @see #getDefaultLabelsConstraint()
	 */
	protected Object getIconLabelConstraint() {
		return getDefaultLabelsConstraint();
	}

	/**
	 * Get the constraint for adding the qualified name label. Children should
	 * override and implement this method in case the label must be drawn with a
	 * specific constraint.
	 * 
	 * @return figure containing the qualified name label
	 * @see #getQualifiedNameLabelContainer()
	 * @see #getDefaultLabelsConstraint()
	 */
	protected Object getQualifiedNameLabelConstraint() {
		return getDefaultLabelsConstraint();
	}

	/**
	 * Get the constraint for adding the stereotype label. Children should
	 * override and implement this method in case the label must be drawn with a
	 * specific constraint.
	 * 
	 * @return figure containing the qualified name label
	 * @see #getStereotypeLabelContainer()
	 * @see #getDefaultLabelsConstraint()
	 */
	protected Object getStereotypeLabelConstraint() {
		return getDefaultLabelsConstraint();
	}

	/**
	 * Get the constraint for adding the stereotype properties in brace label.
	 * Children should override and implement this method in case the label must
	 * be drawn with a specific constraint.
	 * 
	 * @return figure containing the stereotype properties in brace label
	 * @see #getStereotypePropertiesInBraceLabelContainer()
	 * @see #getDefaultLabelsConstraint()
	 */
	protected Object getStereotypePropertiesInBraceLabelConstraint() {
		return getDefaultLabelsConstraint();
	}

	/**
	 * Get the constraint for adding the stereotype properties compartment.
	 * Children should override and implement this method in case the label must
	 * be drawn with a specific constraint.
	 * 
	 * @return figure containing the stereotype properties compartment
	 * @see #getStereotypePropertiesCompartmentContainer()
	 * @see #getDefaultLabelsConstraint()
	 */
	protected Object getStereotypePropertiesCompartmentConstraint() {
		return getDefaultLabelsConstraint();
	}

	/**
	 * Get the constraint for adding the tag label. Children should override and
	 * implement this method in case the label must be drawn with a specific
	 * constraint.
	 * 
	 * @return figure containing the qualified name label
	 * @see #getTagLabelContainer()
	 * @see #getDefaultLabelsConstraint()
	 */
	protected Object getTagLabelConstraint() {
		return getDefaultLabelsConstraint();
	}

	/**
	 * Get the default constraint for all labels. Children should override and
	 * implement this method in case the label must be drawn with a specific
	 * constraint.
	 * 
	 * @return constraint for all labels by default
	 * @see #getDefaultLabelsContainer()
	 */
	protected Object getDefaultLabelsConstraint() {
		return null;
	}

	/**
	 * Get the container for the name label. Children should override and
	 * implement this method in case the label must not be drawn in the overall
	 * figure. The returned figure shall be created in the method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing the name label
	 * @see #getDefaultLabelsContainer()
	 */
	protected IFigure getNameLabelContainer() {
		return getDefaultLabelsContainer();
	}

	/**
	 * Get the container for the icon label. Children should override and
	 * implement this method in case the label must not be drawn in the overall
	 * figure. The returned figure shall be created in the method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing the icon label
	 * @see #getDefaultLabelsContainer()
	 */
	protected IFigure getIconLabelContainer() {
		return getDefaultLabelsContainer();
	}

	/**
	 * Get the container for the qualified name label. Children should override
	 * and implement this method in case the label must not be drawn in the
	 * overall figure. The returned figure shall be created in the method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing the qualified name label
	 * @see #getDefaultLabelsContainer()
	 */
	protected IFigure getQualifiedNameLabelContainer() {
		return getDefaultLabelsContainer();
	}

	/**
	 * Get the container for the stereotype label. Children should override and
	 * implement this method in case the label must not be drawn in the overall
	 * figure. The returned figure shall be created in the method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing the qualified name label
	 * @see #getDefaultLabelsContainer()
	 */
	protected IFigure getStereotypeLabelContainer() {
		return getDefaultLabelsContainer();
	}

	/**
	 * Get the container for the stereotype properties in brace label. Children
	 * should override and implement this method in case the label must not be
	 * drawn in the overall figure. The returned figure shall be created in the
	 * method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing the stereotype properties in brace label
	 * @see #getDefaultLabelsContainer()
	 */
	protected IFigure getStereotypePropertiesInBraceLabelContainer() {
		return getDefaultLabelsContainer();
	}

	/**
	 * Get the container for the stereotype properties compartment. Children
	 * should override and implement this method in case the compartment must
	 * not be drawn in the overall figure. The returned figure shall be created
	 * in the method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing the stereotype properties compartment
	 * @see #getDefaultLabelsContainer()
	 */
	protected IFigure getStereotypePropertiesCompartmentContainer() {
		return getDefaultLabelsContainer();
	}

	/**
	 * Get the container for the tag label. Children should override and
	 * implement this method in case the label must not be drawn in the overall
	 * figure. The returned figure shall be created in the method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing the qualified name label
	 * @see #getDefaultLabelsContainer()
	 */
	protected IFigure getTagLabelContainer() {
		return getDefaultLabelsContainer();
	}

	/**
	 * Get the default container for all labels. Children should override and
	 * implement this method in case the label must not be drawn in the overall
	 * figure. The returned figure shall be created in the method {@link #createCompositeFigureStructure()}.
	 * 
	 * @return figure containing labels by default
	 */
	protected IFigure getDefaultLabelsContainer() {
		return this;
	}

	/**
	 * Copy context to.
	 * 
	 * @param fig
	 *        the fig
	 */
	// @unused
	public void copyContextTo(IFigure fig) {
		Iterator it = this.getListeners(FigureListener.class);
		while(it.hasNext()) {
			fig.addFigureListener((FigureListener)it.next());
		}

	}

	/**
	 * used to create a label that contains the icon.
	 */
	protected void createIconLabel() {
		iconLabel = new LabelWithScalableIcons();
		// Add the label to the figure, at pos 0
		getIconLabelContainer().add(iconLabel, getIconLabelConstraint(), getIconLabelPosition());
		iconLabel.setLabelAlignment(PositionConstants.LEFT);
	}

	/**
	 * Creates the icon label.
	 * 
	 * @param position
	 *        the position
	 */
	protected void createIconLabel(int position) {
		iconLabel = new LabelWithScalableIcons();
		getIconLabelContainer().add(iconLabel, getIconLabelConstraint(), getIconLabelPosition());
		iconLabel.setLabelAlignment(position);
	}

	/**
	 * create the label that contains the qualified name.
	 */
	protected void createQualifiedNameLabel() {
		qualifiedLabel = new Label();
		qualifiedLabel.setOpaque(false);
		qualifiedLabel.setFont(getNameLabel().getFont());
		qualifiedLabel.setForegroundColor(getNameLabel().getForegroundColor());
		// Add the label to the figure, after the name
		getQualifiedNameLabelContainer().add(qualifiedLabel, getQualifiedNameLabelConstraint(), getQualifiedNameLabelPosition());
	}

	/**
	 * this method is used to create the stereotype label.
	 */
	protected void createStereotypeLabel() {
		stereotypesLabel = new Label();
		stereotypesLabel.setOpaque(false);
		stereotypesLabel.setFont(getNameLabel().getFont());
		stereotypesLabel.setForegroundColor(getNameLabel().getForegroundColor());
		// Add the stereotype label to the figure at pos 0
		getStereotypeLabelContainer().add(stereotypesLabel, getStereotypeLabelConstraint(), getStereotypeLabelPosition());
	}

	/**
	 * this method is used to create the stereotype label.
	 */
	protected void createStereotypePropertiesInBraceLabel() {
		stereotypePropertiesInBraceContent = new Label();
		stereotypePropertiesInBraceContent.setOpaque(false);
		// Add the stereotype label to the figure at pos 0
		getStereotypePropertiesInBraceLabelContainer().add(stereotypePropertiesInBraceContent, getStereotypePropertiesInBraceLabelConstraint(), getStereotypePropertiesLabelPosition());
	}

	protected void createStereotypePropertiesContent() {
		stereotypePropertiesContent = new StereotypePropertiesCompartment();
		stereotypePropertiesContent.setFill(false);
		stereotypePropertiesContent.setLineWidth(0);
		stereotypePropertiesContent.setBorder(null);
		stereotypePropertiesContent.setLayoutManager(getPropertiesCompartmentLayout());
		getStereotypePropertiesCompartmentContainer().add(stereotypePropertiesContent, getStereotypePropertiesCompartmentConstraint(), getStereotypePropertiesCompartmentPosition());
	}

	/**
	 * Get layout to display content of properties compartment. Children may
	 * override this method.
	 * 
	 * @return the layout
	 */
	protected LayoutManager getPropertiesCompartmentLayout() {
		return new PropertiesCompartmentLayoutManager();
	}

	private void fillStereotypePropertiesInCompartment(String stereotypeProperties) {

		stereotypePropertiesContent.getChildren().clear();
		StringTokenizer stringTokenizer = new StringTokenizer(stereotypeProperties, ";");
		while(stringTokenizer.hasMoreElements()) {
			String tokenStereotype = stringTokenizer.nextToken();
			tokenStereotype = tokenStereotype.replace("#", "\n  ");
			tokenStereotype = tokenStereotype.replace("|", "\n  ");
			Label label = new Label(tokenStereotype);
			label.setLabelAlignment(PositionConstants.LEFT);
			label.setBorder(null);
			stereotypePropertiesContent.add(label);
		}

	}

	/**
	 * Get the label containing the tagged value
	 * 
	 * @return
	 */
	public Label getTaggedLabel() {
		return taggedLabel;
	}

	/**
	 * Gets the depth.
	 * 
	 * @return the depth
	 */
	// @unused
	public int getDepth() {
		return depth;
	}

	/**
	 * return the label thath contains the icon.
	 * 
	 * @return the label that contains the icon
	 */
	public Label getIconLabel() {
		return this.iconLabel;
	}

	/**
	 * Create the tag label in the figure. The tag label is created if value is
	 * not null.
	 * 
	 * @param value
	 *        the value to use
	 */
	protected void initTagLabel(String value) {
		if(value != null && value.length() > 0) {
			taggedLabel = new Label();
			String textToDisplay = new StringBuffer(CHEVRON).insert(1, value).toString();
			taggedLabel.setText(textToDisplay);
			taggedLabel.setOpaque(false);
			taggedLabel.setForegroundColor(getNameLabel().getForegroundColor());
			taggedLabel.setFont(getNameLabel().getFont());
			getTagLabelContainer().add(taggedLabel, getTagLabelConstraint(), 0);
		}
	}

	public Dimension getMinimumDimension() {
		int width = 0;
		int height = 0;
		int temporysize = 0;
		if(getNameLabelContainer().getChildren().contains(getNameLabel())) {
			width = getNameLabel().getTextBounds().width + 10;
			height = getNameLabel().getTextBounds().height + 10;
		}
		if(getStereotypesLabel() != null) {
			temporysize = getStereotypesLabel().getTextBounds().width + 10;
			height = height + getStereotypesLabel().getTextBounds().height;
			if(width < temporysize) {
				width = temporysize;
			}
		}
		if(getQualifiedNameLabel() != null) {
			temporysize = getQualifiedNameLabel().getTextBounds().width + 10;
			height = height + getQualifiedNameLabel().getTextBounds().height;
			if(width < temporysize) {
				width = temporysize;
			}
		}
		return new Dimension(width, height);
	}

	/**
	 * Helper method to calculate the height of name
	 */
	protected int getNameHeight() {
		int nameHeight = this.getNameLabel().getPreferredSize().height;

		if(this.getIconLabel() != null && getIconLabelContainer().equals(getNameLabelContainer())) {
			nameHeight += this.getIconLabel().getPreferredSize().height;
		}
		if(this.getStereotypesLabel() != null && getStereotypeLabelContainer().equals(getNameLabelContainer())) {
			nameHeight += this.getStereotypesLabel().getPreferredSize().height;
		}
		if(this.getQualifiedNameLabel() != null && getQualifiedNameLabelContainer().equals(getNameLabelContainer())) {
			nameHeight += this.getQualifiedNameLabel().getPreferredSize().height;
		}
		nameHeight += 5;

		return nameHeight;

	}

	/**
	 * Gets the name label.
	 * 
	 * @return the name label
	 */
	public WrappingLabel getNameLabel() {
		return this.nameLabel;
	}

	// @unused
	public Image getNameLabelIcon() {
		return nameLabelIcon;
	}

	/**
	 * Calculate the partial qualified name with a specified depth.
	 * 
	 * @param qualifiedName
	 *        the qualified name can return null
	 */
	public String getQualifiedName(String qualifiedName, int depth) {
		int n = -1;
		if(qualifiedName == null) {
			return null;
		}
		int i = 0;
		if(depth <= 0) {
			return qualifiedName;
		}

		while(i < depth) {
			if((n = qualifiedName.indexOf("::", n + 1)) != -1) {
				i++;
			} else {
				return null;
			}
		}

		if(n == -1) {
			return qualifiedName;
		} else {
			return qualifiedName.substring(n + 2);
		}

	}

	/**
	 * return the label that contains the qualified name.
	 * 
	 * @return the label that contains the qualified name
	 */
	public Label getQualifiedNameLabel() {
		return this.qualifiedLabel;
	}

	/**
	 * @return the position of the icon label
	 */
	protected int getIconLabelPosition() {
		return 0;
	}

	/**
	 * @return the position of the stereotype label
	 */
	protected int getStereotypeLabelPosition() {
		int position = 0;
		if(getStereotypeLabelContainer().equals(getIconLabelContainer())) {
			// located after icon label
			position = getIconLabelPosition();
			if((this.iconLabel != null) && (this.iconLabel.getIcon() != null)) {
				position++;
			}
		}
		return position;

	}



	/**
	 * Returns the position of the stereotype properties location. this is just
	 * after stereotype position
	 * 
	 * @return the position of the stereotype properties in brace label
	 */
	protected int getStereotypePropertiesLabelPosition() {
		int position = 0;
		if(getStereotypePropertiesInBraceLabelContainer().equals(getStereotypeLabelContainer())) {
			// located after stereotype label
			position = getStereotypeLabelPosition();
			if(this.stereotypesLabel != null) {
				position++;
			}
		} else if(getStereotypePropertiesInBraceLabelContainer().equals(getIconLabelContainer())) {
			// located after icon label
			position = getIconLabelPosition();
			if((this.iconLabel != null) && (this.iconLabel.getIcon() != null)) {
				position++;
			}
		}
		return position;
	}

	/**
	 * @return the position of the qualified name label
	 */
	protected int getQualifiedNameLabelPosition() {
		int position = 0;
		if(getQualifiedNameLabelContainer().equals(getStereotypePropertiesInBraceLabelContainer())) {
			// located after stereotype properties in brace label
			position = getStereotypePropertiesLabelPosition();
			if(this.stereotypePropertiesInBraceContent != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getStereotypeLabelContainer())) {
			// located after stereotype label
			position = getStereotypeLabelPosition();
			if(this.stereotypesLabel != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getIconLabelContainer())) {
			// located after icon label
			position = getIconLabelPosition();
			if((this.iconLabel != null) && (this.iconLabel.getIcon() != null)) {
				position++;
			}
		}
		return position;
	}

	/**
	 * @return the position of the name label
	 */
	// @unused
	protected int getNameLabelPosition() {
		int position = 0;
		if(getNameLabelContainer().equals(getQualifiedNameLabelContainer())) {
			// located after qualifed name label
			position = getQualifiedNameLabelPosition();
			if(this.qualifiedLabel != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getStereotypePropertiesInBraceLabelContainer())) {
			// located after stereotype properties in brace label
			position = getStereotypePropertiesLabelPosition();
			if(this.stereotypePropertiesInBraceContent != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getStereotypeLabelContainer())) {
			// located after stereotype label
			position = getStereotypeLabelPosition();
			if(this.stereotypesLabel != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getIconLabelContainer())) {
			// located after icon label
			position = getIconLabelPosition();
			if((this.iconLabel != null) && (this.iconLabel.getIcon() != null)) {
				position++;
			}
		}
		return position;
	}

	/**
	 * @return the position of the stereotype properties compartment
	 */
	protected int getStereotypePropertiesCompartmentPosition() {
		int position = 0;
		if(getStereotypePropertiesCompartmentContainer().equals(getNameLabelContainer())) {
			// locate after name label (which is never removed)
			position = getNameLabelContainer().getChildren().indexOf(nameLabel);
			position++;
		} else if(getNameLabelContainer().equals(getQualifiedNameLabelContainer())) {
			// located after qualifed name label
			position = getQualifiedNameLabelPosition();
			if(this.qualifiedLabel != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getStereotypePropertiesInBraceLabelContainer())) {
			// located after stereotype properties in brace label
			position = getStereotypePropertiesLabelPosition();
			if(this.stereotypePropertiesInBraceContent != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getStereotypeLabelContainer())) {
			// located after stereotype label
			position = getStereotypeLabelPosition();
			if(this.stereotypesLabel != null) {
				position++;
			}
		} else if(getQualifiedNameLabelContainer().equals(getIconLabelContainer())) {
			// located after icon label
			position = getIconLabelPosition();
			if((this.iconLabel != null) && (this.iconLabel.getIcon() != null)) {
				position++;
			}
		}
		return position;
	}

	/**
	 * to obtain the stereotypePropertiesContent of the class figure
	 * 
	 */
	public RectangleFigure getStereotypePropertiesContent() {
		return this.stereotypePropertiesContent;
	}

	/**
	 * Gets the stereotypes label.
	 * 
	 * @return the stereotypes label
	 */
	public Label getStereotypesLabel() {
		return this.stereotypesLabel;
	}

	/**
	 * return true inf the label in localized at the point pt.
	 * 
	 * @param label
	 *        the label that we look for
	 * @param pt
	 *        the point that we test
	 * 
	 * @return true if the point is on the label
	 */
	// @unused
	protected boolean labelContainsPoint(Label label, Point pt) {
		Rectangle rc;

		rc = new PrecisionRectangle(label.getBounds());
		label.translateToAbsolute(rc);
		if(rc.contains(pt)) {
			return true;
		}
		return false;
	}

	/**
	 * Refresh stereotypes.
	 * 
	 * @param presentation
	 *        the presentation
	 * @param hasIcon
	 *        the has icon
	 * @param hasShape
	 *        the has shape
	 * @param stereotypes
	 *        the stereotypes
	 */
	public void refreshStereotypes(String stereotypes, String presentation, boolean hasIcon, boolean hasShape) {

		if(stereotypes.equals("")) {
			this.setStereotypes(null);
			return;
		}

		if(presentation.equals(UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION) && hasIcon) {
			this.setStereotypes(null);
			return;
		} else if(presentation.equals(UMLVisualInformationPapyrusConstant.IMAGE_STEREOTYPE_PRESENTATION) && hasShape) {
			this.setStereotypes(null);
			return;
		}

		this.setStereotypes(stereotypes);// add stereotypes on the class figure
		return;
	}

	/**
	 * Sets the depth.
	 * 
	 * @param depth
	 *        the new depth
	 */
	public void setDepth(int depth) {
		this.depth = depth;
	}

	/**
	 * Sets the name.
	 * 
	 * @param name
	 *        the name
	 */
	// @unused
	public void setName(String name) {
		this.nameLabel.setText(name);
	}

	public void setNameLabelIcon(boolean displayNameLabelIcon) {
		if(getNameLabel().getIcon() != null) {
			nameLabelIcon = getNameLabel().getIcon();
		}
		if(displayNameLabelIcon) {
			getNameLabel().setIcon(nameLabelIcon);
		} else {
			getNameLabel().setIcon(null);
		}
	}

	// @unused
	public void setNameLabelIcon(Image nameLabelIcon) {
		this.nameLabelIcon = nameLabelIcon;
	}

	/**
	 * Sets the qualified name.
	 * 
	 * @param qualifiedName
	 *        the qualified name
	 */
	public void setQualifiedName(String qualifiedName) {
		String tmpQualifiedName = getQualifiedName(qualifiedName, depth);
		// two raisons to remove label!
		// null
		// or the qualified name is equal to 1
		if(qualifiedName == null || tmpQualifiedName == null || !tmpQualifiedName.contains("::")) { // Remove
			// label
			// if
			// any
			if(this.qualifiedLabel != null) {
				getQualifiedNameLabelContainer().remove(this.qualifiedLabel);
				this.qualifiedLabel = null;
			}
			return;
		}

		// Set the stereotype label
		if(this.qualifiedLabel == null) {
			this.createQualifiedNameLabel();
		}
		// we have to not display name.

		int i = tmpQualifiedName.lastIndexOf("::");
		if(i != -1) {
			tmpQualifiedName = tmpQualifiedName.substring(0, i);
		}
		this.qualifiedLabel.setText("(" + tmpQualifiedName.trim() + ")");

	}

	/**
	 * Sets the stereotypes properties for this figure.
	 * <p>
	 * This implementation checks if the specified string is null or not.
	 * <ul>
	 * <li>if the string is <code>null</code>, it removes the label representing the stereotypes properties with brace.</li>
	 * <li>if this is not <code>null</code>, it creates the stereotype properties label if needed and displays the specified string.</li>
	 * </ul>
	 * </p>
	 * 
	 * @param stereotypeProperties
	 *        the string representing the stereotype properties to be
	 *        displayed
	 */
	public void setStereotypePropertiesInBrace(String stereotypeProperties) {
		if(stereotypeProperties == null) {
			// Remove label if any
			if(this.stereotypePropertiesInBraceContent != null) {
				getStereotypePropertiesInBraceLabelContainer().remove(this.stereotypePropertiesInBraceContent);
				this.stereotypePropertiesInBraceContent = null;
			}
			return;
		}

		// Set the stereotype label if it does not already exist
		if(this.stereotypePropertiesInBraceContent == null) {
			this.createStereotypePropertiesInBraceLabel();
		}

		// Set stereotype text on figure
		if(!"".equals(stereotypeProperties)) {
			this.stereotypePropertiesInBraceContent.setText("{" + stereotypeProperties + "}");
		} else {
			this.stereotypePropertiesInBraceContent.setText("");
		}
	}

	/**
	 * displays the new string corresponding to the list of stereotypes.
	 * 
	 * if the string is <code>null</code>, then the figure that displays the
	 * stereotype label is removed from the NodeNamedElementFigure.
	 * 
	 * @param stereotypeProperties
	 *        the string to be displayed.
	 */
	public void setStereotypePropertiesInCompartment(String stereotypeProperties) {
		if(stereotypeProperties == null || stereotypeProperties.trim() == "") {
			// remove figure of stereotype properties compartment
			if(this.stereotypePropertiesContent != null) {
				getStereotypePropertiesCompartmentContainer().remove(this.stereotypePropertiesContent);
				this.stereotypePropertiesContent = null;
			}
			return;
		}

		// set stereotype properties content
		if(stereotypePropertiesContent == null) {
			this.createStereotypePropertiesContent();
		}

		fillStereotypePropertiesInCompartment(stereotypeProperties);
	}

	/**
	 * Sets the stereotypes for this figure.
	 * <p>
	 * This implementation checks if the specified string is null or not.
	 * <ul>
	 * <li>if the string is <code>null</code>, it removes the label representing the stereotypes.</li>
	 * <li>if this is not <code>null</code>, it creates the stereotype label if needed and displays the specified string.</li>
	 * </ul>
	 * </p>
	 * 
	 * @param stereotypes
	 *        the string representing the stereotypes to be displayed
	 */
	public void setStereotypes(String stereotypes) {
		if(stereotypes == null) {
			// Remove label if any
			if(this.stereotypesLabel != null) {
				getStereotypeLabelContainer().remove(this.stereotypesLabel);
				this.stereotypesLabel = null;
			}
			return;
		}

		// Set the stereotype label if it does not already exist
		if(this.stereotypesLabel == null) {
			this.createStereotypeLabel();
		}

		// Set stereotype text on figure
		if(!"".equals(stereotypes)) {
			this.stereotypesLabel.setText(stereotypes);
		} else {
			this.stereotypesLabel.setText("");
		}
	}

	/**
	 * Sets the stereotype icon for this figure.
	 * 
	 * @param stereotypes
	 *        the image representing the stereotype
	 */
	public void setAppliedStereotypeIcon(Image image) {
		if(image == null) {
			// Remove label if any
			if(this.iconLabel != null) {
				getIconLabelContainer().remove(this.iconLabel);
				this.iconLabel = null;
			}
			return;
		}

		// Set the stereotype label if it does not already exist
		if(this.iconLabel == null) {
			this.createIconLabel();
		}

		// Set stereotype icon on figure
		this.iconLabel.setIcon(image);
	}

	/**
	 * Sets the applied stereotype icon.
	 * 
	 * @param image
	 *        the image
	 * @param position
	 *        the position
	 */
	public void setAppliedStereotypeIcon(Image image, int position) {
		if(image == null) {
			// Remove label if any
			if(this.iconLabel != null) {
				getIconLabelContainer().remove(this.iconLabel);
				this.iconLabel = null;
			}
			return;
		}

		// Set the stereotype label with position parameter if it does not
		// already exist
		if(this.iconLabel == null) {
			this.createIconLabel(position);
		}

		// Set stereotype icon on figure
		this.iconLabel.setIcon(image);
	}

}

Back to the top