xlawrence 2004/12/06 15:39:16 CET
Modified files:
src/java/org/jahia/suite/calendar/syncClients AboutDialog.java
CalendarFileManager.java
CommSettingsConfigPanel.java
EditCommSettingsDialog.java
ICalendarFileFilter.java
ICalendarSyncSource.java
SyncClient.java
SyncClientFrame.java
Log:
iCalendar Sync Client version 1.0 beta
Revision Changes Path
1.2 +1 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/AboutDialog.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/AboutDialog.java.diff?r1=1.1&r2=1.2&f=h
1.5 +1 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/CalendarFileManager.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/CalendarFileManager.java.diff?r1=1.4&r2=1.5&f=h
1.2 +1 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/CommSettingsConfigPanel.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/CommSettingsConfigPanel.java.diff?r1=1.1&r2=1.2&f=h
1.3 +1 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/EditCommSettingsDialog.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/EditCommSettingsDialog.java.diff?r1=1.2&r2=1.3&f=h
1.2 +1 -0
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/ICalendarFileFilter.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/ICalendarFileFilter.java.diff?r1=1.1&r2=1.2&f=h
1.6 +65 -120
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/ICalendarSyncSource.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/ICalendarSyncSource.java.diff?r1=1.5&r2=1.6&f=h
1.7 +62 -38
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClient.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClient.java.diff?r1=1.6&r2=1.7&f=h
1.5 +23 -7
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClientFrame.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClientFrame.java.diff?r1=1.4&r2=1.5&f=h
Index: AboutDialog.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/AboutDialog.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AboutDialog.java 26 Nov 2004 16:29:01 -0000 1.1
+++ AboutDialog.java 6 Dec 2004 14:39:15 -0000 1.2
@@ -53,6 +53,7 @@
* Simple common "About" Dialog showing information about the application.
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class AboutDialog extends JDialog implements
PropertyChangeListener {
Index: CalendarFileManager.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/CalendarFileManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CalendarFileManager.java 3 Dec 2004 11:13:42 -0000 1.4
+++ CalendarFileManager.java 6 Dec 2004 14:39:15 -0000 1.5
@@ -61,6 +61,7 @@
* This class reads, parses, validates and writes iCalendar files.
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class CalendarFileManager {
Index: CommSettingsConfigPanel.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/CommSettingsConfigPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CommSettingsConfigPanel.java 26 Nov 2004 16:29:01 -0000 1.1
+++ CommSettingsConfigPanel.java 6 Dec 2004 14:39:15 -0000 1.2
@@ -48,6 +48,7 @@
* EditCommSettingsDialog as a basic component for settings editing.
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class CommSettingsConfigPanel extends JPanel {
Index: EditCommSettingsDialog.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/EditCommSettingsDialog.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EditCommSettingsDialog.java 3 Dec 2004 11:13:42 -0000 1.2
+++ EditCommSettingsDialog.java 6 Dec 2004 14:39:15 -0000 1.3
@@ -57,6 +57,7 @@
* Connexion and authentication parameters for the remote sync server.
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class EditCommSettingsDialog extends JDialog implements
PropertyChangeListener {
Index: ICalendarFileFilter.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/ICalendarFileFilter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ICalendarFileFilter.java 26 Nov 2004 16:29:01 -0000 1.1
+++ ICalendarFileFilter.java 6 Dec 2004 14:39:15 -0000 1.2
@@ -45,6 +45,7 @@
* The only accepted file extension is ".ics"
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class ICalendarFileFilter extends FileFilter {
Index: ICalendarSyncSource.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/ICalendarSyncSource.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ICalendarSyncSource.java 3 Dec 2004 11:13:42 -0000 1.5
+++ ICalendarSyncSource.java 6 Dec 2004 14:39:15 -0000 1.6
@@ -63,6 +63,7 @@
* stored in .ics files and derive proper sync items.
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class ICalendarSyncSource implements SyncSource {
@@ -79,11 +80,14 @@
private Properties syncDatabase;
+ private int fileId;
+
/**
* Creates a new instance of ICalendarSyncSource
*/
public ICalendarSyncSource() {
syncDatabase = new Properties();
+ fileId = 0;
}
/**
@@ -180,6 +184,17 @@
public void commitSync() throws SyncException {
log.debug("commitSync()");
try {
+ Enumeration en = syncDatabase.keys();
+
+ while (en.hasMoreElements()) {
+ String key = (String)en.nextElement();
+ String value = syncDatabase.getProperty(key);
+ if (stateFromStateString(value) != SyncItemState.DELETED) {
+ setState(key, SyncItemState.SYNCHRONIZED,
+ lastModifiedFromStateString(value));
+ }
+ }
+
storeSyncDatabase();
} catch (IOException e) {
throw new SyncException(e.getMessage(), e);
@@ -244,13 +259,23 @@
*/
public SyncItem setSyncItem(Principal principal, SyncItem syncItem)
throws SyncException {
- log.debug("setSyncItem(" + principal + " , " +
+ log.debug("setSyncItem(" + principal + " , GUID: " +
syncItem.getKey().getKeyAsString() + ")");
- try {
- String fileName = syncItem.getKey().getKeyAsString();
+ try {
byte[] fileContent =
(byte[])syncItem.getPropertyValue(SyncItem.PROPERTY_BINARY_CONTENT);
+ final String fileName;
+
+ if (!(new String(fileContent).startsWith("BEGIN"))) {
+ // It is the item containing the calendar properties
+ fileName = "0";
+ } else {
+ fileName = getFileID();
+ }
+
+ log.debug("fileName (LUID): "+fileName);
+
File file = new File(sourceDirectory, fileName);
FileOutputStream fos = new FileOutputStream(file);
if (fileContent != null) {
@@ -259,12 +284,12 @@
fos.flush();
fos.close();
- Date date =
- (Date)syncItem.getPropertyValue(SyncItem.PROPERTY_TIMESTAMP);
+ Date date = (Date)
+ syncItem.getPropertyValue(SyncItem.PROPERTY_TIMESTAMP);
file.setLastModified(date.getTime());
- setState(principal, fileName, SyncItemState.SYNCHRONIZED, date);
+ setState(fileName, SyncItemState.SYNCHRONIZED, date);
SyncItem newSyncItem =
new SyncItemImpl(this, fileName, SyncItemState.NEW);
@@ -306,109 +331,6 @@
}
/**
- * The synchronization database is stored in a file whose name is given
- * by the value of the constant DATABASE_FILE_NAME prefixed by the user
name
- * and the device id. For example:
- * <pre>
- * guest.Sync4jTest.sync.db
- * </pre>
- * The database is a property file where each entry has the following
- * format:
- * <pre>
- * [filename]=[state][lastmodified_timestamp]
- * </pre>
- * For example:
- * <blockquote>
- * readme.txt=U98928743098094
- * </blockquote>
- * <p>
- * updateSyncDatabase works as follows:
- * <pre>
- * 1. Read the existing database (if it exists)
- * 2. Scan the source directory getting all files in the directory
- * 3. For each file f in the source directory
- * 3.1. If f is already in the database
- * 3.1.1. If f has been modified after the lastmodified_timestamp
stored into the database
- * 3.1.1.1. Set the state of the file to UPDATE and store the new
lastmodified_timestamp
- * 3.2. Else
- * 3.2.1. Add f to the database setting its state to NEW and store
the lastmodified_timestamp
- * 3. End For each
- * 4. For each file f in the database
- * 4.1. If f does not exist in the source directory
- * 4.1.1. Set the state to DELETED
- * 5. End For each
- * </pre>
- * <p>
- * At the end of the process, the updated database is saved and than
returned.
- *
- * @return the updated databse. In case of error, an error message is
traced
- * and an empty Properties object is returned.
- */
- private Properties updateSyncDatabase(Principal principal) throws
SyncException{
-
- Properties syncDatabase = new Properties();
-
- try {
- File fileSyncDatabase = getDatabaseFile();
-
- // Reads the existing database
- if (fileSyncDatabase.exists()) {
- FileInputStream fis = new FileInputStream(fileSyncDatabase);
- syncDatabase.load(fis);
- fis.close();
- }
-
- // Get the list of files in the source directory, 1 file per
SyncItem
- Vector existingFiles = getExistingFiles();
-
- // Get the list of the file in the databsae
- Enumeration databaseFiles = syncDatabase.propertyNames();
-
- String state, fileName;
- long lastModified;
-
- int n = existingFiles.size();
- for (int i=0; i < n; ++i) {
- fileName = (String)existingFiles.elementAt(i);
- lastModified = new File(sourceDirectory,
fileName).lastModified();
-
- state = syncDatabase.getProperty(fileName);
-
- if (state != null) {
- // The file is already in the database
- if (lastModified > lastModifiedFromStateString(state)) {
- state = buildStateString(SyncItemState.UPDATED,
lastModified);
- syncDatabase.setProperty(fileName, state);
- }
- } else {
- // The file is not in the database
- state = buildStateString(SyncItemState.NEW,
lastModified);
- syncDatabase.setProperty(fileName, state);
- }
- }
-
- while (databaseFiles.hasMoreElements()) {
- fileName = (String)databaseFiles.nextElement();
-
- if (!existingFiles.contains(fileName)) {
- state = buildStateString(SyncItemState.DELETED,
- System.currentTimeMillis());
- syncDatabase.setProperty(fileName, state);
- }
- }
-
- // Save & return
- FileOutputStream fos = new FileOutputStream(fileSyncDatabase);
- syncDatabase.store(fos, DATABASE_HEADER);
- fos.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return syncDatabase;
- }
-
- /**
* Extracts the first byte of the given state String
* @param state The String containing the state
* @return the state
@@ -447,6 +369,20 @@
}
/**
+ *
+ */
+ protected void setState(String file, char state, Date since) {
+ syncDatabase.setProperty(file, buildStateString(state,
since.getTime()));
+ }
+
+ /**
+ *
+ */
+ protected void setState(String file, char state, long since) {
+ syncDatabase.setProperty(file, buildStateString(state, since));
+ }
+
+ /**
* The synchronization database is stored in a file whose name is given
* by the value of the constant DATABASE_FILE_NAME.
* The database is a property file where each entry has the following
@@ -516,6 +452,7 @@
state = buildStateString(SyncItemState.UPDATED,
lastModified);
syncDatabase.setProperty(fileName, state);
}
+
} else {
// The file is not in the database
log.debug("Item: "+fileName+": NEW");
@@ -531,7 +468,9 @@
(stateFromStateString(syncDatabase.getProperty(fileName)) ==
SyncItemState.DELETED)) {
syncDatabase.remove(fileName);
+
} else if (!existingFiles.contains(fileName)) {
+ log.debug("Item: "+fileName+": DELETED");
state = buildStateString(SyncItemState.DELETED,
System.currentTimeMillis());
syncDatabase.setProperty(fileName, state);
@@ -546,7 +485,10 @@
File fileSyncDatabase = getDatabaseFile();
FileOutputStream fos = new FileOutputStream(fileSyncDatabase);
syncDatabase.store(fos, DATABASE_HEADER);
+ fos.flush();
fos.close();
+
+
}
/**
@@ -568,14 +510,6 @@
}
/**
- *
- */
- protected void setState(Principal principal, String file, char state,
- Date since) {
- syncDatabase.setProperty(file, buildStateString(state,
since.getTime()));
- }
-
- /**
* Filters the SyncItems in the synchronization database (after a
refresh)
* based on the given principal, last sync timestamp and state (see
* SyncItemState). If state is equals to UNKNOWN all items are
returned.<br>
@@ -588,9 +522,7 @@
* state.
*/
private SyncItem[] filterSyncItems(Principal principal, Date since,
- char state) throws SyncException {
- Properties syncDatabase = updateSyncDatabase(principal);
-
+ char state) throws SyncException {
Vector syncItems = new Vector();
long fileTimestamp,
@@ -627,4 +559,17 @@
return ret;
}
+
+ /**
+ * Generates increasing LUID values for Sync Item files
+ * @return The LUID as a String
+ */
+ private String getFileID() {
+ if (fileId == 0) {
+ fileId = new File(sourceDirectory).listFiles().length - 1;
+ if (fileId < 0) fileId = 0;
+ }
+ fileId++;
+ return new Integer(fileId).toString();
+ }
}
Index: SyncClient.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClient.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SyncClient.java 3 Dec 2004 11:13:42 -0000 1.6
+++ SyncClient.java 6 Dec 2004 14:39:15 -0000 1.7
@@ -62,6 +62,7 @@
* This is the controller of the iCalendar synchronization client.
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class SyncClient {
@@ -82,15 +83,6 @@
}
/**
- * Prints out an Exception
- * @param e The Exception to print/log
- */
- static void printException(Exception e) {
- log.error(e);
- e.printStackTrace();
- }
-
- /**
* This method creates a new File for each SyncItem
* @param file The file to store the SyncItem
* @param content The content of the file
@@ -109,13 +101,14 @@
byte[] buf = new byte[(int)file.length()];
fin.read(buf);
fin.close();
- String currentContent = new String(buf);
+ String currentContent = new String(buf).trim();
// If the content has not changed between 2 syncs...
if (currentContent.equals(content)) {
// ... do nothing
- log.debug("Content has not changed for: "+file.getName());
+ log.debug("Content has not changed for item:
"+file.getName());
return;
+
} else {
file.delete();
file.createNewFile();
@@ -134,58 +127,90 @@
* file.
* @param file The SyncItem file to append to the iCalendar file
* @param fileName The iCalendar file (*.ics)
- * @param syncItemFileSuffix
- * @throws FileNotFoundException
- * @throws IOException
- * @throws ValidationException
- * @throws ParserException
+ * @param dbDir The directory where the sync item files are kept
+ * @throws FileNotFoundException If a syncItem file is not found
+ * @throws IOException If something goes wrong during reading/writing
+ * @throws ValidationException If the iCalendar resulting from the
+ * merge of the syncItem files is not valid
+ * @throws ParserException If the iCalendar resulting from the
+ * merge of the syncItem files is not in the
+ * right format
*/
private void updateICSFile(File[] files, String fileName, String
- syncItemFileSuffix) throws FileNotFoundException, IOException,
+ dbDir) throws FileNotFoundException, IOException,
ValidationException, ParserException {
String[] contents = new String[files.length];
+ // file name
+ int j=0;
for (int i=0; i<files.length; i++) {
- File f = new File(syncItemFileSuffix + i);
+ File f = new File(dbDir + "/" + j);
+ if (!f.exists()) {
+ i--;
+ j++;
+ continue;
+ }
FileInputStream fis = new FileInputStream(f);
byte[] content = new byte[(int)f.length()];
fis.read(content);
contents[i] = new String(content);
fis.close();
+ j++;
}
calManager.writeCalendarItems(fileName, contents);
}
/**
- * Starts the synchronization process
+ * Performs the synchronization process.
* @param fileName The file absolute name to synchronize (.ics files
only)
- * @throws FileNotFoundException
- * @throws IOException
- * @throws SyncException
- * @throws DMException
- * @throws ParserException
- * @throws ValidationException
+ * @throws FileNotFoundException If a specified file is not found
+ * @throws IOException If an error occurs while writing/reading files
+ * @throws SyncException If the SyncManager encounters a problem
+ * @throws DMException If the DeviceManager encounters a problem
+ * @throws ParserException If the iCalendar file is not in the right
format
+ * @throws ValidationException If the iCalendar file is not valid (cf.
RFC-2445)
*/
public void sync(String fileName) throws FileNotFoundException,
IOException,
SyncException, DMException, ParserException, ValidationException {
+
+ // Get the Sync Items from the iCalendar file
String[] items = calManager.getCalendarItems(fileName);
syncClientGUI.log("File is valid. Preparing Sync data...");
- String[] userValues = syncClientGUI.getSettingValues();
+ final String[] userValues = syncClientGUI.getSettingValues();
+
+ // The directory name to store the Sync Items files
+ final String dbDirectoryName = new String(DB_DIRECTORY +
userValues[1] +
+ userValues[3]);
- File dir = new File(DB_DIRECTORY + new String(userValues[1]) +
- new String(userValues[3]));
+ final File dir = new File(dbDirectoryName);
+ // create the db directory if it does not exist
dir.mkdir();
+
+ String[] files = dir.list();
+
+ // Generate all Sync Item files
for (int i=0; i<items.length; i++) {
- File f = new File(DB_DIRECTORY + new String(userValues[1] +
- userValues[3] +"/"+ i));
- generateSyncItemFile(f, items[i]);
+ File f = new File(dbDirectoryName +"/"+ i);
+ generateSyncItemFile(f, items[i].trim());
+ }
+
+ if (files.length > items.length) {
+ // There are more files in the directory than sync items
+ // -> delete unecessary files <-
+ for (int i=items.length; i<files.length; i++) {
+ File f = new File(dbDirectoryName +"/"+ i);
+ f.delete();
+ }
}
+
syncClientGUI.log("Sync data ready. Synchronizing...");
Properties props = System.getProperties();
+ // The root configuration directoy
props.put(SimpleDeviceManager.PROP_DM_DIR_BASE, "conf/sync4j");
System.setProperties(props);
+ // Runtime properties for the SyncManager
Properties properties = new Properties();
// The initial URL for the SyncML request
@@ -202,7 +227,8 @@
// The target URI of the server being contacted
String uri = userValues[0].substring(0, end + delimiter);
- properties.put(SyncManager.PARAM_TARGETLOCALURI, constructURL(new
String(uri)));
+ properties.put(SyncManager.PARAM_TARGETLOCALURI,
+ constructURL(new String(uri)));
// Username and password for authentication to the sync server
properties.put(SyncManager.PARAM_USERNAME, new
String(userValues[1]));
@@ -212,18 +238,16 @@
properties.put(SyncManager.PARAM_DEVICEID, new
String(userValues[3]));
// Set the property for the sourceDirectoy database
- properties.put("sourceDirectory", new String(DB_DIRECTORY +
userValues[1]) +
- userValues[3]);
+ properties.put("sourceDirectory", new String(dbDirectoryName));
+ // Perform the actual SYNCHRONIZATION of the data
SyncManager syncManager = SyncManager.getSyncManager(".",
properties);
syncManager.sync();
syncClientGUI.log("Updating iCalendar file...");
-
- String syncItemFileSuffix = DB_DIRECTORY + new String(userValues[1] +
- userValues[3] +"/");
- updateICSFile(dir.listFiles(), fileName, syncItemFileSuffix);
+ // Update the source iCalendar file
+ updateICSFile(dir.listFiles(), fileName, dbDirectoryName);
}
/**
Index: SyncClientFrame.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncClients/SyncClientFrame.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SyncClientFrame.java 3 Dec 2004 11:13:42 -0000 1.4
+++ SyncClientFrame.java 6 Dec 2004 14:39:15 -0000 1.5
@@ -86,9 +86,11 @@
* This is the main Window of the iCalendar synchronization client GUI.
*
* @author Xavier Lawrence
+ * @version 1.0
*/
public class SyncClientFrame extends JFrame implements Runnable {
+ // file to keep the user's settings
public static final String configFileName = "values.dat";
private static Logger log = Logger.getLogger(SyncClientFrame.class);
@@ -97,6 +99,8 @@
private EditCommSettingsDialog settingsDialog;
private AboutDialog aboutDialog;
private JFileChooser fc;
+
+ private boolean busy;
// The controller object that will handle the proper data processing
actions
private SyncClient controller;
@@ -106,6 +110,7 @@
* @param controller The SyncClient controller object for this GUI
*/
public SyncClientFrame(final SyncClient controller) {
+ busy = false;
this.controller = controller;
initComponents();
fileFilter = new ICalendarFileFilter();
@@ -119,6 +124,7 @@
readDataFile();
setFrameLocation();
show();
+ setDefaultCloseOperation(super.DO_NOTHING_ON_CLOSE);
}
/**
@@ -127,13 +133,15 @@
*/
public static void setLookAndFeel() {
try {
-
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
+ UIManager.setLookAndFeel(
+ "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
try {
-
UIManager.setLookAndFeel("com.sun.java.swing.plaf.mac.MacLookAndFeel");
+ UIManager.setLookAndFeel(
+ "com.sun.java.swing.plaf.mac.MacLookAndFeel");
} catch (Exception ee) {
try {
- UIManager.setLookAndFeel("plaf.metal.MetalLookAndFeel");;
+ UIManager.setLookAndFeel("plaf.metal.MetalLookAndFeel");
} catch (Exception eee) {}
}
}
@@ -426,6 +434,7 @@
private void syncButtonActionPerformed(ActionEvent evt) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ busy = true;
setAllEnable(this, false);
// Look at method run for more details about the synchronization
Thread t = new Thread(this);
@@ -455,6 +464,13 @@
/** Exit the Application */
private void exitForm(WindowEvent evt) {
+ if (busy && JOptionPane.showConfirmDialog(this,
+ "Synchronization not finished ! Exit anyway ?",
+ "Exit",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
+ return;
+ }
System.exit(0);
}
@@ -669,8 +685,8 @@
return settingsDialog.getValues();
}
-
/**
+ * Performs the actual synchronization in a separate Thread
* @see Runnable
*/
public void run() {
@@ -682,16 +698,16 @@
// Launch the actual sync process
controller.sync(fileValue.getText());
- log("Synchronization finished successfully !");
+ log("\nSynchronization finished successfully !");
} catch (IllegalArgumentException e) {
showError(e.getMessage());
} catch (Exception e) {
log("Error: "+e.getMessage());
- log("Synchronization failed !");
- e.printStackTrace();
+ log("\nSynchronization FAILED !");
}
setAllEnable(this, true);
setCursor(Cursor.getDefaultCursor());
+ busy = false;
}
}