1 package cz
.cvut
.promod
.gui
.dialogs
.configurationChangeDialog
;
3 import cz
.cvut
.promod
.services
.ModelerSession
;
4 import cz
.cvut
.promod
.services
.projectService
.results
.ConfigurationDifference
;
5 import cz
.cvut
.promod
.plugin
.notationSpecificPlugIn
.notation
.Notation
;
8 import java
.awt
.event
.ActionListener
;
9 import java
.awt
.event
.ActionEvent
;
10 import java
.awt
.event
.KeyEvent
;
12 import org
.apache
.log4j
.Logger
;
17 * ProMod, master thesis project
18 * User: Petr Zverina, petr.zverina@gmail.com
19 * Date: 17:55:32, 12.12.2009
21 * Dialog displaying differences between actual ProMod configuration and the ProMod configuration that
22 * was actual at the time, when the project, that is now being loaded, was saved.
24 public class ConfigurationDiffDialog
extends ConfigurationDiffDialogView
{
26 private static final Logger LOG
= Logger
.getLogger(ConfigurationDiffDialog
.class);
28 private static final String TITLE_LABEL
=
29 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.title");
30 private static final String MISSING_NOTATION_LABEL
=
31 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.missing.notation");
32 private static final String LOADED_VALUE_LABEL
=
33 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.loaded.value");
34 private static final String ACTUAL_VALUE_LABEL
=
35 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.actual.value");
36 private static final String MISSING_MODULE_LABEL
=
37 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.missing.module");
38 private static final String RELATED_IDENTIFIER_LABEL
=
39 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.related.notation");
40 private static final String MISSING_EXTENSION_LABEL
=
41 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.missing.extension");
42 private static final String DIFF_EXTENSION_LABEL
=
43 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.different.extension");
44 private static final String DIFF_ABBREVIATION_LABEL
=
45 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.different.abbreviation");
46 private static final String DIFF_NAME_LABEL
=
47 ModelerSession
.getCommonResourceBundle().getString("modeler.configuration.different.name");
49 public final String NEW_LINE
= "\n";
53 * Constructs a new ConfigurationDiffDialog class.
55 * @param differences is the list containing all configuration differences
57 public ConfigurationDiffDialog(final List
<ConfigurationDifference
> differences
){
58 setTitle(TITLE_LABEL
);
62 initReport(differences
);
66 getRootPane().setDefaultButton(hideButton
);
72 * Initialize event handling.
74 private void initEventHandling() {
75 hideButton
.addActionListener(new ActionListener(){
76 public void actionPerformed(ActionEvent e
) {
81 getRootPane().registerKeyboardAction(new ActionListener(){
82 public void actionPerformed(ActionEvent actionEvent
) {
86 KeyStroke
.getKeyStroke(KeyEvent
.VK_ESCAPE
, 0),
87 JComponent
.WHEN_IN_FOCUSED_WINDOW
);
93 private void disposeDialog(){
99 * Initialize messages about configuration differences.
101 * @param differences all configuration differences
103 private void initReport(final List
<ConfigurationDifference
> differences
) {
104 for(final ConfigurationDifference difference
: differences
){
105 switch (difference
.getChangeType()){
106 case MISSING_NOTATION
:
107 publishMissingNotationDiff(difference
);
110 publishMissingModuleDiff(difference
);
112 case MISSING_EXTENSION
:
113 publishMissingExtensionDiff(difference
);
115 case DIFFERENT_FULL_NAME
:
116 publishDiffName(difference
);
118 case DIFFERENT_ABBREVIATION
:
119 publishDiffAbbreviation(difference
);
121 case DIFFERENT_EXTENSION
:
122 publishDiffExtension(difference
);
125 LOG
.error("No such a configuration change option.");
128 diffTextArea
.append(NEW_LINE
);
129 diffTextArea
.append(NEW_LINE
);
134 * Publishes different full name.
136 * @param difference is the difference detail
138 private void publishDiffName(final ConfigurationDifference difference
) {
139 diffTextArea
.append(DIFF_NAME_LABEL
);
140 diffTextArea
.append(NEW_LINE
);
141 diffTextArea
.append(LOADED_VALUE_LABEL
+ " " + difference
.getMessage());
142 diffTextArea
.append(NEW_LINE
);
143 diffTextArea
.append(ACTUAL_VALUE_LABEL
+ " " + ModelerSession
.getNotationService().getNotation(difference
.getIdentifier()).getFullName());
147 * Publishes different abbreviation.
149 * @param difference is the difference detail
151 private void publishDiffAbbreviation(final ConfigurationDifference difference
) {
152 diffTextArea
.append(DIFF_ABBREVIATION_LABEL
);
153 diffTextArea
.append(NEW_LINE
);
154 diffTextArea
.append(LOADED_VALUE_LABEL
+ " " + difference
.getMessage());
155 diffTextArea
.append(NEW_LINE
);
156 diffTextArea
.append(ACTUAL_VALUE_LABEL
+ " " + ModelerSession
.getNotationService().getNotation(difference
.getIdentifier()).getAbbreviation());
160 * Publishes different extension.
162 * @param difference is the difference detail
164 private void publishDiffExtension(final ConfigurationDifference difference
) {
165 diffTextArea
.append(DIFF_EXTENSION_LABEL
);
166 diffTextArea
.append(NEW_LINE
);
167 diffTextArea
.append(LOADED_VALUE_LABEL
+" " + difference
.getMessage());
168 diffTextArea
.append(NEW_LINE
);
170 ACTUAL_VALUE_LABEL
+ " " + ModelerSession
.getNotationService().getNotation(
171 difference
.getIdentifier()
172 ).getLocalIOController().getNotationFileExtension());
176 * Publishes missing extension difference.
178 * @param difference is the difference detail
180 private void publishMissingExtensionDiff(final ConfigurationDifference difference
) {
181 diffTextArea
.append(MISSING_EXTENSION_LABEL
);
182 diffTextArea
.append(NEW_LINE
);
183 diffTextArea
.append(LOADED_VALUE_LABEL
+ " " + difference
.getMessage());
187 * Publishes missing module difference.
189 * @param difference is the difference detail
191 private void publishMissingModuleDiff(final ConfigurationDifference difference
) {
192 diffTextArea
.append(MISSING_MODULE_LABEL
);
193 diffTextArea
.append(NEW_LINE
);
195 final Notation notation
= ModelerSession
.getNotationService().getNotation(difference
.getIdentifier());
196 if(notation
!= null){
197 diffTextArea
.append(RELATED_IDENTIFIER_LABEL
+ "" + notation
.getFullName() + " (" + notation
.getIdentifier() + ").");
198 diffTextArea
.append(NEW_LINE
);
200 LOG
.error("Unavailable notation for given identifier: " + difference
.getIdentifier());
203 diffTextArea
.append(LOADED_VALUE_LABEL
+ " " + difference
.getMessage());
207 * Publishes missing notation difference.
209 * @param difference is the difference detail
211 private void publishMissingNotationDiff(final ConfigurationDifference difference
) {
212 diffTextArea
.append(MISSING_NOTATION_LABEL
);
213 diffTextArea
.append(NEW_LINE
);
214 diffTextArea
.append(LOADED_VALUE_LABEL
+ " " + difference
.getMessage());