Converted all CRLF to LF.
[indepmod/mmn.git] / IndependentModeler / src / cz / cvut / promod / services / projectService / dialogs / SyncDialog.java
blob283b96179c3b155869e081355794b92c26bc7a7c
1 package cz.cvut.promod.services.projectService.dialogs;
3 import javax.swing.*;
4 import java.awt.event.*;
6 /**
7 * ProMod, master thesis project
8 * User: Petr Zverina, petr.zverina@gmail.com
9 * Date: 22:05:47, 13.11.2009
12 /**
13 * SyncDialog controller.
15 public class SyncDialog extends SyncDialogView{
17 public static final String NEW_LINE_MARK = "\n";
19 private SwingWorker swingWorker = null;
21 /**
22 * Creates a new SyncDialog.
24 * @param title is the SyncDialog title.
26 public SyncDialog(final String title){
27 super(title);
29 initEventHandling();
31 okButton.setEnabled(false);
32 cancelButton.setEnabled(false);
34 getRootPane().setDefaultButton(okButton);
36 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
38 setModal(true);
41 /**
42 * Initialize event handling.
44 private void initEventHandling() {
45 okButton.addActionListener(new ActionListener(){
46 public void actionPerformed(ActionEvent e) {
47 disposeDialog();
49 });
51 cancelButton.addActionListener(new ActionListener(){
52 public void actionPerformed(ActionEvent e) {
53 swingWorker.cancel(true);
55 });
57 getRootPane().registerKeyboardAction(new ActionListener(){
58 public void actionPerformed(ActionEvent actionEvent) {
59 escape();
62 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
63 JComponent.WHEN_IN_FOCUSED_WINDOW);
65 addWindowListener(new WindowAdapter(){
66 @Override
67 public void windowClosing(WindowEvent windowEvent) {
68 escape();
70 });
73 /**
74 * When the EXC or cross buton is pressed.
76 private void escape() {
77 if(okButton.isEnabled()){
78 disposeDialog();
82 /**
83 * Controls dialogs final appearance.
85 * @param errors if true the dialog remains visible, false -> the dialog will be disposed
87 public void syncComplete(final boolean errors){
88 if(errors){
89 okButton.setEnabled(true);
90 } else {
91 disposeDialog();
95 /**
96 * Sets the cancel button enabled.
98 public void disableCancelButton(){
99 cancelButton.setEnabled(false);
103 * Disposes the dialog.
105 public void disposeDialog(){
106 setVisible(false);
107 dispose();
111 * Appends a new error message to the synchronization error dialog.
113 * @param message is the error message
115 * @param addEmptyLine if true then there will be added an empty line after this error message
117 public void appendErrorInfo(final String message, final boolean addEmptyLine){
118 errorsTextArea.append(message);
120 errorsTextArea.append(NEW_LINE_MARK);
122 if(addEmptyLine){
123 errorsTextArea.append(NEW_LINE_MARK);
128 * Update current sync position.
129 * @param text the location
131 public void updatePosition(final String text){
132 currentSearchLocationLabel.setText(text);
136 * Sets the sync worker.
137 * @param swingWorker the sync worker.
139 public void setSyncWorker(final SwingWorker swingWorker) {
140 if(swingWorker == null){
141 return;
144 this.swingWorker = swingWorker;
146 cancelButton.setEnabled(true);