Lines 30-35
Link Here
|
30 |
public class ControlDecorationUpdater { |
30 |
public class ControlDecorationUpdater { |
31 |
/** |
31 |
/** |
32 |
* <b>EXPERIMENTAL</b>: This method is not API. It is experimental and |
32 |
* <b>EXPERIMENTAL</b>: This method is not API. It is experimental and |
|
|
33 |
* subject to arbitrary change, including removals. Please provide feedback |
34 |
* if you would like to see this become API. |
35 |
* |
36 |
* @return . |
37 |
*/ |
38 |
public static ControlDecorationUpdater required() { |
39 |
return new ControlDecorationUpdater() { |
40 |
protected String getFieldDecorationId(IStatus status, boolean init) { |
41 |
String decorationId = super.getFieldDecorationId(status, init); |
42 |
if (decorationId == null || init) |
43 |
return FieldDecorationRegistry.DEC_REQUIRED; |
44 |
return decorationId; |
45 |
} |
46 |
}; |
47 |
} |
48 |
|
49 |
/** |
50 |
* <b>EXPERIMENTAL</b>: This method is not API. It is experimental and |
33 |
* subject to arbitrary change, including removal. Please provide feedback |
51 |
* subject to arbitrary change, including removal. Please provide feedback |
34 |
* if you would like to see this become API. |
52 |
* if you would like to see this become API. |
35 |
* <p> |
53 |
* <p> |
Lines 40-52
Link Here
|
40 |
* the ControlDecoration to update |
58 |
* the ControlDecoration to update |
41 |
* @param status |
59 |
* @param status |
42 |
* the status to be displayed by the decoration |
60 |
* the status to be displayed by the decoration |
|
|
61 |
* @param init |
62 |
* whether the decoration is being updated for the first time |
43 |
*/ |
63 |
*/ |
44 |
protected void update(ControlDecoration decoration, IStatus status) { |
64 |
protected void update(ControlDecoration decoration, IStatus status, |
|
|
65 |
boolean init) { |
45 |
if (status == null || status.isOK()) { |
66 |
if (status == null || status.isOK()) { |
46 |
decoration.hide(); |
67 |
decoration.hide(); |
47 |
} else { |
68 |
} else { |
48 |
decoration.setImage(getImage(status)); |
69 |
decoration.setImage(getImage(status, init)); |
49 |
decoration.setDescriptionText(getDescriptionText(status)); |
70 |
decoration.setDescriptionText(getDescriptionText(status, init)); |
50 |
decoration.show(); |
71 |
decoration.show(); |
51 |
} |
72 |
} |
52 |
} |
73 |
} |
Lines 62-71
Link Here
|
62 |
* |
83 |
* |
63 |
* @param status |
84 |
* @param status |
64 |
* the status object. |
85 |
* the status object. |
|
|
86 |
* @param init |
87 |
* whether the decoration is being updated for the first time |
65 |
* @return the description text to show in a ControlDecoration for the given |
88 |
* @return the description text to show in a ControlDecoration for the given |
66 |
* status. |
89 |
* status. |
67 |
*/ |
90 |
*/ |
68 |
protected String getDescriptionText(IStatus status) { |
91 |
protected String getDescriptionText(IStatus status, boolean init) { |
69 |
return status == null ? "" : status.getMessage(); //$NON-NLS-1$ |
92 |
return status == null ? "" : status.getMessage(); //$NON-NLS-1$ |
70 |
} |
93 |
} |
71 |
|
94 |
|
Lines 76-100
Link Here
|
76 |
* <p> |
99 |
* <p> |
77 |
* Returns an image to display in a ControlDecoration which is appropriate |
100 |
* Returns an image to display in a ControlDecoration which is appropriate |
78 |
* for the given status. The default implementation of this method returns |
101 |
* for the given status. The default implementation of this method returns |
79 |
* an image according to <code>status.getSeverity()</code>: |
102 |
* an image according to <code>status.getSeverity()</code> and/or the |
|
|
103 |
* <code>init</code> parameter: |
80 |
* <ul> |
104 |
* <ul> |
81 |
* <li>IStatus.OK => No image |
105 |
* <li>severity == IStatus.OK => No image |
82 |
* <li>IStatus.INFO => FieldDecorationRegistry.DEC_INFORMATION |
106 |
* <li>severity == IStatus.INFO => FieldDecorationRegistry.DEC_INFORMATION |
83 |
* <li>IStatus.WARNING => FieldDecorationRegistry.DEC_WARNING |
107 |
* <li>severity == IStatus.WARNING => FieldDecorationRegistry.DEC_WARNING |
84 |
* <li>IStatus.ERROR => FieldDecorationRegistry.DEC_ERROR |
108 |
* <li>init == true => No image |
85 |
* <li>IStatus.CANCEL => FieldDecorationRegistry.DEC_ERROR |
109 |
* <li>severity == IStatus.ERROR => FieldDecorationRegistry.DEC_ERROR |
|
|
110 |
* <li>severity == IStatus.CANCEL => FieldDecorationRegistry.DEC_ERROR |
86 |
* <li>Other => No image |
111 |
* <li>Other => No image |
87 |
* </ul> |
112 |
* </ul> |
88 |
* |
113 |
* |
89 |
* @param status |
114 |
* @param status |
90 |
* the status object. |
115 |
* the status object (may be null) |
|
|
116 |
* @param init |
117 |
* whether the decoration is being updated for the first time |
91 |
* @return an image to display in a ControlDecoration which is appropriate |
118 |
* @return an image to display in a ControlDecoration which is appropriate |
92 |
* for the given status. |
119 |
* for the given status. |
93 |
*/ |
120 |
*/ |
94 |
protected Image getImage(IStatus status) { |
121 |
protected Image getImage(IStatus status, boolean init) { |
|
|
122 |
FieldDecoration decoration = FieldDecorationRegistry.getDefault() |
123 |
.getFieldDecoration(getFieldDecorationId(status, init)); |
124 |
return decoration == null ? null : decoration.getImage(); |
125 |
} |
126 |
|
127 |
/** |
128 |
* <b>EXPERIMENTAL</b>: This method is not API. It is experimental and |
129 |
* subject to arbitrary change, including removal. Please provide feedback |
130 |
* if you would like to see this become API. |
131 |
* |
132 |
* @param status |
133 |
* the status object (may be null) |
134 |
* @param init |
135 |
* whether the decoration is being updated for the first time |
136 |
* @return . |
137 |
*/ |
138 |
protected String getFieldDecorationId(IStatus status, boolean init) { |
95 |
if (status == null) |
139 |
if (status == null) |
96 |
return null; |
140 |
return null; |
97 |
|
|
|
98 |
String fieldDecorationID = null; |
141 |
String fieldDecorationID = null; |
99 |
switch (status.getSeverity()) { |
142 |
switch (status.getSeverity()) { |
100 |
case IStatus.INFO: |
143 |
case IStatus.INFO: |
Lines 105-116
Link Here
|
105 |
break; |
148 |
break; |
106 |
case IStatus.ERROR: |
149 |
case IStatus.ERROR: |
107 |
case IStatus.CANCEL: |
150 |
case IStatus.CANCEL: |
108 |
fieldDecorationID = FieldDecorationRegistry.DEC_ERROR; |
151 |
if (!init) |
|
|
152 |
fieldDecorationID = FieldDecorationRegistry.DEC_ERROR; |
109 |
break; |
153 |
break; |
110 |
} |
154 |
} |
111 |
|
155 |
return fieldDecorationID; |
112 |
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault() |
|
|
113 |
.getFieldDecoration(fieldDecorationID); |
114 |
return fieldDecoration == null ? null : fieldDecoration.getImage(); |
115 |
} |
156 |
} |
116 |
} |
157 |
} |