From 3f08f3f32710a7baee9014832d4794f23db76179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Jouin?= Date: Wed, 26 Apr 2023 04:08:09 +0200 Subject: [PATCH] v4.9.0-beta --- sources/META-INF/MANIFEST.MF | 2 +- .../database/DBCheckForPluginUpdate.java | 38 +- .../database/DBDatabaseEntry.java | 10 +- .../archicontribs/database/DBExporter.java | 4 +- .../archicontribs/database/DBImporter.java | 4 +- .../org/archicontribs/database/DBLogger.java | 4 +- .../org/archicontribs/database/DBPlugin.java | 41 +- .../org/archicontribs/database/GUI/DBGui.java | 3113 ++++++++--------- .../database/GUI/DBGuiAdminDatabase.java | 40 +- .../database/GUI/DBGuiComponentHistory.java | 16 +- .../database/GUI/DBGuiExportModel.java | 180 +- .../database/GUI/DBGuiImportComponents.java | 45 +- .../database/GUI/DBGuiImportImage.java | 4 +- .../database/GUI/DBGuiImportModel.java | 99 +- .../database/GUI/DBGuiReplaceElement.java | 2 +- .../database/GUI/DBGuiShowDebug.java | 182 +- .../database/GUI/DBGuiUtils.java | 446 +++ .../connection/DBDatabaseConnection.java | 115 +- .../DBDatabaseImportConnection.java | 10 +- .../database/data/DBChecksum.java | 4 +- .../menu/DBMenuComponentHistoryHandler.java | 6 +- .../menu/DBMenuComponentImportHandler.java | 4 +- .../menu/DBMenuConvertIdsHandler.java | 12 +- .../menu/DBMenuElementReplaceHandler.java | 4 +- .../menu/DBMenuModelExportHandler.java | 4 +- .../menu/DBMenuModelImportHandler.java | 4 +- .../database/menu/DBMenuShowDebugHandler.java | 6 +- .../database/model/DBArchimateModel.java | 191 +- .../database/model/DBMetadata.java | 19 +- .../commands/DBDeleteProfileCommand.java | 36 + .../DBImportElementFromIdCommand.java | 8 +- .../DBImportProfileFromIdCommand.java | 195 ++ .../CanvasModelBlockSection.java | 3 +- .../DiagramModelImageSection.java | 3 +- .../DBDatabaseEntryTableEditor.java | 19 +- .../preferences/DBPreferencePage.java | 193 +- 36 files changed, 2909 insertions(+), 2157 deletions(-) create mode 100644 sources/src/org/archicontribs/database/GUI/DBGuiUtils.java create mode 100644 sources/src/org/archicontribs/database/model/commands/DBDeleteProfileCommand.java create mode 100644 sources/src/org/archicontribs/database/model/commands/DBImportProfileFromIdCommand.java diff --git a/sources/META-INF/MANIFEST.MF b/sources/META-INF/MANIFEST.MF index a2648d0d..66e27e06 100644 --- a/sources/META-INF/MANIFEST.MF +++ b/sources/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Database export / import plugin for Archimate Tool Bundle-SymbolicName: org.archicontribs.database;singleton:=true -Bundle-Version: 4.9.0.alpha +Bundle-Version: 4.9.0.beta Bundle-Vendor: Herve Jouin Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-11 diff --git a/sources/src/org/archicontribs/database/DBCheckForPluginUpdate.java b/sources/src/org/archicontribs/database/DBCheckForPluginUpdate.java index 57d38ab6..983bc6ac 100644 --- a/sources/src/org/archicontribs/database/DBCheckForPluginUpdate.java +++ b/sources/src/org/archicontribs/database/DBCheckForPluginUpdate.java @@ -29,7 +29,7 @@ import javax.net.ssl.HttpsURLConnection; import org.apache.log4j.Level; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.eclipse.core.runtime.IStatus; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; @@ -87,7 +87,7 @@ public DBCheckForPluginUpdate(boolean showPopup, String pluginApiUrl, String rel dropinsFolderName = dropinsFolder.getCanonicalPath(); } catch (IOException err) { if ( showPopup ) - DBGui.popup(Level.ERROR, "Failed to get dropins folder.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get dropins folder.", err); else logger.error("Failed to get dropins folder.", err); return; @@ -95,9 +95,9 @@ public DBCheckForPluginUpdate(boolean showPopup, String pluginApiUrl, String rel if ( !dropinsFolder.canWrite() ) { if ( showPopup ) - DBGui.popup(Level.ERROR, "Can't write to \""+dropinsFolderName+"\" folder."); + DBGuiUtils.popup(Level.ERROR, "Can't write to \""+dropinsFolderName+"\" folder."); else - DBGui.popup(Level.ERROR, "Can't write to \""+dropinsFolderName+"\" folder."); + DBGuiUtils.popup(Level.ERROR, "Can't write to \""+dropinsFolderName+"\" folder."); return; } @@ -105,7 +105,7 @@ public DBCheckForPluginUpdate(boolean showPopup, String pluginApiUrl, String rel JSONParser parser = new JSONParser(); if ( showPopup ) - DBGui.popup("Checking for a new database plugin version on GitHub ..."); + DBGuiUtils.showPopupMessage("Checking for a new database plugin version on GitHub ..."); else logger.debug("Checking for a new database plugin version on GitHub"); @@ -164,8 +164,8 @@ protected PasswordAuthentication getPasswordAuthentication() { if ( result == null ) { if ( showPopup ) { - DBGui.closePopup(); - DBGui.popup(Level.ERROR, "Failed to check for new database plugin version.\n\nParsing error."); + DBGuiUtils.closePopupMessage(); + DBGuiUtils.popup(Level.ERROR, "Failed to check for new database plugin version.\n\nParsing error."); } else logger.error("Failed to check for new database plugin version.\n\nParsing error."); return; @@ -184,19 +184,19 @@ protected PasswordAuthentication getPasswordAuthentication() { } } - if ( showPopup ) DBGui.closePopup(); + if ( showPopup ) DBGuiUtils.closePopupMessage(); if ( versions.isEmpty() ) { if ( showPopup ) - DBGui.popup(Level.ERROR, "Failed to check for new database plugin version.\n\nDid not find any "+DBPlugin.pluginsPackage+"_*.archiplugin file."); + DBGuiUtils.popup(Level.ERROR, "Failed to check for new database plugin version.\n\nDid not find any "+DBPlugin.pluginsPackage+"_*.archiplugin file."); else logger.error("Failed to check for new database plugin version.\n\nDid not find any "+DBPlugin.pluginsPackage+"_*.archiplugin file."); return; } } catch (Exception e) { if ( showPopup ) { - DBGui.closePopup(); - DBGui.popup(Level.ERROR, "Failed to check for new version on GitHub.", e); + DBGuiUtils.closePopupMessage(); + DBGuiUtils.popup(Level.ERROR, "Failed to check for new version on GitHub.", e); } else { logger.error("Failed to check for new version on GitHub.", e); } @@ -210,7 +210,7 @@ protected PasswordAuthentication getPasswordAuthentication() { if ( DBPlugin.pluginVersion.compareTo(new Version(entry.getKey())) >= 0 ) { if ( showPopup ) - DBGui.popup(Level.INFO, "You already have got the latest version: "+DBPlugin.pluginVersion.toString()); + DBGuiUtils.popup(Level.INFO, "You already have got the latest version: "+DBPlugin.pluginVersion.toString()); else logger.info("You already have got the latest version: "+DBPlugin.pluginVersion.toString()); return; @@ -218,7 +218,7 @@ protected PasswordAuthentication getPasswordAuthentication() { if ( !DBPlugin.pluginsFilename.endsWith(".jar") ) { if ( showPopup ) - DBGui.popup(Level.ERROR,"A new version of the database plugin is available:\n actual version: "+DBPlugin.pluginVersion.toString()+"\n new version: "+entry.getKey()+"\n\nUnfortunately, it cannot be downloaded while Archi is running inside Eclipse."); + DBGuiUtils.popup(Level.ERROR,"A new version of the database plugin is available:\n actual version: "+DBPlugin.pluginVersion.toString()+"\n new version: "+entry.getKey()+"\n\nUnfortunately, it cannot be downloaded while Archi is running inside Eclipse."); else logger.error("A new version of the database plugin is available:\n actual version: "+DBPlugin.pluginVersion.toString()+"\n new version: "+entry.getKey()+"\n\nUnfortunately, it cannot be downloaded while Archi is running inside Eclipse."); return; @@ -226,7 +226,7 @@ protected PasswordAuthentication getPasswordAuthentication() { boolean ask = true; while ( ask ) { - this.display.syncExec(new Runnable() { @Override public void run() { DBCheckForPluginUpdate.this.answer = DBGui.question("A new version of the database plugin is available:\n actual version: "+DBPlugin.pluginVersion.toString()+"\n new version: "+entry.getKey()+"\n\nDo you wish to download and install it ?", new String[] {"Yes", "No", "Check release note"}); }}); + this.display.syncExec(new Runnable() { @Override public void run() { DBCheckForPluginUpdate.this.answer = DBGuiUtils.question("A new version of the database plugin is available:\n actual version: "+DBPlugin.pluginVersion.toString()+"\n new version: "+entry.getKey()+"\n\nDo you wish to download and install it ?", new String[] {"Yes", "No", "Check release note"}); }}); switch ( this.answer ) { case 0: ask = false ; break; // Yes case 1: return ; // No @@ -285,10 +285,10 @@ protected PasswordAuthentication getPasswordAuthentication() { try { Files.deleteIfExists(this.fileSystem.getPath(newPluginFilename)); } catch (Exception err) { - DBGui.popup(Level.ERROR, "Failed to delete partially downloaded file \""+newPluginFilename+"\".", err); + DBGuiUtils.popup(Level.ERROR, "Failed to delete partially downloaded file \""+newPluginFilename+"\".", err); } if ( showPopup ) - DBGui.popup(Level.ERROR, "Failed to download the new version of the database plugin.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to download the new version of the database plugin.", e); else logger.error("Failed to download the new version of the database plugin.",e); return; @@ -301,21 +301,21 @@ protected PasswordAuthentication getPasswordAuthentication() { IStatus status = this.dropinsPluginHandler.installFile(new File(newPluginFilename)); if ( !status.isOK() ) { if ( showPopup ) - DBGui.popup(Level.ERROR, "Failed to install new plugin version."); + DBGuiUtils.popup(Level.ERROR, "Failed to install new plugin version."); else logger.error("Failed to install new plugin version."); return; } } catch (IOException e) { if ( showPopup ) - DBGui.popup(Level.ERROR, "Failed to install new plugin version.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to install new plugin version.", e); else logger.error("Failed to install new plugin version.",e); return; } - if( DBGui.question("A new version on the database plugin has been downloaded. Archi needs to be restarted to install it.\n\nDo you wish to restart Archi now ?") ) { + if( DBGuiUtils.question("A new version on the database plugin has been downloaded. Archi needs to be restarted to install it.\n\nDo you wish to restart Archi now ?") ) { this.display.syncExec(new Runnable() { @Override public void run() { PlatformUI.getWorkbench().restart(); diff --git a/sources/src/org/archicontribs/database/DBDatabaseEntry.java b/sources/src/org/archicontribs/database/DBDatabaseEntry.java index b4846737..0b9c3502 100644 --- a/sources/src/org/archicontribs/database/DBDatabaseEntry.java +++ b/sources/src/org/archicontribs/database/DBDatabaseEntry.java @@ -19,7 +19,7 @@ import javax.crypto.spec.SecretKeySpec; import org.apache.log4j.Level; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.data.DBDatabase; import org.eclipse.jface.preference.IPersistentPreferenceStore; @@ -274,7 +274,7 @@ public String getJdbcConnectionString() { if ( DBPlugin.isEmpty(this.getUsername()) && DBPlugin.isEmpty(this.getDecryptedPassword()) ) this.jdbcConnectionString += ";integratedSecurity=true"; } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchPaddingException e) { - DBGui.popup(Level.ERROR, "Failed to decrypt password.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to decrypt password.", e); this.jdbcConnectionString = ""; } break; @@ -401,14 +401,14 @@ public static List getAllDatabasesFromPreferenceStore() { store.setValue(preferenceName+"_encrypted_password_"+String.valueOf(line), databaseEntry.getEncryptedPassword()); store.setValue(preferenceName+"_password_"+String.valueOf(line), ""); } catch (InvalidKeyException|IllegalBlockSizeException|BadPaddingException|InvalidAlgorithmParameterException|NoSuchAlgorithmException|NoSuchPaddingException e) { - DBGui.popup(Level.ERROR, "Failed to encrypt password for database entry \""+databaseEntry.getName()+"\".\n\nYour password will be left unencrypted in your preference store.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to encrypt password for database entry \""+databaseEntry.getName()+"\".\n\nYour password will be left unencrypted in your preference store.", e); } } } databaseEntries.add(databaseEntry); } catch (Exception e) { - DBGui.popup(Level.ERROR, "Failed to get database entry \""+databaseEntry.getName()+"\" from preference store.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to get database entry \""+databaseEntry.getName()+"\" from preference store.", e); } } return databaseEntries; @@ -514,7 +514,7 @@ public static void persistDatabaseEntryListIntoPreferenceStore(List DBLogger(Class clazz) { configure(); } catch (Exception e) { initialised = false; - DBGui.popup(Level.ERROR, "Failed to configure logger", e); + DBGuiUtils.popup(Level.ERROR, "Failed to configure logger", e); } } this.logger = Logger.getLogger(clazz); diff --git a/sources/src/org/archicontribs/database/DBPlugin.java b/sources/src/org/archicontribs/database/DBPlugin.java index 2ac53127..e3e43a9b 100644 --- a/sources/src/org/archicontribs/database/DBPlugin.java +++ b/sources/src/org/archicontribs/database/DBPlugin.java @@ -13,7 +13,7 @@ import java.util.UUID; import org.apache.log4j.Level; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.preference.IPersistentPreferenceStore; @@ -22,6 +22,7 @@ import org.eclipse.ui.preferences.ScopedPreferenceStore; import com.archimatetool.model.IIdentifier; +import com.archimatetool.model.ModelVersion; import lombok.Getter; @@ -32,14 +33,27 @@ * The DBPlugin class implements static methods and properties used everywhere else in the database plugin. * * @author Herve Jouin - * - * v4.9.0 22/09/2021 Change plugin version numbering to match Archi version - * Adapt plugin to Archi 4.9, especially specialization * - * v4.8.1 22/09/2021 fix coherence checking - * change plugin numbering to follow Archi's and indicate more clearly that this version is compatible with Archi 4.8 and not Archi 4.9 + * v4.8.1 22/09/2021 fix coherence checking + * change plugin numbering to follow Archi's and indicate more clearly that this version is compatible with Archi 4.8 and not Archi 4.9 * - * v4.8.2 22/09/2021 fix exception raised when model purpose is null rather than an empty string + * v4.8.2 22/09/2021 fix exception raised when model purpose is null rather than an empty string + * + * ----------------------------------------------------------------------------------------- + * + * v4.9.0a 22/09/2021 Change plugin version numbering to match Archi version + * Adapt plugin to Archi 4.9, especially specialization + * + * v4.9.0b 26/10/2021 Fix database model update + * fix SQL Server exception caused by missing column in GROUP BY clause + * Fix folder when import individual component + * Fix import and export windows default location + * Fix import relationships in right folder + * Improve specializations management during export to database + * Add Options tab in preference page to reduce window size + * Add model metadata in compare to database process + * + * ----------------------------------------------------------------------------------------- * * TO-DO list: * ---------- @@ -161,14 +175,14 @@ public DBPlugin() { "log4j.appender.file.layout = org.apache.log4j.PatternLayout\n"+ "log4j.appender.file.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %4L:%-40.40C{1} %m%n"); logger = new DBLogger(DBPlugin.class); - logger.info("Initialising "+pluginName+" plugin ..."); + logger.info("Initialising "+pluginTitle+" ..."); logger.info("==============================================="); // we force the class initialization by the SWT thread Display.getDefault().syncExec(new Runnable() { @Override public void run() { - DBGui.closePopup(); + DBGuiUtils.closePopupMessage(); } }); @@ -177,7 +191,7 @@ public void run() { if ( maxMemory < 950 ) { if ( getPreferenceStore().getBoolean("checkMaxMemory") ) - DBGui.popup(Level.WARN, "Archi is configured with "+maxMemory+" MB max memory.\n\n" + DBGuiUtils.popup(Level.WARN, "Archi is configured with "+maxMemory+" MB max memory.\n\n" + "If you plan to use the database plugin with huge models, we recommand to configure Archi\n" + "with 1 GB of memory (you may add or update the \"-Xmx\" parameter in the Archi.ini file).\n\n" + "You may deactivate the memory check in the database plugin preference page."); @@ -214,9 +228,9 @@ public void run() { DBDatabaseEntry.getAllDatabasesFromPreferenceStore(); preferenceStore.save(); } catch (IOException e) { - DBGui.popup(Level.ERROR, "Failed to save your preferences.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to save your preferences.", e); } - DBGui.popup(Level.INFO, welcomeMessage); + DBGuiUtils.popup(Level.INFO, welcomeMessage); } // we check if the plugin has been upgraded using the automatic procedure @@ -228,6 +242,7 @@ public void run() { if ( logger.isDebugEnabled() ) { logger.debug("Plugin's package = "+pluginsPackage); logger.debug("Plugin's version = "+pluginVersion.toString()); + logger.debug("Archi's version = "+ModelVersion.VERSION); logger.debug("Plugin's folder = "+pluginsFolder); logger.debug("Plugin's filename = "+pluginsFilename); } @@ -239,7 +254,7 @@ public void run() { checkForUpdate(false); } } catch ( IOException e ) { - DBGui.popup(Level.ERROR, "Failed to get database plugin's folder.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to get database plugin's folder.", e); } } diff --git a/sources/src/org/archicontribs/database/GUI/DBGui.java b/sources/src/org/archicontribs/database/GUI/DBGui.java index 50da7d03..9d28c8ce 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGui.java +++ b/sources/src/org/archicontribs/database/GUI/DBGui.java @@ -6,8 +6,6 @@ package org.archicontribs.database.GUI; -import java.awt.HeadlessException; -import java.awt.Toolkit; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; @@ -19,11 +17,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Stack; - import org.apache.log4j.Level; -import org.apache.log4j.Priority; import org.archicontribs.database.DBDatabaseEntry; import org.archicontribs.database.DBLogger; import org.archicontribs.database.DBPlugin; @@ -34,7 +28,6 @@ import org.archicontribs.database.data.DBProperty; import org.archicontribs.database.model.DBMetadata; import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; @@ -43,7 +36,6 @@ import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.Image; @@ -54,8 +46,6 @@ import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; @@ -64,6 +54,7 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Monitor; import org.eclipse.swt.widgets.ProgressBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; @@ -114,164 +105,134 @@ * @author Herve Jouin */ public class DBGui { - protected static final DBLogger logger = new DBLogger(DBGui.class); - - @Getter @Setter private boolean closedByUser = false; - - protected List databaseEntries; - protected List comboDatabaseEntries; - protected DBDatabaseEntry selectedDatabase; - DBDatabaseImportConnection connection; - - protected static final Display display = Display.getCurrent() == null ? Display.getDefault() : Display.getCurrent(); - protected Shell dialog; - protected Shell parentDialog; - - protected boolean includeNeo4j = true; - - String HELP_HREF = null; - boolean mouseOverHelpButton = false; - - protected enum ACTION {One, Two, Three, Four} - protected enum STATUS {Empty, Selected, Running, Bypassed, Ok, Warn, Error} - - public static final Color LIGHT_GREEN_COLOR = new Color(display, 204, 255, 229); - public static final Color LIGHT_RED_COLOR = new Color(display, 255, 230, 230); - public static final Color RED_COLOR = new Color(display, 240, 0, 0); - public static final Color GREEN_COLOR = new Color(display, 0, 180, 0); - public static final Color WHITE_COLOR = new Color(display, 255, 255, 255); - public static final Color GREY_COLOR = new Color(display, 100, 100, 100); - public static final Color BLACK_COLOR = new Color(display, 0, 0, 0); - public static final Color YELLOW_COLOR = new Color(display, 255, 255, 0); - - public static final Color COMPO_LEFT_COLOR = new Color(display, 240, 248, 255); // light blue - public static final Color COMPO_BACKGROUND_COLOR = new Color(display, 250, 250, 250); // light grey - public static final Color GROUP_BACKGROUND_COLOR = new Color(display, 235, 235, 235); // light grey (a bit darker than compo background) - public static final Color TABLE_BACKGROUND_COLOR = new Color(display, 225, 225, 225); // light grey (a bit darker than group background) - public static final Color HIGHLIGHTED_COLOR = display.getSystemColor(SWT.COLOR_GRAY); - - public static final Color STRATEGY_COLOR = new Color(display, 255, 222, 170); - public static final Color BUSINESS_COLOR = new Color(display, 255, 255, 181); - public static final Color APPLICATION_COLOR = new Color(display, 181, 255, 255); - public static final Color TECHNOLOGY_COLOR = new Color(display, 201, 231, 183); - public static final Color PHYSICAL_COLOR = new Color(display, 201, 231, 183); - public static final Color IMPLEMENTATION_COLOR = new Color(display, 255, 224, 224); - public static final Color MOTIVATION_COLOR = new Color(display, 204, 204, 255); - - public static final Color PASSIVE_COLOR = new Color(display, 250, 250, 250); - - public static final Cursor CURSOR_WAIT = new Cursor(null, SWT.CURSOR_WAIT); - public static final Cursor CURSOR_ARROW = new Cursor(null, SWT.CURSOR_ARROW); - - public static final FontData SYSTEM_FONT = display.getSystemFont().getFontData()[0]; - public static final Font GROUP_TITLE_FONT = new Font(display, SYSTEM_FONT.getName(), SYSTEM_FONT.getHeight()+2, SWT.BOLD | SWT.ITALIC); - public static final Font TITLE_FONT = new Font(display, SYSTEM_FONT.getName(), SYSTEM_FONT.getHeight()+2, SWT.BOLD); - public static final Font BOLD_FONT = new Font(display, SYSTEM_FONT.getName(), SYSTEM_FONT.getHeight(), SWT.BOLD); - - public static final Image LOGO_IMAGE = new Image(display, DBGui.class.getResourceAsStream("/img/logo.png")); - public static final Image EXPORT_TO_DATABASE_IMAGE = new Image(display, DBGui.class.getResourceAsStream("/img/22x22/export.png")); - public static final Image IMPORT_FROM_DATABASE_IMAGE = new Image(display, DBGui.class.getResourceAsStream("/img/22x22/import.png")); - - public static final Image BYPASSED_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/bypassed.png")); - public static final Image CLOCK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/clock.png")); - public static final Image ERROR_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/error.png")); - public static final Image WARNING_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/warning.png")); - public static final Image OK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/ok.png")); - public static final Image RIGHT_ARROW_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/right_arrow.png")); - - public static final Image LOCK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/lock.png")); - public static final Image UNLOCK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/unlock.png")); - - public static final Image HELP_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/28x28/help.png")); - - private Composite compoLeft; - protected Composite compoRight; - protected Composite compoRightTop; - protected Composite compoRightBottom; - private Composite compoBottom; - - private Label imgFirstAction; - private Label imgSecondAction; - private Label imgThirdAction; - private Label imgFourthAction; - - private Label lblFirstAction; - private Label lblSecondAction; - private Label lblThirdAction; - private Label lblFourthAction; - - private Label lblOption; - Button radioOption1; - Button radioOption2; - Button radioOption3; - - @Getter protected Combo comboDatabases; - protected Button btnSetPreferences; - protected Button btnClose; - protected Button btnDoAction; - protected Label btnHelp; - - private Group grpDatabase; - - protected Group grpProgressBar = null; - protected Label lblProgressBar; - private ProgressBar progressBar; - - protected Group grpMessage = null; - private CLabel lblMessage; - - /** Default height of a Label widget */ - @Getter private int defaultLabelHeight; - - /** Default margin between widgets */ - @Getter private int defaultMargin = 10; - - - /** - * Create the dialog with minimal graphical objects: - * left composite: picture of a database with Archimate diagram inside, the plugin version, (my name of course) and 4 icons + texts to list actions - * bottom composite: Close, doAction button at the right and help buton on the left - * right composite: database list in a combo and a button to set preferences - */ - protected DBGui(String title) { - if ( logger.isDebugEnabled() ) logger.debug("Creating Form GUI."); - - setArrowCursor(); - - this.parentDialog = display.getActiveShell(); - this.dialog = new Shell(display, SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL | SWT.RESIZE); - this.dialog.setText(DBPlugin.pluginTitle + " - " + title); - this.dialog.setMinimumSize(800, 700); - this.dialog.setSize(1024, 700); - - int scaleFactor = 1; - try { - if ( (Toolkit.getDefaultToolkit().getScreenResolution() != 0) && (this.dialog.getDisplay().getDPI() != null) && (this.dialog.getDisplay().getDPI().x != 0) ) - scaleFactor = Toolkit.getDefaultToolkit().getScreenResolution() / this.dialog.getDisplay().getDPI().x; - } catch ( @SuppressWarnings("unused") HeadlessException ign) { - // nothing to do - } - if ( scaleFactor == 0 ) - scaleFactor = 1; // just in case - - // Use the active shell, if available, to determine the new shell placing - int locationX = 0; - int locationY = 0; - Rectangle shellSize = this.dialog.getBounds(); - if (this.parentDialog!=null) { - Rectangle parentSize = this.parentDialog.getBounds(); - locationX = (parentSize.width - shellSize.width)/2+parentSize.x; - locationY = (parentSize.height - shellSize.height)/2+parentSize.y; - } else { - locationX = ((Toolkit.getDefaultToolkit().getScreenSize().width / scaleFactor) - this.dialog.getSize().x) / 2; - //locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - this.dialog.getSize().x) / 2; - locationY = ((Toolkit.getDefaultToolkit().getScreenSize().height / scaleFactor) - this.dialog.getSize().y) / 2; - //locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - this.dialog.getSize().y) / 2; - } - this.dialog.setLocation(new Point(locationX, locationY)); - - this.dialog.setLayout(new FormLayout()); - + protected static final DBLogger logger = new DBLogger(DBGui.class); + + @Getter @Setter private boolean closedByUser = false; + + protected List databaseEntries; + protected List comboDatabaseEntries; + protected DBDatabaseEntry selectedDatabase; + DBDatabaseImportConnection connection; + + protected static final Display display = Display.getCurrent() == null ? Display.getDefault() : Display.getCurrent(); + protected Shell dialog; + protected Shell parentDialog; + + protected boolean includeNeo4j = true; + + String HELP_HREF = null; + boolean mouseOverHelpButton = false; + + protected enum ACTION {One, Two, Three, Four} + protected enum STATUS {Empty, Selected, Running, Bypassed, Ok, Warn, Error} + + public static final Color LIGHT_GREEN_COLOR = new Color(display, 204, 255, 229); + public static final Color LIGHT_RED_COLOR = new Color(display, 255, 230, 230); + public static final Color RED_COLOR = new Color(display, 240, 0, 0); + public static final Color GREEN_COLOR = new Color(display, 0, 180, 0); + public static final Color WHITE_COLOR = new Color(display, 255, 255, 255); + public static final Color GREY_COLOR = new Color(display, 100, 100, 100); + public static final Color BLACK_COLOR = new Color(display, 0, 0, 0); + public static final Color YELLOW_COLOR = new Color(display, 255, 255, 0); + + public static final Color COMPO_LEFT_COLOR = new Color(display, 240, 248, 255); // light blue + public static final Color COMPO_BACKGROUND_COLOR = new Color(display, 250, 250, 250); // light grey + public static final Color GROUP_BACKGROUND_COLOR = new Color(display, 235, 235, 235); // light grey (a bit darker than compo background) + public static final Color TABLE_BACKGROUND_COLOR = new Color(display, 225, 225, 225); // light grey (a bit darker than group background) + public static final Color HIGHLIGHTED_COLOR = display.getSystemColor(SWT.COLOR_GRAY); + + public static final Color STRATEGY_COLOR = new Color(display, 255, 222, 170); + public static final Color BUSINESS_COLOR = new Color(display, 255, 255, 181); + public static final Color APPLICATION_COLOR = new Color(display, 181, 255, 255); + public static final Color TECHNOLOGY_COLOR = new Color(display, 201, 231, 183); + public static final Color PHYSICAL_COLOR = new Color(display, 201, 231, 183); + public static final Color IMPLEMENTATION_COLOR = new Color(display, 255, 224, 224); + public static final Color MOTIVATION_COLOR = new Color(display, 204, 204, 255); + + public static final Color PASSIVE_COLOR = new Color(display, 250, 250, 250); + + public static final FontData SYSTEM_FONT = display.getSystemFont().getFontData()[0]; + public static final Font GROUP_TITLE_FONT = new Font(display, SYSTEM_FONT.getName(), SYSTEM_FONT.getHeight()+2, SWT.BOLD | SWT.ITALIC); + public static final Font TITLE_FONT = new Font(display, SYSTEM_FONT.getName(), SYSTEM_FONT.getHeight()+2, SWT.BOLD); + public static final Font BOLD_FONT = new Font(display, SYSTEM_FONT.getName(), SYSTEM_FONT.getHeight(), SWT.BOLD); + + public static final Image LOGO_IMAGE = new Image(display, DBGui.class.getResourceAsStream("/img/logo.png")); + public static final Image EXPORT_TO_DATABASE_IMAGE = new Image(display, DBGui.class.getResourceAsStream("/img/22x22/export.png")); + public static final Image IMPORT_FROM_DATABASE_IMAGE = new Image(display, DBGui.class.getResourceAsStream("/img/22x22/import.png")); + + public static final Image BYPASSED_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/bypassed.png")); + public static final Image CLOCK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/clock.png")); + public static final Image ERROR_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/error.png")); + public static final Image WARNING_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/warning.png")); + public static final Image OK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/ok.png")); + public static final Image RIGHT_ARROW_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/right_arrow.png")); + + public static final Image LOCK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/lock.png")); + public static final Image UNLOCK_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/10x10/unlock.png")); + + public static final Image HELP_ICON = new Image(display, DBGui.class.getResourceAsStream("/img/28x28/help.png")); + + private Composite compoLeft; + protected Composite compoRight; + protected Composite compoRightTop; + protected Composite compoRightBottom; + private Composite compoBottom; + + private Label imgFirstAction; + private Label imgSecondAction; + private Label imgThirdAction; + private Label imgFourthAction; + + private Label lblFirstAction; + private Label lblSecondAction; + private Label lblThirdAction; + private Label lblFourthAction; + + private Label lblOption; + Button radioOption1; + Button radioOption2; + Button radioOption3; + + @Getter protected Combo comboDatabases; + protected Button btnSetPreferences; + protected Button btnClose; + protected Button btnDoAction; + protected Label btnHelp; + + private Group grpDatabase; + + protected Group grpProgressBar = null; + protected Label lblProgressBar; + private ProgressBar progressBar; + + protected Group grpMessage = null; + private CLabel lblMessage; + + /** Default height of a Label widget */ + @Getter private int defaultLabelHeight; + + /** Default margin between widgets */ + @Getter protected int defaultMargin = 5; + + + /** + * Create the dialog with minimal graphical objects: + * left composite: picture of a database with Archimate diagram inside, the plugin version, (my name of course) and 4 icons + texts to list actions + * bottom composite: Close, doAction button at the right and help buton on the left + * right composite: database list in a combo and a button to set preferences + * @param title Title of the window + */ + protected DBGui(String title) { + if ( logger.isDebugEnabled() ) logger.debug("Creating Form GUI."); + + DBGuiUtils.setWaitCursor(); + + this.parentDialog = display.getActiveShell(); + Rectangle parentBounds = this.parentDialog.getBounds(); + this.dialog = new Shell(display, SWT.BORDER | SWT.TITLE | SWT.APPLICATION_MODAL | SWT.RESIZE); + this.dialog.setText(DBPlugin.pluginTitle + " - " + title); + this.dialog.setMinimumSize(1024, 768); + /** * Calculate the default height of a Label widget */ @@ -279,1524 +240,1310 @@ protected DBGui(String title) { label.setText("Test"); this.defaultLabelHeight = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; label.dispose(); + + // in case the monitor is smaller than 1280x850 (which may be the case on some laptops) + Monitor[] monitors = display.getMonitors(); + + for (int i = 0; i < monitors.length; i++) { + Rectangle monitorBounds = monitors[i].getBounds(); + if (monitorBounds.intersects(parentBounds)) + this.dialog.setSize(Math.min(monitorBounds.width, 1400), Math.min(monitorBounds.height, 1024)); + } + + int locationX = parentBounds.x + (parentBounds.width - this.dialog.getSize().x)/2; + int locationY = parentBounds.y + (parentBounds.height - this.dialog.getSize().y)/2; + + this.dialog.setLocation(new Point(locationX, locationY)); + + this.dialog.setLayout(new FormLayout()); + + this.dialog.addListener(SWT.Close, new Listener() + { + @Override + public void handleEvent(Event event) + { + boolean doIt = true; + if ( DBGui.this.btnClose.getText().equals("Cancel") ) { + doIt = DBGuiUtils.question("Are you sure you wish to cancel ?"); + } + + if ( doIt ) { + setClosedByUser(true); + try { + rollbackAndCloseConnection(); + } catch (SQLException e) { + DBGuiUtils.popup(Level.ERROR, "Failed to rollback and close the database connection.", e); + } + close(); + event.doit = true; + } + } + }); + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// compoLeft //////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + this.compoLeft = new Composite(this.dialog, SWT.BORDER); + this.compoLeft.setBackground(COMPO_LEFT_COLOR); + FormData fd = new FormData(); + fd.top = new FormAttachment(0); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(0, 210); + fd.bottom = new FormAttachment(100, -40); + this.compoLeft.setLayoutData(fd); + this.compoLeft.setLayout(new FormLayout()); + + Composite compoTitle = new Composite(this.compoLeft, SWT.BORDER); + compoTitle.setBackground(COMPO_LEFT_COLOR); + compoTitle.setLayout(new FormLayout()); + + Label lblTitle = new Label(compoTitle, SWT.CENTER | SWT.WRAP); + lblTitle.setBackground(COMPO_LEFT_COLOR); + lblTitle.setText("Archi database plugin"); + lblTitle.setFont(TITLE_FONT); + fd = new FormData(); + fd.top = new FormAttachment(getDefaultMargin()); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + lblTitle.setLayoutData(fd); + + Label lblPluginVersion = new Label(compoTitle, SWT.CENTER); + lblPluginVersion.setBackground(COMPO_LEFT_COLOR); + lblPluginVersion.setText("v" + DBPlugin.pluginVersion.toString()); + fd = new FormData(); + fd.top = new FormAttachment(lblTitle, getDefaultMargin()); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + fd.bottom = new FormAttachment(100, -getDefaultMargin()); + lblPluginVersion.setLayoutData(fd); + + //we calculate the size of the compoTitle widget + lblTitle.pack(); + lblPluginVersion.pack(); + fd = new FormData(140,50); + fd.top = new FormAttachment(0, 40); + fd.left = new FormAttachment(getDefaultMargin()); + fd.right = new FormAttachment(100, -getDefaultMargin()); + fd.height = 2*lblTitle.getSize().y + lblPluginVersion.getSize().y + 3*getDefaultMargin(); + compoTitle.setLayoutData(fd); + + Label imgDatabase = new Label(this.compoLeft, SWT.CENTER); + imgDatabase.setBackground(COMPO_LEFT_COLOR); + imgDatabase.setImage(LOGO_IMAGE); + fd = new FormData(135,115); + fd.top = new FormAttachment(compoTitle, 30); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + imgDatabase.setLayoutData(fd); + + this.imgFirstAction = new Label(this.compoLeft, SWT.CENTER); + this.imgFirstAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(10,10); + fd.top = new FormAttachment(imgDatabase, 50); + fd.left = new FormAttachment(0, 10); + this.imgFirstAction.setLayoutData(fd); + + this.lblFirstAction = new Label(this.compoLeft, SWT.NONE); + this.lblFirstAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.imgFirstAction, 0, SWT.CENTER); + fd.left = new FormAttachment(this.imgFirstAction, 10); + fd.right = new FormAttachment(100, -10); + this.lblFirstAction.setLayoutData(fd); + + this.imgSecondAction = new Label(this.compoLeft, SWT.CENTER); + this.imgSecondAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(10,10); + fd.top = new FormAttachment(this.imgFirstAction, 10); + fd.left = new FormAttachment(0, 10); + this.imgSecondAction.setLayoutData(fd); + + this.lblSecondAction = new Label(this.compoLeft, SWT.NONE); + this.lblSecondAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.imgSecondAction, 0, SWT.CENTER); + fd.left = new FormAttachment(this.imgSecondAction, 10); + fd.right = new FormAttachment(100, -10); + this.lblSecondAction.setLayoutData(fd); + + this.imgThirdAction = new Label(this.compoLeft, SWT.CENTER); + this.imgThirdAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(10,10); + fd.top = new FormAttachment(this.imgSecondAction, 10); + fd.left = new FormAttachment(0, 10); + this.imgThirdAction.setLayoutData(fd); + + this.lblThirdAction = new Label(this.compoLeft, SWT.NONE); + this.lblThirdAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.imgThirdAction, 0, SWT.CENTER); + fd.left = new FormAttachment(this.imgThirdAction, 10); + fd.right = new FormAttachment(100, -10); + this.lblThirdAction.setLayoutData(fd); + + this.imgFourthAction = new Label(this.compoLeft, SWT.CENTER); + this.imgFourthAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(10,10); + fd.top = new FormAttachment(this.imgThirdAction, 10); + fd.left = new FormAttachment(0, 10); + this.imgFourthAction.setLayoutData(fd); + + this.lblFourthAction = new Label(this.compoLeft, SWT.NONE); + this.lblFourthAction.setBackground(COMPO_LEFT_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.imgFourthAction, 0, SWT.CENTER); + fd.left = new FormAttachment(this.imgFourthAction, 10); + fd.right = new FormAttachment(100, -10); + this.lblFourthAction.setLayoutData(fd); + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// compoRight /////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + this.compoRight = new Composite(this.dialog, SWT.BORDER); + this.compoRight.setBackground(COMPO_BACKGROUND_COLOR); + FormData fd_compoRight = new FormData(); + fd_compoRight.top = new FormAttachment(0); + fd_compoRight.bottom = new FormAttachment(100, -40); + fd_compoRight.left = new FormAttachment(this.compoLeft); + fd_compoRight.right = new FormAttachment(100); + this.compoRight.setLayoutData(fd_compoRight); + this.compoRight.setLayout(new FormLayout()); + + this.compoRightTop = new Composite(this.compoRight, SWT.NONE); + this.compoRightTop.setBackground(COMPO_BACKGROUND_COLOR); + FormData fd_compoRightUp = new FormData(); + fd_compoRightUp.top = new FormAttachment(0, 10); + fd_compoRightUp.bottom = new FormAttachment(0, 100); + fd_compoRightUp.left = new FormAttachment(0, 10); + fd_compoRightUp.right = new FormAttachment(100, -10); + this.compoRightTop.setLayoutData(fd_compoRightUp); + this.compoRightTop.setLayout(new FormLayout()); + + this.compoRightBottom = new Composite(this.compoRight, SWT.NONE); + this.compoRightBottom.setBackground(COMPO_BACKGROUND_COLOR); + FormData fd_compoRightBottom = new FormData(); + fd_compoRightBottom.top = new FormAttachment(this.compoRightTop, 10); + fd_compoRightBottom.bottom = new FormAttachment(100, -10); + fd_compoRightBottom.left = new FormAttachment(0, 10); + fd_compoRightBottom.right = new FormAttachment(100, -10); + this.compoRightBottom.setLayoutData(fd_compoRightBottom); + this.compoRightBottom.setLayout(new FormLayout()); + + this.grpDatabase = new Group(this.compoRightTop, SWT.SHADOW_ETCHED_IN); + this.grpDatabase.setVisible(true); + this.grpDatabase.setData("visible", true); + this.grpDatabase.setBackground(GROUP_BACKGROUND_COLOR); + this.grpDatabase.setFont(GROUP_TITLE_FONT); + this.grpDatabase.setText("Database: "); + fd = new FormData(); + fd.top = new FormAttachment(0); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + fd.bottom = new FormAttachment(100); + this.grpDatabase.setLayoutData(fd); + this.grpDatabase.setLayout(new FormLayout()); + + Label lblRegisteredDatabases = new Label(this.grpDatabase, SWT.NONE); + lblRegisteredDatabases.setBackground(GROUP_BACKGROUND_COLOR); + lblRegisteredDatabases.setText("Registered databases:"); + fd = new FormData(); + fd.top = new FormAttachment(25); + fd.left = new FormAttachment(0, 10); + lblRegisteredDatabases.setLayoutData(fd); + + this.btnSetPreferences = new Button(this.grpDatabase, SWT.NONE); + this.btnSetPreferences.setText("Set preferences ..."); + this.btnSetPreferences.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { try { setPreferences(); } catch (Exception e) { DBGuiUtils.popup(Level.ERROR, "Failed to set preferences", e); } } + @Override + public void widgetDefaultSelected(SelectionEvent event) { widgetSelected(event); } + }); + fd = new FormData(); + fd.top = new FormAttachment(lblRegisteredDatabases, 0, SWT.CENTER); + fd.right = new FormAttachment(100, -10); + this.btnSetPreferences.setLayoutData(fd); + + this.comboDatabases = new Combo(this.grpDatabase, SWT.NONE | SWT.READ_ONLY); + this.comboDatabases.setBackground(GROUP_BACKGROUND_COLOR); + this.comboDatabases.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { databaseSelected(); } + @Override + public void widgetDefaultSelected(SelectionEvent event) { widgetSelected(event); } + }); + fd = new FormData(); + fd.top = new FormAttachment(lblRegisteredDatabases, 0, SWT.CENTER); + fd.left = new FormAttachment(lblRegisteredDatabases, 10); + fd.right = new FormAttachment(this.btnSetPreferences, -40); + this.comboDatabases.setLayoutData(fd); + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////// compoBottom ////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + this.compoBottom = new Composite(this.dialog, SWT.NONE); + this.compoBottom.setBackground(COMPO_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(100, -40); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + fd.bottom = new FormAttachment(100); + this.compoBottom.setLayoutData(fd); + this.compoBottom.setLayout(new FormLayout()); + + this.btnHelp = new Label(this.compoBottom, SWT.NONE); + this.btnHelp.setVisible(false); + this.btnHelp.addListener(SWT.MouseEnter, new Listener() { @Override public void handleEvent(Event event) { DBGui.this.mouseOverHelpButton = true; DBGui.this.btnHelp.redraw(); } }); + this.btnHelp.addListener(SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { DBGui.this.mouseOverHelpButton = false; DBGui.this.btnHelp.redraw(); } }); + this.btnHelp.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent event) + { + if ( DBGui.this.mouseOverHelpButton ) event.gc.drawRoundRectangle(0, 0, 29, 29, 10, 10); + event.gc.drawImage(HELP_ICON, 2, 2); + } + }); + this.btnHelp.addListener(SWT.MouseUp, new Listener() { @Override public void handleEvent(Event event) { if ( DBGui.this.HELP_HREF != null ) { if ( logger.isDebugEnabled() ) logger.debug("Showing help: /"+DBPlugin.PLUGIN_ID+"/help/html/"+DBGui.this.HELP_HREF); PlatformUI.getWorkbench().getHelpSystem().displayHelpResource("/"+DBPlugin.PLUGIN_ID+"/help/html/"+DBGui.this.HELP_HREF); } } }); + fd = new FormData(30,30); + fd.top = new FormAttachment(0, 5); + fd.left = new FormAttachment(0, 5); + this.btnHelp.setLayoutData(fd); + + + this.btnClose = new Button(this.compoBottom, SWT.NONE); + this.btnClose.setText("Close"); + this.btnClose.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent event) { + boolean doIt = true; + if ( DBGui.this.btnClose.getText().equals("Cancel") ) { + doIt = DBGuiUtils.question("Are you sure you wish to cancel ?"); + } + + if ( doIt ) { + setClosedByUser(true); + try { + rollbackAndCloseConnection(); + } catch (SQLException e) { + DBGuiUtils.popup(Level.ERROR, "Failed to rollback and close the database connection.", e); + } + close(); + event.doit = true; + } + } + @Override + public void widgetDefaultSelected(SelectionEvent event) { widgetSelected(event); } + }); + fd = new FormData(100,25); + fd.top = new FormAttachment(0, 8); + fd.right = new FormAttachment(100, -10); + this.btnClose.setLayoutData(fd); + + this.btnDoAction = new Button(this.compoBottom, SWT.NONE); + this.btnDoAction.setEnabled(false); + this.btnDoAction.setVisible(false); + fd = new FormData(100,25); + fd.top = new FormAttachment(0, 8); + fd.right = new FormAttachment(this.btnClose, -10); + this.btnDoAction.setLayoutData(fd); + + this.radioOption3 = new Button(this.compoBottom, SWT.RADIO); + this.radioOption3.setBackground(COMPO_BACKGROUND_COLOR); + this.radioOption3.setVisible(false); + fd = new FormData(); + fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); + fd.right = new FormAttachment(this.btnDoAction, -20); + this.radioOption3.setLayoutData(fd); + + this.radioOption2 = new Button(this.compoBottom, SWT.RADIO); + this.radioOption2.setBackground(COMPO_BACKGROUND_COLOR); + this.radioOption2.setVisible(false); + fd = new FormData(); + fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); + fd.right = new FormAttachment(this.radioOption3, -10); + this.radioOption2.setLayoutData(fd); + + this.radioOption1 = new Button(this.compoBottom, SWT.RADIO); + this.radioOption1.setBackground(COMPO_BACKGROUND_COLOR); + this.radioOption1.setVisible(false); + fd = new FormData(); + fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); + fd.right = new FormAttachment(this.radioOption2, -10); + this.radioOption1.setLayoutData(fd); + + this.lblOption = new Label(this.compoBottom, SWT.NONE); + this.lblOption.setBackground(COMPO_BACKGROUND_COLOR); + this.lblOption.setVisible(false); + fd = new FormData(); + fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); + fd.right = new FormAttachment(this.radioOption1, -10); + this.lblOption.setLayoutData(fd); + } + + public void run() { + this.dialog.open(); + this.dialog.layout(); + refreshDisplay(); + } + + /** + * Gets the list of configured databases, fill-in the comboDatabases and select the database provided + * @param mustIncludeNeo4j if true, include the Neo4J databases in the list, if false, do not include them in the list + * @param defaultDatabaseId Indicated the ID of the default database (the first database will be selected, if the database is not found or if null) + * @param defaultDatabaseName Indicated the name of the default database (the first database will be selected, if the database is not found or if null) - if both ID and name are provided, the ID has got higher priority + * @throws Exception + */ + protected void getDatabases(boolean mustIncludeNeo4j, String defaultDatabaseId, String defaultDatabaseName) throws Exception { + refreshDisplay(); + + this.databaseEntries = DBDatabaseEntry.getAllDatabasesFromPreferenceStore(); + this.comboDatabaseEntries = new ArrayList(); + if ( (this.databaseEntries == null) || (this.databaseEntries.size() == 0) ) { + DBGuiUtils.popup(Level.ERROR, "You haven't configure any database yet.\n\nPlease setup at least one database in Archi preferences."); + } else { + int databaseToSelect = -1; + int line = 0; + for (DBDatabaseEntry databaseEntry: this.databaseEntries) { + if ( mustIncludeNeo4j || !databaseEntry.getDriver().equals(DBDatabase.NEO4J.getDriverName()) ) { + this.comboDatabases.add(databaseEntry.getName()); + this.comboDatabaseEntries.add(databaseEntry); + if ( defaultDatabaseId != null && databaseEntry.getId().equals(defaultDatabaseId) ) + databaseToSelect = line; + if ( defaultDatabaseName != null && databaseToSelect != 0 && databaseEntry.getName().equals(defaultDatabaseName) ) + databaseToSelect = line; + ++line; + } + } + if ( line == 0 ) + DBGuiUtils.popup(Level.ERROR, "You haven't configure any SQL database yet.\n\nPlease setup at least one SQL database in Archi preferences."); + else { + // if no default database is provided, then we select the first database in the combo + if ( defaultDatabaseId == null && defaultDatabaseName == null ) + databaseToSelect = 0; + if ( databaseToSelect != -1 ) { + this.comboDatabases.select(databaseToSelect); + this.comboDatabases.notifyListeners(SWT.Selection, new Event()); // calls the databaseSelected() method + } + } + } + } + + /** + * Gets the list of configured databases, fill-in the comboDatabases and select the first-one + * @param mustIncludeNeo4j if true, include the Neo4J databases in the list, if false, do not include them in the list + * @throws Exception + */ + protected void getDatabases(boolean mustIncludeNeo4j) throws Exception { + getDatabases(mustIncludeNeo4j, null, null); + } + + /** + * Called when the user clicks on the "set preferences" button
+ * This method opens up the database plugin preference page that the user can configure database details. + * @throws Exception + */ + protected void setPreferences() throws Exception { + if ( logger.isDebugEnabled() ) logger.debug("Openning preference page ..."); + PreferenceDialog prefDialog = PreferencesUtil.createPreferenceDialogOn(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "org.archicontribs.database.DBPreferencePage", null, null); + prefDialog.setBlockOnOpen(true); + if ( prefDialog.open() == 0 ) { + if ( logger.isDebugEnabled() ) logger.debug("Resetting settings from preferences ..."); + + this.comboDatabases.removeAll(); + + this.databaseEntries = DBDatabaseEntry.getAllDatabasesFromPreferenceStore(); + if ( (this.databaseEntries == null) || (this.databaseEntries.size() == 0) ) { + this.comboDatabases.select(0); + DBGuiUtils.popup(Level.ERROR, "You haven't configure any database yet.\n\nPlease setup at least one database in Archi preferences."); + } else { + int line = 0; + for (DBDatabaseEntry databaseEntry: this.databaseEntries) { + if ( this.includeNeo4j || !databaseEntry.getDriver().equals(DBDatabase.NEO4J.getDriverName()) ) { + this.comboDatabases.add(databaseEntry.getName()); + this.comboDatabaseEntries.add(databaseEntry); + ++line; + } + } + if ( line == 0 ) + DBGuiUtils.popup(Level.ERROR, "You haven't configure any SQL database yet.\n\nPlease setup at least one SQL database in Archi preferences."); + else { + this.comboDatabases.select(0); + this.comboDatabases.notifyListeners(SWT.Selection, new Event()); + } + } + } else { + if ( logger.isDebugEnabled() ) logger.debug("Preferences cancelled ..."); + if ( this.comboDatabases.getItemCount() == 0 ) + DBGuiUtils.popup(Level.ERROR, "You won't be able to export until a database is configured in the preferences."); + } + this.comboDatabases.setFocus(); + } + + /** + * Listener called when a database is selected in the comboDatabases
+ * This method retrieve the database name from the comboDatabases and reads the preferences to get the connection details. A connection is then established to the database. + */ + protected void databaseSelected() { + setMessage("Connecting to the database ..."); + refreshDisplay(); + + databaseSelectedCleanup(); + + this.btnDoAction.setEnabled(false); + + // we get the databaseEntry corresponding to the selected combo entry + this.selectedDatabase = this.comboDatabaseEntries.get(this.comboDatabases.getSelectionIndex()); + if ( logger.isDebugEnabled() ) logger.debug("Selected database = " + this.selectedDatabase.getName()+" ("+this.selectedDatabase.getDriver()+", "+this.selectedDatabase.getServer()+", "+this.selectedDatabase.getPort()+", "+this.selectedDatabase.getDatabase()+", "+this.selectedDatabase.getUsername()); + + // then we connect to the database. + try { + this.connection = new DBDatabaseImportConnection(this.selectedDatabase); + //if the database connection failed, then an exception is raised, meaning that we get here only if the database connection succeeded + if ( logger.isDebugEnabled() ) logger.debug("We are connected to the database."); + } catch (Exception err) { + closeMessage(); + notConnectedToDatabase(); + DBGuiUtils.popup(Level.ERROR, "Cannot connect to the database.", err); + return; + } + + // then, we check if the database has got the right pre-requisites + try { + this.connection.checkDatabase(null); + } catch (Exception err) { + closeMessage(); + DBGuiUtils.popup(Level.ERROR, "Cannot use this database.", err); + notConnectedToDatabase(); + return; + } finally { + closeMessage(); + } + + connectedToDatabase(true); + } + + /** + * This method is called by the databaseSelected method. It allows to do some actions when a new database is selected. + */ + protected void databaseSelectedCleanup() { + //to be overridden + } + + /** + * This method is called by the databaseSelected method. It allows to do some actions when the connection to a new database is successful. + * @param forceCheckDatabase true when the database should be checked. + */ + protected void connectedToDatabase(boolean forceCheckDatabase) { + // to be overridden + enableOption(); + this.btnDoAction.setEnabled(true); + } + + /** + * This method is called by the databaseSelected method. It allows to do some actions when the connection to a new database is failed. + */ + protected void notConnectedToDatabase() { + // to be overridden + disableOption(); + this.btnDoAction.setEnabled(false); + } + + /** + * Sets the reference of the online help + */ + protected void setHelpHref(String href) { + this.HELP_HREF = href; + this.btnHelp.setVisible(this.HELP_HREF != null); + } + + private ACTION activeAction = null; + /** + * Activate an action (on the left handside panel) + * @param action Reference of the action + * @param status status of the action + */ + protected void setActiveAction(ACTION action, STATUS status) { + Image icon; + switch ( status ) { + case Selected: icon = RIGHT_ARROW_ICON; break; + case Running: icon = CLOCK_ICON; break; + case Bypassed: icon = BYPASSED_ICON; break; + case Ok: icon = OK_ICON; break; + case Warn: icon = WARNING_ICON; break; + case Error: icon = ERROR_ICON; break; + case Empty: icon = null; break; + default: icon = null; + } + switch ( action ) { + case One: this.activeAction = ACTION.One; this.imgFirstAction.setImage(icon); break; + case Two: this.activeAction = ACTION.Two; this.imgSecondAction.setImage(icon); break; + case Three: this.activeAction = ACTION.Three; this.imgThirdAction.setImage(icon); break; + case Four: this.activeAction = ACTION.Four; this.imgFourthAction.setImage(icon); break; + default: + } + } + + /** + * Changes the status of the current action (on the left handside panel) + * @param status status of the action + */ + protected void setActiveAction(STATUS status) { + if ( this.activeAction == null ) + this.activeAction = ACTION.One; + setActiveAction(this.activeAction, status); + } + + /** + * Changes the active action (on the left handside panel) + * @param action Reference of the action + */ + protected void setActiveAction(ACTION action) { + setActiveAction(action, STATUS.Selected); + } + + /** + * Creates an action (on the left handside panel) + * @param action Reference of the action + * @param label Label of the action + */ + protected void createAction(ACTION action, String label) { + switch ( action ) { + case One: this.lblFirstAction.setText(label); break; + case Two: this.lblSecondAction.setText(label); break; + case Three: this.lblThirdAction.setText(label); break; + case Four: this.lblFourthAction.setText(label); break; + default: + } + } + + protected void setOption(int selectedOption) { + int realSelectedOption = selectedOption % 3; + this.radioOption1.setSelection(realSelectedOption == 0); + this.radioOption2.setSelection(realSelectedOption == 1); + this.radioOption3.setSelection(realSelectedOption == 2); + } + + protected void setOption(String label, String option1, boolean option1Selected, String toolTip1, String option2, boolean option2Selected, String toolTip2, String option3, boolean option3Selected, String toolTip3) { + if ( label != null ) this.lblOption.setText(label); + + if ( option1 == null ) { + this.radioOption1.setText(""); + this.radioOption1.setToolTipText(""); + this.radioOption1.setVisible(false); + } else { + this.radioOption1.setText(option1); + this.radioOption1.setSelection(option1Selected); + this.radioOption1.setVisible(true); + if ( toolTip1 != null ) this.radioOption1.setToolTipText(toolTip1); + } + + if ( option2 == null ) { + this.radioOption2.setText(""); + this.radioOption2.setToolTipText(""); + this.radioOption2.setVisible(true); + } else { + this.radioOption2.setText(option2); + this.radioOption2.setSelection(option2Selected); + this.radioOption2.setVisible(true); + if ( toolTip2 != null ) this.radioOption2.setToolTipText(toolTip2); + } + + if ( option3 == null ) { + this.radioOption3.setText(""); + this.radioOption3.setToolTipText(""); + this.radioOption3.setVisible(false); + } else { + this.radioOption3.setText(option3); + this.radioOption3.setSelection(option3Selected); + this.radioOption3.setVisible(true); + if ( toolTip3 != null ) this.radioOption3.setToolTipText(toolTip3); + } + + this.compoBottom.layout(); + + showOption(); + disableOption(); + } + + protected void enableOption() { + this.lblOption.setEnabled(true); + this.radioOption1.setEnabled(true); + this.radioOption2.setEnabled(true); + this.radioOption3.setEnabled(true); + } + + protected void disableOption() { + this.lblOption.setEnabled(false); + this.radioOption1.setEnabled(false); + this.radioOption2.setEnabled(false); + this.radioOption3.setEnabled(false); + } + + protected void hideOption() { + this.lblOption.setVisible(false); + this.radioOption1.setVisible(false); + this.radioOption2.setVisible(false); + this.radioOption3.setVisible(false); + } + + protected void showOption() { + this.lblOption.setVisible(true); + this.radioOption1.setVisible(this.radioOption1.getText().length() != 0); + this.radioOption2.setVisible(this.radioOption2.getText().length() != 0); + this.radioOption3.setVisible(this.radioOption3.getText().length() != 0); + } + + /** + * Returns the value of the selected option:
+ * 1 for the first option
+ * 2 for the second option
+ * 3 for the third option + */ + protected int getOptionValue() { + if ( this.radioOption1.getSelection() ) + return 1; + if ( this.radioOption2.getSelection() ) + return 2; + if ( this.radioOption3.getSelection() ) + return 3; + return 0; + } + + + protected void hideGrpDatabase() { + this.grpDatabase.setVisible(false); + this.grpDatabase.setData("visible", false); + } + + protected void showGrpDatabase() { + this.grpDatabase.setVisible(true); + this.grpDatabase.setData("visible", true); + } + + private SelectionListener actionListener = null; + protected void setBtnAction(String label, SelectionListener listener) { + if ( label == null ) { + this.btnDoAction.setVisible(false); + } else { + this.btnDoAction.setText(label); + this.btnDoAction.setVisible(true); + + if ( this.actionListener != null ) { + this.btnDoAction.removeSelectionListener(this.actionListener); + this.actionListener = null; + } + + if ( listener != null ) { + this.actionListener = listener; + this.btnDoAction.addSelectionListener(this.actionListener); + } + } + } + + /** + * Creates the progress bar that will allow to follow the export process + */ + protected void createProgressBar(String label, int min, int max) { + if ( this.grpProgressBar == null ) { + this.grpProgressBar = new Group(this.compoRightTop, SWT.NONE); + this.grpProgressBar.setBackground(GROUP_BACKGROUND_COLOR); + FormData fd = new FormData(); + fd.top = new FormAttachment(0); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + fd.bottom = new FormAttachment(100); + this.grpProgressBar.setLayoutData(fd); + this.grpProgressBar.setLayout(new FormLayout()); + + + this.lblProgressBar = new Label(this.grpProgressBar, SWT.CENTER); + this.lblProgressBar.setBackground(GROUP_BACKGROUND_COLOR); + this.lblProgressBar.setFont(TITLE_FONT); + fd = new FormData(); + fd.top = new FormAttachment(0, -5); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + this.lblProgressBar.setLayoutData(fd); + + this.progressBar = new ProgressBar(this.grpProgressBar, SWT.NONE); + fd = new FormData(); + fd.top = new FormAttachment(this.lblProgressBar); + fd.left = new FormAttachment(25); + fd.right = new FormAttachment(75); + fd.height = 15; + this.progressBar.setLayoutData(fd); + } + + this.grpProgressBar.setVisible(true); + this.grpProgressBar.setData("visible", true); + + this.grpProgressBar.moveAbove(null); + + this.lblProgressBar.setText(label); + logger.info(label); + + this.progressBar.setMinimum(min); + this.progressBar.setMaximum(max); + + + this.compoRightTop.layout(); + refreshDisplay(); + + resetProgressBar(); + } + + public void hideProgressBar() { + if ( this.progressBar != null ) { + this.grpProgressBar.setVisible(false); + this.grpProgressBar.setData("visible", false); + refreshDisplay(); + } + } + + public void setProgressBarLabel(String label) { + if ( this.lblProgressBar == null ) + createProgressBar(label, 0, 100); + else { + this.lblProgressBar.setText(label); + } + logger.info("Setting progress bar label to \""+label+"\""); + refreshDisplay(); + } + + public String getProgressBarLabel() { + if ( this.lblProgressBar == null ) + return ""; + + return this.lblProgressBar.getText(); + } + + /** + * Sets the min and max values of the progressBar and reset its selection to zero + */ + public void setProgressBarMinAndMax(int min, int max) { + if ( this.lblProgressBar != null ) { + this.progressBar.setMinimum(min); + this.progressBar.setMaximum(max); + } + resetProgressBar(); + } + + /** + * Resets the progressBar to zero in the SWT thread (thread safe method) + */ + public void resetProgressBar() { + if ( this.lblProgressBar != null ) + this.progressBar.setSelection(0); + refreshDisplay(); + } + + /** + * Increases the progressBar selection in the SWT thread (thread safe method) + */ + public void increaseProgressBar() { + if ( this.lblProgressBar != null ) + this.progressBar.setSelection(this.progressBar.getSelection()+1); + refreshDisplay(); + } + + public void setMessage(String message) { + setMessage(message, GROUP_BACKGROUND_COLOR); + } + + protected void setMessage(String message, Color background) { + if ( this.grpMessage == null ) { + this.grpMessage = new Group(this.compoRightTop, SWT.NONE); + this.grpMessage.setBackground(GROUP_BACKGROUND_COLOR); + this.grpMessage.setFont(GROUP_TITLE_FONT); + this.grpMessage.setText("Please wait ... "); + FormData fd = new FormData(); + fd.top = new FormAttachment(0); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + fd.bottom = new FormAttachment(100); + this.grpMessage.setLayoutData(fd); + this.grpMessage.setLayout(new FormLayout()); + + this.lblMessage = new CLabel(this.grpMessage, SWT.CENTER); + this.lblMessage.setAlignment(SWT.CENTER); + this.lblMessage.setBackground(GROUP_BACKGROUND_COLOR); + this.lblMessage.setFont(TITLE_FONT); + fd = new FormData(); + fd.top = new FormAttachment(0); + fd.left = new FormAttachment(0); + fd.right = new FormAttachment(100); + fd.bottom = new FormAttachment(100); + this.lblMessage.setLayoutData(fd); + refreshDisplay(); + } + + this.grpMessage.setVisible(true); + + if (this.grpProgressBar != null ) + this.grpProgressBar.setVisible(false); + + if ( this.grpDatabase != null ) + this.grpDatabase.setVisible(false); + + this.compoRightTop.layout(); + + this.lblMessage.setBackground(background); + + String msg = message.replace("\n\n", "\n"); + if ( background == RED_COLOR ) + logger.error(msg); + else + logger.info(msg); + + this.lblMessage.setText(msg); + + this.grpMessage.moveAbove(null); + + refreshDisplay(); + } + + + public void closeMessage() { + if ( (this.grpMessage != null) && !this.grpMessage.isDisposed() ) { + this.grpMessage.setVisible(false); + + if (this.grpProgressBar != null && (this.grpProgressBar.getData("visible") != null) ) + this.grpProgressBar.setVisible((boolean)this.grpProgressBar.getData("visible")); + + if ( this.grpDatabase != null && (this.grpDatabase.getData("visible") != null) ) + this.grpDatabase.setVisible((boolean)this.grpDatabase.getData("visible")); + + this.compoRightTop.layout(); + refreshDisplay(); + } + } + + /** + * Method used to close graphical objects if needed + */ + public void close() { + this.dialog.dispose(); + this.dialog = null; + + DBGuiUtils.restoreCursors(); + } + + public void commitAndCloseConnection() throws SQLException { + if ( this.connection != null ) { + // in case some transactions have been started, we commit them + this.connection.commit(); + + this.connection.close(); + this.connection = null; + } + } + + public void rollbackAndCloseConnection() throws SQLException { + if ( this.connection != null ) { + // in case some transactions have been started, we roll them back + this.connection.rollback(); + + this.connection.close(); + this.connection = null; + } + } + + public boolean isDisposed() { + return this.dialog==null ? true : this.dialog.isDisposed(); + } + + protected Boolean fillInCompareTable(Tree tree, EObject memoryObject, int memoryObjectversion) { + return fillInCompareTable(tree, null, memoryObject, memoryObjectversion); + } + + @SuppressWarnings("unchecked") + protected Boolean fillInCompareTable(Tree tree, TreeItem treeItem, EObject memoryObject, int memoryObjectversion) { + assert ( memoryObject!=null ); + DBMetadata dbMetadata = DBMetadata.getDBMetadata(memoryObject); + + logger.debug("Showing up memory and database versions of component "+dbMetadata.getDebugName()); + + // we get the database version of the component + HashMap databaseObject; + try { + databaseObject = this.connection.getObjectFromDatabase(memoryObject, memoryObjectversion); + } catch (Exception err) { + DBGuiUtils.popup(Level.ERROR, "Failed to get component "+dbMetadata.getDebugName()+" from the database.", err); + return null; + } + + boolean areIdentical = true; + + if ( treeItem == null ) { // the root component + tree.removeAll(); + refreshDisplay(); + + TreeItem item = new TreeItem(tree, SWT.NONE); + item.setText(new String[] {"Version", String.valueOf(dbMetadata.getInitialVersion().getVersion()), String.valueOf(databaseObject.get("version"))}); + + if ( (String)databaseObject.get("created_by") != null ) { + item = new TreeItem(tree, SWT.NONE); + item.setText(new String[] {"Created by", System.getProperty("user.name"), (String)databaseObject.get("created_by")}); + } + + if ( databaseObject.get("created_on") != null ) { + item = new TreeItem(tree, SWT.NONE); + if ( dbMetadata.getDatabaseVersion().getTimestamp() != null ) + item.setText(new String[] {"Created on", new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(dbMetadata.getInitialVersion().getTimestamp().getTime()), new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(databaseObject.get("created_on"))}); + else + item.setText(new String[] {"Created on", "", new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(databaseObject.get("created_on"))}); + } + } - this.dialog.addListener(SWT.Close, new Listener() - { - @Override - public void handleEvent(Event event) - { - boolean doIt = true; - if ( DBGui.this.btnClose.getText().equals("Cancel") ) { - doIt = question("Are you sure you wish to cancel ?"); - } - - if ( doIt ) { - setClosedByUser(true); - try { - rollbackAndCloseConnection(); - } catch (SQLException e) { - popup(Level.ERROR, "Failed to rollback and close the database connection.", e); - } - close(); - event.doit = true; - } - } - }); - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// compoLeft //////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - this.compoLeft = new Composite(this.dialog, SWT.BORDER); - this.compoLeft.setBackground(COMPO_LEFT_COLOR); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(0, 160); - fd.bottom = new FormAttachment(100, -40); - this.compoLeft.setLayoutData(fd); - this.compoLeft.setLayout(new FormLayout()); - - Composite compoTitle = new Composite(this.compoLeft, SWT.BORDER); - compoTitle.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(140,50); - fd.top = new FormAttachment(0, 40); - fd.left = new FormAttachment(5); - fd.right = new FormAttachment(100, -5); - compoTitle.setLayoutData(fd); - compoTitle.setLayout(new FormLayout()); - - Label lblTitle = new Label(compoTitle, SWT.CENTER); - lblTitle.setBackground(COMPO_LEFT_COLOR); - lblTitle.setText("Archi database plugin"); - lblTitle.setFont(TITLE_FONT); - fd = new FormData(); - fd.top = new FormAttachment(10); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - lblTitle.setLayoutData(fd); - - Label lblPluginVersion = new Label(compoTitle, SWT.CENTER); - lblPluginVersion.setBackground(COMPO_LEFT_COLOR); - lblPluginVersion.setText(DBPlugin.pluginVersion.toString()); - fd = new FormData(); - fd.top = new FormAttachment(lblTitle, 5); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - lblPluginVersion.setLayoutData(fd); - - Label imgDatabase = new Label(this.compoLeft, SWT.CENTER); - imgDatabase.setBackground(COMPO_LEFT_COLOR); - imgDatabase.setImage(LOGO_IMAGE); - fd = new FormData(135,115); - fd.top = new FormAttachment(compoTitle, 30); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - imgDatabase.setLayoutData(fd); - - this.imgFirstAction = new Label(this.compoLeft, SWT.CENTER); - this.imgFirstAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(10,10); - fd.top = new FormAttachment(imgDatabase, 50); - fd.left = new FormAttachment(0, 10); - this.imgFirstAction.setLayoutData(fd); - - this.lblFirstAction = new Label(this.compoLeft, SWT.NONE); - this.lblFirstAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.imgFirstAction, 0, SWT.CENTER); - fd.left = new FormAttachment(this.imgFirstAction, 10); - fd.right = new FormAttachment(100, -10); - this.lblFirstAction.setLayoutData(fd); - - this.imgSecondAction = new Label(this.compoLeft, SWT.CENTER); - this.imgSecondAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(10,10); - fd.top = new FormAttachment(this.imgFirstAction, 10); - fd.left = new FormAttachment(0, 10); - this.imgSecondAction.setLayoutData(fd); - - this.lblSecondAction = new Label(this.compoLeft, SWT.NONE); - this.lblSecondAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.imgSecondAction, 0, SWT.CENTER); - fd.left = new FormAttachment(this.imgSecondAction, 10); - fd.right = new FormAttachment(100, -10); - this.lblSecondAction.setLayoutData(fd); - - this.imgThirdAction = new Label(this.compoLeft, SWT.CENTER); - this.imgThirdAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(10,10); - fd.top = new FormAttachment(this.imgSecondAction, 10); - fd.left = new FormAttachment(0, 10); - this.imgThirdAction.setLayoutData(fd); - - this.lblThirdAction = new Label(this.compoLeft, SWT.NONE); - this.lblThirdAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.imgThirdAction, 0, SWT.CENTER); - fd.left = new FormAttachment(this.imgThirdAction, 10); - fd.right = new FormAttachment(100, -10); - this.lblThirdAction.setLayoutData(fd); - - this.imgFourthAction = new Label(this.compoLeft, SWT.CENTER); - this.imgFourthAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(10,10); - fd.top = new FormAttachment(this.imgThirdAction, 10); - fd.left = new FormAttachment(0, 10); - this.imgFourthAction.setLayoutData(fd); - - this.lblFourthAction = new Label(this.compoLeft, SWT.NONE); - this.lblFourthAction.setBackground(COMPO_LEFT_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.imgFourthAction, 0, SWT.CENTER); - fd.left = new FormAttachment(this.imgFourthAction, 10); - fd.right = new FormAttachment(100, -10); - this.lblFourthAction.setLayoutData(fd); - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// compoRight /////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - this.compoRight = new Composite(this.dialog, SWT.BORDER); - this.compoRight.setBackground(COMPO_BACKGROUND_COLOR); - FormData fd_compoRight = new FormData(); - fd_compoRight.top = new FormAttachment(0); - fd_compoRight.bottom = new FormAttachment(100, -40); - fd_compoRight.left = new FormAttachment(this.compoLeft); - fd_compoRight.right = new FormAttachment(100); - this.compoRight.setLayoutData(fd_compoRight); - this.compoRight.setLayout(new FormLayout()); - - this.compoRightTop = new Composite(this.compoRight, SWT.NONE); - this.compoRightTop.setBackground(COMPO_BACKGROUND_COLOR); - FormData fd_compoRightUp = new FormData(); - fd_compoRightUp.top = new FormAttachment(0, 10); - fd_compoRightUp.bottom = new FormAttachment(0, 70); - fd_compoRightUp.left = new FormAttachment(0, 10); - fd_compoRightUp.right = new FormAttachment(100, -10); - this.compoRightTop.setLayoutData(fd_compoRightUp); - this.compoRightTop.setLayout(new FormLayout()); - - this.compoRightBottom = new Composite(this.compoRight, SWT.NONE); - this.compoRightBottom.setBackground(COMPO_BACKGROUND_COLOR); - FormData fd_compoRightBottom = new FormData(); - fd_compoRightBottom.top = new FormAttachment(this.compoRightTop, 10); - fd_compoRightBottom.bottom = new FormAttachment(100, -10); - fd_compoRightBottom.left = new FormAttachment(0, 10); - fd_compoRightBottom.right = new FormAttachment(100, -10); - this.compoRightBottom.setLayoutData(fd_compoRightBottom); - this.compoRightBottom.setLayout(new FormLayout()); - - this.grpDatabase = new Group(this.compoRightTop, SWT.SHADOW_ETCHED_IN); - this.grpDatabase.setVisible(true); - this.grpDatabase.setData("visible", true); - this.grpDatabase.setBackground(GROUP_BACKGROUND_COLOR); - this.grpDatabase.setFont(GROUP_TITLE_FONT); - this.grpDatabase.setText("Database: "); - fd = new FormData(); - fd.top = new FormAttachment(0); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - fd.bottom = new FormAttachment(100); - this.grpDatabase.setLayoutData(fd); - this.grpDatabase.setLayout(new FormLayout()); - - Label lblRegisteredDatabases = new Label(this.grpDatabase, SWT.NONE); - lblRegisteredDatabases.setBackground(GROUP_BACKGROUND_COLOR); - lblRegisteredDatabases.setText("Registered databases:"); - fd = new FormData(); - fd.top = new FormAttachment(25); - fd.left = new FormAttachment(0, 10); - lblRegisteredDatabases.setLayoutData(fd); - - this.btnSetPreferences = new Button(this.grpDatabase, SWT.NONE); - this.btnSetPreferences.setText("Set preferences ..."); - this.btnSetPreferences.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent event) { try { setPreferences(); } catch (Exception e) { popup(Level.ERROR, "Failed to set preferences", e); } } - @Override - public void widgetDefaultSelected(SelectionEvent event) { widgetSelected(event); } - }); - fd = new FormData(); - fd.top = new FormAttachment(lblRegisteredDatabases, 0, SWT.CENTER); - fd.right = new FormAttachment(100, -10); - this.btnSetPreferences.setLayoutData(fd); - - this.comboDatabases = new Combo(this.grpDatabase, SWT.NONE | SWT.READ_ONLY); - this.comboDatabases.setBackground(GROUP_BACKGROUND_COLOR); - this.comboDatabases.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent event) { databaseSelected(); } - @Override - public void widgetDefaultSelected(SelectionEvent event) { widgetSelected(event); } - }); - fd = new FormData(); - fd.top = new FormAttachment(lblRegisteredDatabases, 0, SWT.CENTER); - fd.left = new FormAttachment(lblRegisteredDatabases, 10); - fd.right = new FormAttachment(this.btnSetPreferences, -40); - this.comboDatabases.setLayoutData(fd); - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// compoBottom ////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - this.compoBottom = new Composite(this.dialog, SWT.NONE); - this.compoBottom.setBackground(COMPO_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(100, -40); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - fd.bottom = new FormAttachment(100); - this.compoBottom.setLayoutData(fd); - this.compoBottom.setLayout(new FormLayout()); - - this.btnHelp = new Label(this.compoBottom, SWT.NONE); - this.btnHelp.setVisible(false); - this.btnHelp.addListener(SWT.MouseEnter, new Listener() { @Override public void handleEvent(Event event) { DBGui.this.mouseOverHelpButton = true; DBGui.this.btnHelp.redraw(); } }); - this.btnHelp.addListener(SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { DBGui.this.mouseOverHelpButton = false; DBGui.this.btnHelp.redraw(); } }); - this.btnHelp.addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent event) - { - if ( DBGui.this.mouseOverHelpButton ) event.gc.drawRoundRectangle(0, 0, 29, 29, 10, 10); - event.gc.drawImage(HELP_ICON, 2, 2); - } - }); - this.btnHelp.addListener(SWT.MouseUp, new Listener() { @Override public void handleEvent(Event event) { if ( DBGui.this.HELP_HREF != null ) { if ( logger.isDebugEnabled() ) logger.debug("Showing help: /"+DBPlugin.PLUGIN_ID+"/help/html/"+DBGui.this.HELP_HREF); PlatformUI.getWorkbench().getHelpSystem().displayHelpResource("/"+DBPlugin.PLUGIN_ID+"/help/html/"+DBGui.this.HELP_HREF); } } }); - fd = new FormData(30,30); - fd.top = new FormAttachment(0, 5); - fd.left = new FormAttachment(0, 5); - this.btnHelp.setLayoutData(fd); - - - this.btnClose = new Button(this.compoBottom, SWT.NONE); - this.btnClose.setText("Close"); - this.btnClose.addSelectionListener(new SelectionListener() { - @Override - public void widgetSelected(SelectionEvent event) { - boolean doIt = true; - if ( DBGui.this.btnClose.getText().equals("Cancel") ) { - doIt = question("Are you sure you wish to cancel ?"); - } - - if ( doIt ) { - setClosedByUser(true); - try { - rollbackAndCloseConnection(); - } catch (SQLException e) { - popup(Level.ERROR, "Failed to rollback and close the database connection.", e); - } - close(); - event.doit = true; - } - } - @Override - public void widgetDefaultSelected(SelectionEvent event) { widgetSelected(event); } - }); - fd = new FormData(100,25); - fd.top = new FormAttachment(0, 8); - fd.right = new FormAttachment(100, -10); - this.btnClose.setLayoutData(fd); - - this.btnDoAction = new Button(this.compoBottom, SWT.NONE); - this.btnDoAction.setEnabled(false); - this.btnDoAction.setVisible(false); - fd = new FormData(100,25); - fd.top = new FormAttachment(0, 8); - fd.right = new FormAttachment(this.btnClose, -10); - this.btnDoAction.setLayoutData(fd); - - this.radioOption3 = new Button(this.compoBottom, SWT.RADIO); - this.radioOption3.setBackground(COMPO_BACKGROUND_COLOR); - this.radioOption3.setVisible(false); - fd = new FormData(); - fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); - fd.right = new FormAttachment(this.btnDoAction, -20); - this.radioOption3.setLayoutData(fd); - - this.radioOption2 = new Button(this.compoBottom, SWT.RADIO); - this.radioOption2.setBackground(COMPO_BACKGROUND_COLOR); - this.radioOption2.setVisible(false); - fd = new FormData(); - fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); - fd.right = new FormAttachment(this.radioOption3, -10); - this.radioOption2.setLayoutData(fd); - - this.radioOption1 = new Button(this.compoBottom, SWT.RADIO); - this.radioOption1.setBackground(COMPO_BACKGROUND_COLOR); - this.radioOption1.setVisible(false); - fd = new FormData(); - fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); - fd.right = new FormAttachment(this.radioOption2, -10); - this.radioOption1.setLayoutData(fd); - - this.lblOption = new Label(this.compoBottom, SWT.NONE); - this.lblOption.setBackground(COMPO_BACKGROUND_COLOR); - this.lblOption.setVisible(false); - fd = new FormData(); - fd.top = new FormAttachment(this.btnDoAction, 0, SWT.CENTER); - fd.right = new FormAttachment(this.radioOption1, -10); - this.lblOption.setLayoutData(fd); - } - - public void run() { - this.dialog.open(); - this.dialog.layout(); - refreshDisplay(); - } - - /** - * Gets the list of configured databases, fill-in the comboDatabases and select the database provided - * @param mustIncludeNeo4j if true, include the Neo4J databases in the list, if false, do not include them in the list - * @param defaultDatabaseId Indicated the ID of the default database (the first database will be selected, if the database is not found or if null) - * @param defaultDatabaseName Indicated the name of the default database (the first database will be selected, if the database is not found or if null) - if both ID and name are provided, the ID has got higher priority - * @throws Exception - */ - protected void getDatabases(boolean mustIncludeNeo4j, String defaultDatabaseId, String defaultDatabaseName) throws Exception { - refreshDisplay(); - - this.databaseEntries = DBDatabaseEntry.getAllDatabasesFromPreferenceStore(); - this.comboDatabaseEntries = new ArrayList(); - if ( (this.databaseEntries == null) || (this.databaseEntries.size() == 0) ) { - popup(Level.ERROR, "You haven't configure any database yet.\n\nPlease setup at least one database in Archi preferences."); - } else { - int databaseToSelect = -1; - int line = 0; - for (DBDatabaseEntry databaseEntry: this.databaseEntries) { - if ( mustIncludeNeo4j || !databaseEntry.getDriver().equals(DBDatabase.NEO4J.getDriverName()) ) { - this.comboDatabases.add(databaseEntry.getName()); - this.comboDatabaseEntries.add(databaseEntry); - if ( defaultDatabaseId != null && databaseEntry.getId().equals(defaultDatabaseId) ) - databaseToSelect = line; - if ( defaultDatabaseName != null && databaseToSelect != 0 && databaseEntry.getName().equals(defaultDatabaseName) ) - databaseToSelect = line; - ++line; - } - } - if ( line == 0 ) - popup(Level.ERROR, "You haven't configure any SQL database yet.\n\nPlease setup at least one SQL database in Archi preferences."); - else { - // if no default database is provided, then we select the first database in the combo - if ( defaultDatabaseId == null && defaultDatabaseName == null ) - databaseToSelect = 0; - if ( databaseToSelect != -1 ) { - this.comboDatabases.select(databaseToSelect); - this.comboDatabases.notifyListeners(SWT.Selection, new Event()); // calls the databaseSelected() method - } - } - } - } - - /** - * Gets the list of configured databases, fill-in the comboDatabases and select the first-one - * @param mustIncludeNeo4j if true, include the Neo4J databases in the list, if false, do not include them in the list - * @throws Exception - */ - protected void getDatabases(boolean mustIncludeNeo4j) throws Exception { - getDatabases(mustIncludeNeo4j, null, null); - } - - /** - * Called when the user clicks on the "set preferences" button
- * This method opens up the database plugin preference page that the user can configure database details. - * @throws Exception - */ - protected void setPreferences() throws Exception { - if ( logger.isDebugEnabled() ) logger.debug("Openning preference page ..."); - PreferenceDialog prefDialog = PreferencesUtil.createPreferenceDialogOn(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "org.archicontribs.database.DBPreferencePage", null, null); - prefDialog.setBlockOnOpen(true); - if ( prefDialog.open() == 0 ) { - if ( logger.isDebugEnabled() ) logger.debug("Resetting settings from preferences ..."); - - this.comboDatabases.removeAll(); - - this.databaseEntries = DBDatabaseEntry.getAllDatabasesFromPreferenceStore(); - if ( (this.databaseEntries == null) || (this.databaseEntries.size() == 0) ) { - this.comboDatabases.select(0); - popup(Level.ERROR, "You haven't configure any database yet.\n\nPlease setup at least one database in Archi preferences."); - } else { - int line = 0; - for (DBDatabaseEntry databaseEntry: this.databaseEntries) { - if ( this.includeNeo4j || !databaseEntry.getDriver().equals(DBDatabase.NEO4J.getDriverName()) ) { - this.comboDatabases.add(databaseEntry.getName()); - this.comboDatabaseEntries.add(databaseEntry); - ++line; - } - } - if ( line == 0 ) - popup(Level.ERROR, "You haven't configure any SQL database yet.\n\nPlease setup at least one SQL database in Archi preferences."); - else { - this.comboDatabases.select(0); - this.comboDatabases.notifyListeners(SWT.Selection, new Event()); - } - } - } else { - if ( logger.isDebugEnabled() ) logger.debug("Preferences cancelled ..."); - if ( this.comboDatabases.getItemCount() == 0 ) - popup(Level.ERROR, "You won't be able to export until a database is configured in the preferences."); - } - this.comboDatabases.setFocus(); - } - - /** - * Listener called when a database is selected in the comboDatabases
- * This method retrieve the database name from the comboDatabases and reads the preferences to get the connection details. A connection is then established to the database. - */ - protected void databaseSelected() { - setMessage("Connecting to the database ..."); - refreshDisplay(); - - databaseSelectedCleanup(); - - this.btnDoAction.setEnabled(false); - - // we get the databaseEntry corresponding to the selected combo entry - this.selectedDatabase = this.comboDatabaseEntries.get(this.comboDatabases.getSelectionIndex()); - if ( logger.isDebugEnabled() ) logger.debug("Selected database = " + this.selectedDatabase.getName()+" ("+this.selectedDatabase.getDriver()+", "+this.selectedDatabase.getServer()+", "+this.selectedDatabase.getPort()+", "+this.selectedDatabase.getDatabase()+", "+this.selectedDatabase.getUsername()); - - // then we connect to the database. - try { - this.connection = new DBDatabaseImportConnection(this.selectedDatabase); - //if the database connection failed, then an exception is raised, meaning that we get here only if the database connection succeeded - if ( logger.isDebugEnabled() ) logger.debug(DBGui.class, "We are connected to the database."); - } catch (Exception err) { - closeMessage(); - notConnectedToDatabase(); - popup(Level.ERROR, "Cannot connect to the database.", err); - return; - } - - // then, we check if the database has got the right pre-requisites - try { - this.connection.checkDatabase(null); - } catch (Exception err) { - closeMessage(); - popup(Level.ERROR, "Cannot use this database.", err); - notConnectedToDatabase(); - return; - } finally { - closeMessage(); - } - - connectedToDatabase(true); - } - - /** - * This method is called by the databaseSelected method. It allows to do some actions when a new database is selected. - */ - protected void databaseSelectedCleanup() { - //to be overridden - } - - /** - * This method is called by the databaseSelected method. It allows to do some actions when the connection to a new database is successful. - * @param forceCheckDatabase true when the database should be checked. - */ - protected void connectedToDatabase(boolean forceCheckDatabase) { - // to be overridden - enableOption(); - this.btnDoAction.setEnabled(true); - } - - /** - * This method is called by the databaseSelected method. It allows to do some actions when the connection to a new database is failed. - */ - protected void notConnectedToDatabase() { - // to be overridden - disableOption(); - this.btnDoAction.setEnabled(false); - } - - /** - * Sets the reference of the online help - */ - protected void setHelpHref(String href) { - this.HELP_HREF = href; - this.btnHelp.setVisible(this.HELP_HREF != null); - } - - private ACTION activeAction = null; - /** - * Activate an action (on the left handside panel) - * @param action Reference of the action - * @param status status of the action - */ - protected void setActiveAction(ACTION action, STATUS status) { - Image icon; - switch ( status ) { - case Selected: icon = RIGHT_ARROW_ICON; break; - case Running: icon = CLOCK_ICON; break; - case Bypassed: icon = BYPASSED_ICON; break; - case Ok: icon = OK_ICON; break; - case Warn: icon = WARNING_ICON; break; - case Error: icon = ERROR_ICON; break; - case Empty: icon = null; break; - default: icon = null; - } - switch ( action ) { - case One: this.activeAction = ACTION.One; this.imgFirstAction.setImage(icon); break; - case Two: this.activeAction = ACTION.Two; this.imgSecondAction.setImage(icon); break; - case Three: this.activeAction = ACTION.Three; this.imgThirdAction.setImage(icon); break; - case Four: this.activeAction = ACTION.Four; this.imgFourthAction.setImage(icon); break; - default: - } - } - - /** - * Changes the status of the current action (on the left handside panel) - * @param status status of the action - */ - protected void setActiveAction(STATUS status) { - if ( this.activeAction == null ) - this.activeAction = ACTION.One; - setActiveAction(this.activeAction, status); - } - - /** - * Changes the active action (on the left handside panel) - * @param action Reference of the action - */ - protected void setActiveAction(ACTION action) { - setActiveAction(action, STATUS.Selected); - } - - /** - * Creates an action (on the left handside panel) - * @param action Reference of the action - * @param label Label of the action - */ - protected void createAction(ACTION action, String label) { - switch ( action ) { - case One: this.lblFirstAction.setText(label); break; - case Two: this.lblSecondAction.setText(label); break; - case Three: this.lblThirdAction.setText(label); break; - case Four: this.lblFourthAction.setText(label); break; - default: - } - } - - protected void setOption(int selectedOption) { - int realSelectedOption = selectedOption % 3; - this.radioOption1.setSelection(realSelectedOption == 0); - this.radioOption2.setSelection(realSelectedOption == 1); - this.radioOption3.setSelection(realSelectedOption == 2); - } - - protected void setOption(String label, String option1, boolean option1Selected, String toolTip1, String option2, boolean option2Selected, String toolTip2, String option3, boolean option3Selected, String toolTip3) { - if ( label != null ) this.lblOption.setText(label); - - if ( option1 == null ) { - this.radioOption1.setText(""); - this.radioOption1.setToolTipText(""); - this.radioOption1.setVisible(false); - } else { - this.radioOption1.setText(option1); - this.radioOption1.setSelection(option1Selected); - this.radioOption1.setVisible(true); - if ( toolTip1 != null ) this.radioOption1.setToolTipText(toolTip1); - } - - if ( option2 == null ) { - this.radioOption2.setText(""); - this.radioOption2.setToolTipText(""); - this.radioOption2.setVisible(true); - } else { - this.radioOption2.setText(option2); - this.radioOption2.setSelection(option2Selected); - this.radioOption2.setVisible(true); - if ( toolTip2 != null ) this.radioOption2.setToolTipText(toolTip2); - } - - if ( option3 == null ) { - this.radioOption3.setText(""); - this.radioOption3.setToolTipText(""); - this.radioOption3.setVisible(false); - } else { - this.radioOption3.setText(option3); - this.radioOption3.setSelection(option3Selected); - this.radioOption3.setVisible(true); - if ( toolTip3 != null ) this.radioOption3.setToolTipText(toolTip3); - } - - this.compoBottom.layout(); - - showOption(); - disableOption(); - } - - protected void enableOption() { - this.lblOption.setEnabled(true); - this.radioOption1.setEnabled(true); - this.radioOption2.setEnabled(true); - this.radioOption3.setEnabled(true); - } - - protected void disableOption() { - this.lblOption.setEnabled(false); - this.radioOption1.setEnabled(false); - this.radioOption2.setEnabled(false); - this.radioOption3.setEnabled(false); - } - - protected void hideOption() { - this.lblOption.setVisible(false); - this.radioOption1.setVisible(false); - this.radioOption2.setVisible(false); - this.radioOption3.setVisible(false); - } - - protected void showOption() { - this.lblOption.setVisible(true); - this.radioOption1.setVisible(this.radioOption1.getText().length() != 0); - this.radioOption2.setVisible(this.radioOption2.getText().length() != 0); - this.radioOption3.setVisible(this.radioOption3.getText().length() != 0); - } - - /** - * Returns the value of the selected option:
- * 1 for the first option
- * 2 for the second option
- * 3 for the third option - */ - protected int getOptionValue() { - if ( this.radioOption1.getSelection() ) - return 1; - if ( this.radioOption2.getSelection() ) - return 2; - if ( this.radioOption3.getSelection() ) - return 3; - return 0; - } - - - - static Shell dialogShell = null; - static Composite dialogComposite = null; - static Label dialogLabel = null; - /** - * shows up an on screen popup displaying the message but does not wait for any user input
- * it is the responsibility of the caller to dismiss the popup - */ - public static Shell popup(String msg) { - logger.info(DBGui.class, msg); - - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - if ( dialogShell == null ) { - dialogShell = new Shell(display, SWT.APPLICATION_MODAL); - dialogShell.setSize(500, 70); - dialogShell.setBackground(BLACK_COLOR); - - // Use the active shell, if available, to determine the new shell placing - int locationX = 0; - int locationY = 0; - Rectangle shellSize = dialogShell.getBounds(); - Shell parent = display.getActiveShell(); - if (parent!=null) { - Rectangle parentSize = parent.getBounds(); - locationX = (parentSize.width - shellSize.width)/2+parentSize.x; - locationY = (parentSize.height - shellSize.height)/2+parentSize.y; - } else { - locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - 500) / 4; - locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - 70) / 4; - } - dialogShell.setLocation(new Point(locationX, locationY)); - - int borderWidth = (dialogShell.getBorderWidth()+1)*2; - dialogComposite = new Composite(dialogShell, SWT.NONE); - dialogComposite.setSize(500-borderWidth, 70-borderWidth); - dialogComposite.setLocation(1, 1); - dialogComposite.setBackground(COMPO_LEFT_COLOR); - dialogComposite.setLayout(new GridLayout( 1, false ) ); - - dialogLabel = new Label(dialogComposite, SWT.CENTER | SWT.WRAP); - dialogLabel.setBackground(COMPO_LEFT_COLOR); - dialogLabel.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, true ) ); - dialogLabel.setFont(TITLE_FONT); - } else { - restoreCursors(); - } - - dialogLabel.setText(msg); - dialogShell.layout(true); - dialogShell.open(); - - dialogComposite.layout(); - - setArrowCursor(); - } - }); - - return dialogShell; - } - - /** - * dismiss the popup if it is displayed (else, does nothing) - */ - public static void closePopup() { - if ( dialogShell != null ) { - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - dialogShell.close(); - dialogShell = null; - - restoreCursors(); - } - }); - } - } - - private static Stack> cursorsStack = new Stack>(); - public static void setArrowCursor() { - Map cursors = new HashMap(); - for ( Shell shell: display.getShells() ) { - cursors.put(shell, shell.getCursor()); - shell.setCursor(CURSOR_WAIT); - } - cursorsStack.push(cursors); - refreshDisplay(); - } - - public static void restoreCursors() { - Map cursors = cursorsStack.pop(); - for ( Shell shell: display.getShells() ) { - Cursor cursor = (cursors==null) ? null : cursors.get(shell); - shell.setCursor(cursor==null ? CURSOR_ARROW : cursor); - } - refreshDisplay(); - } - - /** - * Shows up an on screen popup displaying the message and wait for the user to click on the "OK" button - */ - public static void popup(Level level, String msg) { - popup(level,msg,null); - } - - /** - * Shows up an on screen popup, displaying the message (and the exception message if any) and wait for the user to click on the "OK" button
- * The exception stacktrace is also printed on the standard error stream - */ - public static void popup(Level level, String msg, Exception e) { - String popupMessage = msg; - logger.log(DBGui.class, level, msg, e); - - Throwable cause = e; - while ( cause != null ) { - if ( cause.getMessage() != null ) { - if ( !popupMessage.endsWith(cause.getMessage()) ) - popupMessage += "\n\n" + cause.getClass().getSimpleName() + ": " + cause.getMessage(); - } else - popupMessage += "\n\n" + cause.getClass().getSimpleName(); - cause = cause.getCause(); - } - - switch ( level.toInt() ) { - case Priority.FATAL_INT: - case Priority.ERROR_INT: - MessageDialog.openError(display.getActiveShell(), DBPlugin.pluginTitle, popupMessage); - break; - case Priority.WARN_INT: - MessageDialog.openWarning(display.getActiveShell(), DBPlugin.pluginTitle, popupMessage); - break; - default: - MessageDialog.openInformation(display.getActiveShell(), DBPlugin.pluginTitle, popupMessage); - break; - } - - refreshDisplay(); - } - - static int questionResult; - - /** - * Shows up an on screen popup displaying the question (and the exception message if any) and wait for the user to click on the "YES" or "NO" button
- * The exception stacktrace is also printed on the standard error stream - */ - public static boolean question(String msg) { - return question(msg, new String[] {"Yes", "No"}) == 0; - } - - /** - * Shows up an on screen popup displaying the question (and the exception message if any) and wait for the user to click on the "YES" or "NO" button
- * The exception stacktrace is also printed on the standard error stream - */ - public static int question(String msg, String[] buttonLabels) { - if ( logger.isDebugEnabled() ) logger.debug(DBGui.class, "Question: "+msg); - - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - //questionResult = MessageDialog.openQuestion(display.getActiveShell(), DBPlugin.pluginTitle, msg); - Shell shell = new Shell(display, SWT.SHELL_TRIM); - shell.setSize(0, 0); - shell.setBackground(BLACK_COLOR); - - // Use the active shell, if available, to determine the new shell placing - int locationX = 0; - int locationY = 0; - Rectangle shellSize = shell.getBounds(); - Shell parent = display.getActiveShell(); - if (parent!=null) { - Rectangle parentSize = parent.getBounds(); - locationX = (parentSize.width - shellSize.width)/2+parentSize.x; - locationY = (parentSize.height - shellSize.height)/2+parentSize.y; - } else { - locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - shell.getSize().x) / 4; - locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - shell.getSize().y) / 4; - } - shell.setLocation(new Point(locationX, locationY)); - MessageDialog messageDialog = new MessageDialog(shell, DBPlugin.pluginTitle, null, msg, MessageDialog.QUESTION, buttonLabels, 0); - questionResult = messageDialog.open(); - } - }); - - if ( logger.isDebugEnabled() ) logger.debug(DBGui.class, "Answer: "+buttonLabels[questionResult]); - return questionResult; - } - - static String answeredPassword; - - /** - * open up an input dialog and ask for a password - * @param message the message on the password dialog - * @return the typed password - */ - public static String passwordDialog(String title, String message) { - if ( logger.isDebugEnabled() ) logger.debug(DBGui.class, "Asking for password"); - answeredPassword = ""; - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - Shell shell = new Shell(display, SWT.SHELL_TRIM); - shell.setText(title); - shell.setSize(0, 0); - shell.setBackground(BLACK_COLOR); - - // Use the active shell, if available, to determine the new shell placing - int locationX = 0; - int locationY = 0; - Rectangle shellSize = shell.getBounds(); - Shell parent = display.getActiveShell(); - if (parent!=null) { - Rectangle parentSize = parent.getBounds(); - locationX = (parentSize.width - shellSize.width)/2+parentSize.x; - locationY = (parentSize.height - shellSize.height)/2+parentSize.y; - } else { - locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - shell.getSize().x) / 4; - locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - shell.getSize().y) / 4; - } - shell.setLocation(new Point(locationX, locationY)); - - DBGuiPasswordDialog passwordDialog = new DBGuiPasswordDialog(shell); - if ( passwordDialog.open() == 0 ) - answeredPassword = passwordDialog.getPassword(); - else - answeredPassword = null; - passwordDialog.close(); - } - }); - - return answeredPassword; - } - - protected void hideGrpDatabase() { - this.grpDatabase.setVisible(false); - this.grpDatabase.setData("visible", false); - } - - protected void showGrpDatabase() { - this.grpDatabase.setVisible(true); - this.grpDatabase.setData("visible", true); - } - - private SelectionListener actionListener = null; - protected void setBtnAction(String label, SelectionListener listener) { - if ( label == null ) { - this.btnDoAction.setVisible(false); - } else { - this.btnDoAction.setText(label); - this.btnDoAction.setVisible(true); - - if ( this.actionListener != null ) { - this.btnDoAction.removeSelectionListener(this.actionListener); - this.actionListener = null; - } - - if ( listener != null ) { - this.actionListener = listener; - this.btnDoAction.addSelectionListener(this.actionListener); - } - } - } - - /** - * Creates the progress bar that will allow to follow the export process - */ - protected void createProgressBar(String label, int min, int max) { - if ( this.grpProgressBar == null ) { - this.grpProgressBar = new Group(this.compoRightTop, SWT.NONE); - this.grpProgressBar.setBackground(GROUP_BACKGROUND_COLOR); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - fd.bottom = new FormAttachment(100); - this.grpProgressBar.setLayoutData(fd); - this.grpProgressBar.setLayout(new FormLayout()); - - - this.lblProgressBar = new Label(this.grpProgressBar, SWT.CENTER); - this.lblProgressBar.setBackground(GROUP_BACKGROUND_COLOR); - this.lblProgressBar.setFont(TITLE_FONT); - fd = new FormData(); - fd.top = new FormAttachment(0, -5); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - this.lblProgressBar.setLayoutData(fd); - - this.progressBar = new ProgressBar(this.grpProgressBar, SWT.NONE); - fd = new FormData(); - fd.top = new FormAttachment(this.lblProgressBar); - fd.left = new FormAttachment(25); - fd.right = new FormAttachment(75); - fd.height = 15; - this.progressBar.setLayoutData(fd); - } - - this.grpProgressBar.setVisible(true); - this.grpProgressBar.setData("visible", true); - - this.grpProgressBar.moveAbove(null); - - this.lblProgressBar.setText(label); - logger.info(DBGui.class, label); - - this.progressBar.setMinimum(min); - this.progressBar.setMaximum(max); - - - this.compoRightTop.layout(); - refreshDisplay(); - - resetProgressBar(); - } - - public void hideProgressBar() { - if ( this.progressBar != null ) { - this.grpProgressBar.setVisible(false); - this.grpProgressBar.setData("visible", false); - refreshDisplay(); - } - } - - public void setProgressBarLabel(String label) { - if ( this.lblProgressBar == null ) - createProgressBar(label, 0, 100); - else { - this.lblProgressBar.setText(label); - logger.info(DBGui.class, label); - } - refreshDisplay(); - } - - public String getProgressBarLabel() { - if ( this.lblProgressBar == null ) - return ""; - - return this.lblProgressBar.getText(); - } - - /** - * Sets the min and max values of the progressBar and reset its selection to zero - */ - public void setProgressBarMinAndMax(int min, int max) { - if ( this.lblProgressBar != null ) { - this.progressBar.setMinimum(min); - this.progressBar.setMaximum(max); - } - resetProgressBar(); - } - - /** - * Resets the progressBar to zero in the SWT thread (thread safe method) - */ - public void resetProgressBar() { - if ( this.lblProgressBar != null ) - this.progressBar.setSelection(0); - refreshDisplay(); - } - - /** - * Increases the progressBar selection in the SWT thread (thread safe method) - */ - public void increaseProgressBar() { - if ( this.lblProgressBar != null ) - this.progressBar.setSelection(this.progressBar.getSelection()+1); - refreshDisplay(); - } - - public void setMessage(String message) { - setMessage(message, GROUP_BACKGROUND_COLOR); - } - - protected void setMessage(String message, Color background) { - if ( this.grpMessage == null ) { - this.grpMessage = new Group(this.compoRightTop, SWT.NONE); - this.grpMessage.setBackground(GROUP_BACKGROUND_COLOR); - this.grpMessage.setFont(GROUP_TITLE_FONT); - this.grpMessage.setText("Please wait ... "); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - fd.bottom = new FormAttachment(100); - this.grpMessage.setLayoutData(fd); - this.grpMessage.setLayout(new FormLayout()); - - this.lblMessage = new CLabel(this.grpMessage, SWT.CENTER); - this.lblMessage.setAlignment(SWT.CENTER); - this.lblMessage.setBackground(GROUP_BACKGROUND_COLOR); - this.lblMessage.setFont(TITLE_FONT); - fd = new FormData(); - fd.top = new FormAttachment(0); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - fd.bottom = new FormAttachment(100); - this.lblMessage.setLayoutData(fd); - refreshDisplay(); - } - - this.grpMessage.setVisible(true); - - if (this.grpProgressBar != null ) - this.grpProgressBar.setVisible(false); - - if ( this.grpDatabase != null ) - this.grpDatabase.setVisible(false); - - this.compoRightTop.layout(); - - this.lblMessage.setBackground(background); - - String msg = message.replace("\n\n", "\n"); - if ( background == RED_COLOR ) - logger.error(DBGui.class, msg); - else - logger.info(DBGui.class, msg); - - this.lblMessage.setText(msg); - - this.grpMessage.moveAbove(null); - - refreshDisplay(); - } - - - public void closeMessage() { - if ( (this.grpMessage != null) && !this.grpMessage.isDisposed() ) { - this.grpMessage.setVisible(false); - - if (this.grpProgressBar != null && (this.grpProgressBar.getData("visible") != null) ) - this.grpProgressBar.setVisible((boolean)this.grpProgressBar.getData("visible")); - - if ( this.grpDatabase != null && (this.grpDatabase.getData("visible") != null) ) - this.grpDatabase.setVisible((boolean)this.grpDatabase.getData("visible")); - - this.compoRightTop.layout(); - refreshDisplay(); - } - } - - /** - * Method used to close graphical objects if needed - */ - public void close() { - this.dialog.dispose(); - this.dialog = null; - - restoreCursors(); - } - - public void commitAndCloseConnection() throws SQLException { - if ( this.connection != null ) { - // in case some transactions have been started, we commit them - this.connection.commit(); - - this.connection.close(); - this.connection = null; - } - } - - public void rollbackAndCloseConnection() throws SQLException { - if ( this.connection != null ) { - // in case some transactions have been started, we roll them back - this.connection.rollback(); - - this.connection.close(); - this.connection = null; - } - } - - public boolean isDisposed() { - return this.dialog==null ? true : this.dialog.isDisposed(); - } - - protected Boolean fillInCompareTable(Tree tree, EObject memoryObject, int memoryObjectversion) { - return fillInCompareTable(tree, null, memoryObject, memoryObjectversion); - } - - @SuppressWarnings("unchecked") - protected Boolean fillInCompareTable(Tree tree, TreeItem treeItem, EObject memoryObject, int memoryObjectversion) { - assert ( memoryObject!=null ); - DBMetadata dbMetadata = DBMetadata.getDBMetadata(memoryObject); - - logger.debug(DBGui.class, "Showing up memory and database versions of component "+dbMetadata.getDebugName()); - - // we get the database version of the component - HashMap databaseObject; - try { - databaseObject = this.connection.getObjectFromDatabase(memoryObject, memoryObjectversion); - } catch (Exception err) { - DBGui.popup(Level.ERROR, "Failed to get component "+dbMetadata.getDebugName()+" from the database.", err); - return null; - } - - boolean areIdentical = true; - - if ( treeItem == null ) { // the root component - tree.removeAll(); - refreshDisplay(); - - TreeItem item = new TreeItem(tree, SWT.NONE); - item.setText(new String[] {"Version", String.valueOf(dbMetadata.getInitialVersion().getVersion()), String.valueOf(databaseObject.get("version"))}); - - if ( (String)databaseObject.get("created_by") != null ) { - item = new TreeItem(tree, SWT.NONE); - item.setText(new String[] {"Created by", System.getProperty("user.name"), (String)databaseObject.get("created_by")}); - } - - if ( databaseObject.get("created_on") != null ) { - item = new TreeItem(tree, SWT.NONE); - if ( dbMetadata.getDatabaseVersion().getTimestamp() != null ) - item.setText(new String[] {"Created on", new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(dbMetadata.getInitialVersion().getTimestamp().getTime()), new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(databaseObject.get("created_on"))}); - else - item.setText(new String[] {"Created on", "", new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(databaseObject.get("created_on"))}); - } - } - - areIdentical &= areIdentical &= addItemToCompareTable(tree, treeItem, "Class", memoryObject.getClass().getSimpleName(), (String)databaseObject.get("class")); - areIdentical &= addItemToCompareTable(tree, treeItem, "Name", ((INameable)memoryObject).getName(), (String)databaseObject.get("name")); - - if ( memoryObject instanceof IDocumentable ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Documentation", ((IDocumentable)memoryObject).getDocumentation(), (String)databaseObject.get("documentation")); - - if ( memoryObject instanceof IJunction ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Type", ((IJunction)memoryObject).getType(), (String)databaseObject.get("type")); - - if ( memoryObject instanceof IArchimateRelationship ) { - areIdentical &= addItemToCompareTable(tree, treeItem, "Source id", ((IArchimateRelationship)memoryObject).getSource().getId(), (String)databaseObject.get("source_id")); - areIdentical &= addItemToCompareTable(tree, treeItem, "Target id", ((IArchimateRelationship)memoryObject).getTarget().getId(), (String)databaseObject.get("target_id")); - if ( memoryObject instanceof IInfluenceRelationship ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Strength", ((IInfluenceRelationship)memoryObject).getStrength(), (String)databaseObject.get("strength")); - if ( memoryObject instanceof IAccessRelationship ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Access type", String.valueOf(((IAccessRelationship)memoryObject).getAccessType()), String.valueOf((int)databaseObject.get("access_type"))); - } - - // TODO: get folders subfolders and elements from the database in order to compare them - if ( memoryObject instanceof IFolder ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Folder type", ((IFolder)memoryObject).getType().getLiteral(), FolderType.get((int)databaseObject.get("type")).getLiteral()); - - if ( memoryObject instanceof IArchimateDiagramModel ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Viewpoint", ((IArchimateDiagramModel)memoryObject).getViewpoint(), (String)databaseObject.get("viewpoint")); - - if ( memoryObject instanceof IDiagramModel ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Router type", String.valueOf(((IDiagramModel)memoryObject).getConnectionRouterType()), databaseObject.get("connection_router_type")==null ? null : String.valueOf((int)databaseObject.get("connection_router_type"))); - - if ( memoryObject instanceof IBorderObject ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Border color", ((IBorderObject)memoryObject).getBorderColor(), (String)databaseObject.get("border_color")); - - if ( memoryObject instanceof IDiagramModelNote ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Border type", String.valueOf(((IDiagramModelNote)memoryObject).getBorderType()), databaseObject.get("border_type")==null ? null : String.valueOf((int)databaseObject.get("border_type"))); - - if ( memoryObject instanceof IConnectable ) { - // TODO: get source and target connections from database and compare then to component's ones - /* + areIdentical &= areIdentical &= addItemToCompareTable(tree, treeItem, "Class", memoryObject.getClass().getSimpleName(), (String)databaseObject.get("class")); + areIdentical &= addItemToCompareTable(tree, treeItem, "Name", ((INameable)memoryObject).getName(), (String)databaseObject.get("name")); + + if ( memoryObject instanceof IDocumentable ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Documentation", ((IDocumentable)memoryObject).getDocumentation(), (String)databaseObject.get("documentation")); + + if ( memoryObject instanceof IJunction ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Type", ((IJunction)memoryObject).getType(), (String)databaseObject.get("type")); + + if ( memoryObject instanceof IArchimateRelationship ) { + areIdentical &= addItemToCompareTable(tree, treeItem, "Source id", ((IArchimateRelationship)memoryObject).getSource().getId(), (String)databaseObject.get("source_id")); + areIdentical &= addItemToCompareTable(tree, treeItem, "Target id", ((IArchimateRelationship)memoryObject).getTarget().getId(), (String)databaseObject.get("target_id")); + if ( memoryObject instanceof IInfluenceRelationship ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Strength", ((IInfluenceRelationship)memoryObject).getStrength(), (String)databaseObject.get("strength")); + if ( memoryObject instanceof IAccessRelationship ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Access type", String.valueOf(((IAccessRelationship)memoryObject).getAccessType()), String.valueOf((int)databaseObject.get("access_type"))); + } + + // TODO: get folders subfolders and elements from the database in order to compare them + if ( memoryObject instanceof IFolder ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Folder type", ((IFolder)memoryObject).getType().getLiteral(), FolderType.get((int)databaseObject.get("type")).getLiteral()); + + if ( memoryObject instanceof IArchimateDiagramModel ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Viewpoint", ((IArchimateDiagramModel)memoryObject).getViewpoint(), (String)databaseObject.get("viewpoint")); + + if ( memoryObject instanceof IDiagramModel ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Router type", String.valueOf(((IDiagramModel)memoryObject).getConnectionRouterType()), databaseObject.get("connection_router_type")==null ? null : String.valueOf((int)databaseObject.get("connection_router_type"))); + + if ( memoryObject instanceof IBorderObject ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Border color", ((IBorderObject)memoryObject).getBorderColor(), (String)databaseObject.get("border_color")); + + if ( memoryObject instanceof IDiagramModelNote ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Border type", String.valueOf(((IDiagramModelNote)memoryObject).getBorderType()), databaseObject.get("border_type")==null ? null : String.valueOf((int)databaseObject.get("border_type"))); + + if ( memoryObject instanceof IConnectable ) { + // TODO: get source and target connections from database and compare then to component's ones + /* for ( IDiagramModelConnection conn: ((IConnectable)component).getSourceConnections() ) areIdentical &= addItemToCompareTable(table, level, "source connections", conn.getId(), (String)hashResult.get("xxxxx")); for ( IDiagramModelConnection conn: ((IConnectable)component).getTargetConnections() ) areIdentical &= addItemToCompareTable(table, level, "target connections", conn.getId(), (String)hashResult.get("xxxxx")); - */ - } - - if ( memoryObject instanceof IDiagramModelArchimateObject ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Type", String.valueOf(((IDiagramModelArchimateObject)memoryObject).getType()), databaseObject.get("type")==null ? null : String.valueOf((int)databaseObject.get("type"))); - - if ( memoryObject instanceof IDiagramModelImageProvider ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Image path", ((IDiagramModelImageProvider)memoryObject).getImagePath(), (String)databaseObject.get("image_path")); - - if ( memoryObject instanceof IDiagramModelObject ) { - areIdentical &= addItemToCompareTable(tree, treeItem, "Fill color", ((IDiagramModelObject)memoryObject).getFillColor(), (String)databaseObject.get("fill_color")); - IBounds bounds = ((IDiagramModelObject)memoryObject).getBounds(); - areIdentical &= addItemToCompareTable(tree, treeItem, "X", String.valueOf(bounds.getX()), databaseObject.get("x") == null ? null : String.valueOf((int)databaseObject.get("x"))); - areIdentical &= addItemToCompareTable(tree, treeItem, "Y", String.valueOf(bounds.getY()), databaseObject.get("y")==null ? null : String.valueOf((int)databaseObject.get("y"))); - areIdentical &= addItemToCompareTable(tree, treeItem, "Width" ,String.valueOf(bounds.getWidth()), databaseObject.get("width")==null ? null : String.valueOf((int)databaseObject.get("width"))); - areIdentical &= addItemToCompareTable(tree, treeItem, "Height", String.valueOf(bounds.getHeight()), databaseObject.get("height")==null ? null : String.valueOf((int)databaseObject.get("height"))); - } - - if ( memoryObject instanceof IDiagramModelArchimateComponent ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Archimate concept", ((IDiagramModelArchimateComponent)memoryObject).getArchimateConcept().getId(), (String)databaseObject.get("element_id")); - - if ( memoryObject instanceof IDiagramModelArchimateConnection ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Archimate concept", ((IDiagramModelArchimateConnection)memoryObject).getArchimateConcept().getId(), (String)databaseObject.get("element_id")); - - if ( memoryObject instanceof IFontAttribute ) { - areIdentical &= addItemToCompareTable(tree, treeItem, "Font", ((IFontAttribute)memoryObject).getFont(), (String)databaseObject.get("font")); - areIdentical &= addItemToCompareTable(tree, treeItem, "Font color", ((IFontAttribute)memoryObject).getFontColor(), (String)databaseObject.get("font_color")); - } - - if ( memoryObject instanceof ILineObject ) { - areIdentical &= addItemToCompareTable(tree, treeItem, "Line width", String.valueOf(((ILineObject)memoryObject).getLineWidth()), databaseObject.get("line_width")==null ? null : String.valueOf((int)databaseObject.get("line_width"))); - areIdentical &= addItemToCompareTable(tree, treeItem, "Line color", ((ILineObject)memoryObject).getLineColor(), (String)databaseObject.get("line_color")); - } - - if ( memoryObject instanceof ILockable ) { - // the database can contain a boolean, a char (oracle) or an integer (sqlite, mysql, mssql, postgres) depending on the database brand - String isLockedInDatabase = null; - if ( databaseObject.get("is_locked") != null ) { - if ( databaseObject.get("is_locked") instanceof Boolean ) - isLockedInDatabase = String.valueOf((boolean)databaseObject.get("is_locked")); - - if ( databaseObject.get("is_locked") instanceof Integer ) - isLockedInDatabase = ((int)databaseObject.get("is_locked") == 0) ? "false" : "true"; - - if ( databaseObject.get("is_locked") instanceof String ) - isLockedInDatabase = (Integer.valueOf((String)databaseObject.get("is_locked")) == 0) ? "false" : "true"; - } - areIdentical &= addItemToCompareTable(tree, treeItem, "Locked", String.valueOf(((ILockable)memoryObject).isLocked()), isLockedInDatabase); - } - - if ( memoryObject instanceof ISketchModel ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Background", String.valueOf(((ISketchModel)memoryObject).getBackground()), databaseObject.get("background")==null ? null : String.valueOf((int)databaseObject.get("background"))); - - if ( memoryObject instanceof ITextAlignment ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Text alignment", String.valueOf(((ITextAlignment)memoryObject).getTextAlignment()), databaseObject.get("text_alignment")==null ? null : String.valueOf((int)databaseObject.get("text_alignment"))); - - if ( memoryObject instanceof ITextPosition ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Text position", String.valueOf(((ITextPosition)memoryObject).getTextPosition()), databaseObject.get("text_position")==null ? null : String.valueOf((int)databaseObject.get("text_position"))); - - if ( memoryObject instanceof ITextContent ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Content", ((ITextContent)memoryObject).getContent(), (String)databaseObject.get("content")); - - if ( dbMetadata.getImagePosition() != null ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Image position", String.valueOf(dbMetadata.getImagePosition()), databaseObject.get("image_position")==null ? null : String.valueOf((int)databaseObject.get("image_position"))); - - if ( memoryObject instanceof INotesContent ) - areIdentical &= addItemToCompareTable(tree, treeItem, "Notes", ((INotesContent)memoryObject).getNotes(), (String)databaseObject.get("notes")); - - if ( memoryObject instanceof IDiagramModelConnection ) { - areIdentical &= addItemToCompareTable(tree, treeItem, "Type", String.valueOf(((IDiagramModelConnection)memoryObject).getType()), databaseObject.get("type")==null ? null : String.valueOf((int)databaseObject.get("type"))); // we do not use getText as it is deprecated - areIdentical &= addItemToCompareTable(tree, treeItem, "Text position", String.valueOf(((IDiagramModelConnection)memoryObject).getTextPosition()), databaseObject.get("text_position")==null ? null : String.valueOf((int)databaseObject.get("text_position"))); - - // we show up the bendpoints only if they both exist - if ( databaseObject.containsKey("bendpoints") ) { - if ( (((IDiagramModelConnection)memoryObject).getBendpoints().size() != 0) || (((ArrayList)databaseObject.get("bendpoints")).size() != 0) ) { - TreeItem bendpointsTreeItem; - if ( treeItem == null ) - bendpointsTreeItem = new TreeItem(tree, SWT.NONE); - else - bendpointsTreeItem = new TreeItem(treeItem, SWT.NONE); - bendpointsTreeItem.setText("Bendpoints"); - bendpointsTreeItem.setExpanded(false); - - // we get a list of component's bendpoints - Integer[][] componentBendpoints = new Integer[((IDiagramModelConnection)memoryObject).getBendpoints().size()][4]; - for (int i = 0; i < ((IDiagramModelConnection)memoryObject).getBendpoints().size(); ++i) { - componentBendpoints[i] = new Integer[] { ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getStartX(), ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getStartY(), ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getEndX(), ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getEndY() }; - } - //Arrays.sort(componentBendpoints, this.integerComparator);www - - // we get a list of properties from the database - Integer[][] databaseBendpoints = new Integer[((ArrayList)databaseObject.get("bendpoints")).size()][4]; - int i = 0; - for (DBBendpoint bp: (ArrayList)databaseObject.get("bendpoints") ) { - componentBendpoints[i] = new Integer[] { bp.getStartX(), bp.getStartY(), bp.getEndX(), bp.getEndY() }; - ++i; - } - //Arrays.sort(databaseBendpoints, this.integerComparator); - - int indexComponent = 0; - int indexDatabase = 0; - while ( (indexComponent < componentBendpoints.length) || (indexDatabase < databaseBendpoints.length) ) { - TreeItem subTreeItem = new TreeItem(bendpointsTreeItem, SWT.NONE); - subTreeItem.setText("Bendpoint "+Math.max(indexComponent, indexDatabase)+1); - subTreeItem.setExpanded(false); - if ( indexComponent >= componentBendpoints.length ) { // only the database has got the property - areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start X", null, String.valueOf(databaseBendpoints[indexDatabase][0])); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start Y", null, String.valueOf(databaseBendpoints[indexDatabase][1])); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "End X", null, String.valueOf(databaseBendpoints[indexDatabase][2])); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "End Y", null, String.valueOf(databaseBendpoints[indexDatabase][3])); - ++indexDatabase; - } else if ( indexDatabase >= databaseBendpoints.length ) { // only the component has got the property - areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start X", String.valueOf(componentBendpoints[indexComponent][0]), null); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start Y", String.valueOf(componentBendpoints[indexComponent][1]), null); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "End X", String.valueOf(componentBendpoints[indexComponent][2]), null); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "End Y", String.valueOf(componentBendpoints[indexComponent][3]), null); - ++indexComponent; - } else { - areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start X", String.valueOf(componentBendpoints[indexComponent][0]), String.valueOf(databaseBendpoints[indexDatabase][0])); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start Y", String.valueOf(componentBendpoints[indexComponent][1]), String.valueOf(databaseBendpoints[indexDatabase][1])); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "End X", String.valueOf(componentBendpoints[indexComponent][2]), String.valueOf(databaseBendpoints[indexDatabase][2])); - areIdentical &= addItemToCompareTable(tree, subTreeItem, "End Y", String.valueOf(componentBendpoints[indexComponent][3]), String.valueOf(databaseBendpoints[indexDatabase][3])); - ++indexComponent; - ++indexDatabase; - } - } - } - } - } - - // we show up the properties if both exist - if ( databaseObject.containsKey("properties") ) { - if ( memoryObject instanceof IProperties && ((IProperties)memoryObject).getProperties().size() != 0) { - TreeItem propertiesTreeItem; - if ( treeItem == null ) - propertiesTreeItem = new TreeItem(tree, SWT.NONE); - else - propertiesTreeItem = new TreeItem(treeItem, SWT.NONE); - propertiesTreeItem.setText("Properties"); - propertiesTreeItem.setExpanded(true); - - // we get a sorted list of component's properties - ArrayList componentProperties = new ArrayList(); - for (int i = 0; i < ((IProperties)memoryObject).getProperties().size(); ++i) { - componentProperties.add(new DBProperty(((IProperties)memoryObject).getProperties().get(i).getKey(), ((IProperties)memoryObject).getProperties().get(i).getValue())); - } - Collections.sort(componentProperties, this.propertyComparator); - - // we get a sorted list of properties from the database - ArrayList databaseProperties = (ArrayList)databaseObject.get("properties"); - Collections.sort(databaseProperties, this.propertyComparator); - - Collator collator = Collator.getInstance(); - int indexComponent = 0; - int indexDatabase = 0; - int compare; - while ( (indexComponent < componentProperties.size()) || (indexDatabase < databaseProperties.size()) ) { - if ( indexComponent >= componentProperties.size() ) - compare = 1; - else { - if ( indexDatabase >= databaseProperties.size() ) - compare = -1; - else - compare = collator.compare(componentProperties.get(indexComponent).getKey(), databaseProperties.get(indexDatabase).getKey()); - } - - if ( compare == 0 ) { // both have got the same property - areIdentical &= addItemToCompareTable(tree, propertiesTreeItem, componentProperties.get(indexComponent).getKey(), componentProperties.get(indexComponent).getValue(), databaseProperties.get(indexDatabase).getValue()); - ++indexComponent; - ++indexDatabase; - } else if ( compare < 0 ) { // only the component has got the property - areIdentical &= addItemToCompareTable(tree, propertiesTreeItem, componentProperties.get(indexComponent).getKey(), componentProperties.get(indexComponent).getValue(), null); - ++indexComponent; - } else { // only the database has got the property - areIdentical &= addItemToCompareTable(tree, propertiesTreeItem, componentProperties.get(indexDatabase).getKey(), null, databaseProperties.get(indexDatabase).getValue()); - ++indexDatabase; - } - } - } - } - - refreshDisplay(); - return areIdentical; - } - - Comparator propertyComparator = new Comparator() { - @Override - public int compare(final DBProperty row1, final DBProperty row2) { - return Collator.getInstance().compare(row1.getKey(),row2.getKey()); - } - }; - - Comparator integerComparator = new Comparator() { - @Override - public int compare(final Integer[] row1, final Integer[] row2) { - return Collator.getInstance().compare(row1[0],row2[0]); - } - }; - - - /** - * Helper function to fill in the compareTable - * @return true if col2 and col3 are equals, false if they differ - */ - private static boolean addItemToCompareTable(Tree tree, TreeItem treeItem, String col1, String col2, String col3) { - TreeItem subTreeItem; - boolean isIdentical; - - if ( treeItem != null ) - subTreeItem = new TreeItem(treeItem, SWT.NULL); - else - subTreeItem = new TreeItem(tree, SWT.NONE); - - subTreeItem.setText(new String[] {col1, col2, col3 }); - if ( !DBPlugin.areEqual(col2, col3) ) { - if ( treeItem != null ) - treeItem.setBackground(DBGui.LIGHT_RED_COLOR); - subTreeItem.setBackground(DBGui.LIGHT_RED_COLOR); - isIdentical = false; - } else - isIdentical = true; - - refreshDisplay(); - return isIdentical; - } - - public byte[] createImage(IDiagramModel view, int scalePercent, int margin) { - byte[] imageContent = null; - DBMetadata dbMetadata = DBMetadata.getDBMetadata(view); - - String oldLabel = getProgressBarLabel(); - logger.debug(DBGui.class, "Creating screenshot of view \""+view.getName()+"\""); - - try ( ByteArrayOutputStream out = new ByteArrayOutputStream() ) { - try ( DataOutputStream writeOut = new DataOutputStream(out) ) { - ImageLoader saver = new ImageLoader(); - ModelReferencedImage viewImage = DiagramUtils.createModelReferencedImage(view, scalePercent/100.0, margin); - Image image = viewImage.getImage(); - - saver.data = new ImageData[] { image.getImageData(ImageFactory.getDeviceZoom()) }; - image.dispose(); - - saver.save(writeOut, SWT.IMAGE_PNG); - imageContent = out.toByteArray(); - - org.eclipse.draw2d.geometry.Rectangle bounds = viewImage.getBounds(); - bounds.performScale(ImageFactory.getDeviceZoom() / 100); // Account for device zoom level - - dbMetadata.getScreenshot().setScreenshotBytes(imageContent); - dbMetadata.getScreenshot().setScaleFactor(scalePercent); - dbMetadata.getScreenshot().setBorderWidth(margin); - dbMetadata.getScreenshot().setBounds(bounds); - } catch (IOException err) { - logger.error(DBGui.class, "Failed to close DataOutputStream", err); - } - } catch (IOException err) { - logger.error(DBGui.class, "Failed to close ByteArrayOutputStream", err); - } - - setProgressBarLabel(oldLabel); - - return imageContent; - } - - /** - * Refreshes the display - */ - public static void refreshDisplay() { - while ( DBGui.display.readAndDispatch() ) { - // nothing to do - } - } - - public static void incrementText(Text txt) { - if ( txt != null ) { - try { - txt.setText(toString(toInt(txt.getText())+1)); - } catch (@SuppressWarnings("unused") Exception ign) { - // ignore - } - } - } - - public static void decrementText(Text txt) { - if ( txt != null ) { - try { - txt.setText(toString(toInt(txt.getText())-1)); - } catch (@SuppressWarnings("unused") Exception ign) { - // ignore - } - } - } - - public static String toString(int value) { - if ( (value == 0) && !DBPlugin.INSTANCE.getPreferenceStore().getBoolean("showZeroValues") ) - return ""; - return String.valueOf(value); - } - - public static int toInt(String value) { - if ( DBPlugin.isEmpty(value) ) - return 0; - return Integer.valueOf(value); - } - - protected DBDatabaseConnection getDatabaseConnection() { - return this.connection; - } + */ + } + + if ( memoryObject instanceof IDiagramModelArchimateObject ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Type", String.valueOf(((IDiagramModelArchimateObject)memoryObject).getType()), databaseObject.get("type")==null ? null : String.valueOf((int)databaseObject.get("type"))); + + if ( memoryObject instanceof IDiagramModelImageProvider ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Image path", ((IDiagramModelImageProvider)memoryObject).getImagePath(), (String)databaseObject.get("image_path")); + + if ( memoryObject instanceof IDiagramModelObject ) { + areIdentical &= addItemToCompareTable(tree, treeItem, "Fill color", ((IDiagramModelObject)memoryObject).getFillColor(), (String)databaseObject.get("fill_color")); + IBounds bounds = ((IDiagramModelObject)memoryObject).getBounds(); + areIdentical &= addItemToCompareTable(tree, treeItem, "X", String.valueOf(bounds.getX()), databaseObject.get("x") == null ? null : String.valueOf((int)databaseObject.get("x"))); + areIdentical &= addItemToCompareTable(tree, treeItem, "Y", String.valueOf(bounds.getY()), databaseObject.get("y")==null ? null : String.valueOf((int)databaseObject.get("y"))); + areIdentical &= addItemToCompareTable(tree, treeItem, "Width" ,String.valueOf(bounds.getWidth()), databaseObject.get("width")==null ? null : String.valueOf((int)databaseObject.get("width"))); + areIdentical &= addItemToCompareTable(tree, treeItem, "Height", String.valueOf(bounds.getHeight()), databaseObject.get("height")==null ? null : String.valueOf((int)databaseObject.get("height"))); + } + + if ( memoryObject instanceof IDiagramModelArchimateComponent ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Archimate concept", ((IDiagramModelArchimateComponent)memoryObject).getArchimateConcept().getId(), (String)databaseObject.get("element_id")); + + if ( memoryObject instanceof IDiagramModelArchimateConnection ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Archimate concept", ((IDiagramModelArchimateConnection)memoryObject).getArchimateConcept().getId(), (String)databaseObject.get("element_id")); + + if ( memoryObject instanceof IFontAttribute ) { + areIdentical &= addItemToCompareTable(tree, treeItem, "Font", ((IFontAttribute)memoryObject).getFont(), (String)databaseObject.get("font")); + areIdentical &= addItemToCompareTable(tree, treeItem, "Font color", ((IFontAttribute)memoryObject).getFontColor(), (String)databaseObject.get("font_color")); + } + + if ( memoryObject instanceof ILineObject ) { + areIdentical &= addItemToCompareTable(tree, treeItem, "Line width", String.valueOf(((ILineObject)memoryObject).getLineWidth()), databaseObject.get("line_width")==null ? null : String.valueOf((int)databaseObject.get("line_width"))); + areIdentical &= addItemToCompareTable(tree, treeItem, "Line color", ((ILineObject)memoryObject).getLineColor(), (String)databaseObject.get("line_color")); + } + + if ( memoryObject instanceof ILockable ) { + // the database can contain a boolean, a char (oracle) or an integer (sqlite, mysql, mssql, postgres) depending on the database brand + String isLockedInDatabase = null; + if ( databaseObject.get("is_locked") != null ) { + if ( databaseObject.get("is_locked") instanceof Boolean ) + isLockedInDatabase = String.valueOf((boolean)databaseObject.get("is_locked")); + + if ( databaseObject.get("is_locked") instanceof Integer ) + isLockedInDatabase = ((int)databaseObject.get("is_locked") == 0) ? "false" : "true"; + + if ( databaseObject.get("is_locked") instanceof String ) + isLockedInDatabase = (Integer.valueOf((String)databaseObject.get("is_locked")) == 0) ? "false" : "true"; + } + areIdentical &= addItemToCompareTable(tree, treeItem, "Locked", String.valueOf(((ILockable)memoryObject).isLocked()), isLockedInDatabase); + } + + if ( memoryObject instanceof ISketchModel ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Background", String.valueOf(((ISketchModel)memoryObject).getBackground()), databaseObject.get("background")==null ? null : String.valueOf((int)databaseObject.get("background"))); + + if ( memoryObject instanceof ITextAlignment ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Text alignment", String.valueOf(((ITextAlignment)memoryObject).getTextAlignment()), databaseObject.get("text_alignment")==null ? null : String.valueOf((int)databaseObject.get("text_alignment"))); + + if ( memoryObject instanceof ITextPosition ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Text position", String.valueOf(((ITextPosition)memoryObject).getTextPosition()), databaseObject.get("text_position")==null ? null : String.valueOf((int)databaseObject.get("text_position"))); + + if ( memoryObject instanceof ITextContent ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Content", ((ITextContent)memoryObject).getContent(), (String)databaseObject.get("content")); + + if ( dbMetadata.getImagePosition() != null ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Image position", String.valueOf(dbMetadata.getImagePosition()), databaseObject.get("image_position")==null ? null : String.valueOf((int)databaseObject.get("image_position"))); + + if ( memoryObject instanceof INotesContent ) + areIdentical &= addItemToCompareTable(tree, treeItem, "Notes", ((INotesContent)memoryObject).getNotes(), (String)databaseObject.get("notes")); + + if ( memoryObject instanceof IDiagramModelConnection ) { + areIdentical &= addItemToCompareTable(tree, treeItem, "Type", String.valueOf(((IDiagramModelConnection)memoryObject).getType()), databaseObject.get("type")==null ? null : String.valueOf((int)databaseObject.get("type"))); // we do not use getText as it is deprecated + areIdentical &= addItemToCompareTable(tree, treeItem, "Text position", String.valueOf(((IDiagramModelConnection)memoryObject).getTextPosition()), databaseObject.get("text_position")==null ? null : String.valueOf((int)databaseObject.get("text_position"))); + + // we show up the bendpoints only if they both exist + if ( databaseObject.containsKey("bendpoints") ) { + if ( (((IDiagramModelConnection)memoryObject).getBendpoints().size() != 0) || (((ArrayList)databaseObject.get("bendpoints")).size() != 0) ) { + TreeItem bendpointsTreeItem; + if ( treeItem == null ) + bendpointsTreeItem = new TreeItem(tree, SWT.NONE); + else + bendpointsTreeItem = new TreeItem(treeItem, SWT.NONE); + bendpointsTreeItem.setText("Bendpoints"); + bendpointsTreeItem.setExpanded(false); + + // we get a list of component's bendpoints + Integer[][] componentBendpoints = new Integer[((IDiagramModelConnection)memoryObject).getBendpoints().size()][4]; + for (int i = 0; i < ((IDiagramModelConnection)memoryObject).getBendpoints().size(); ++i) { + componentBendpoints[i] = new Integer[] { ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getStartX(), ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getStartY(), ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getEndX(), ((IDiagramModelConnection)memoryObject).getBendpoints().get(i).getEndY() }; + } + //Arrays.sort(componentBendpoints, this.integerComparator);www + + // we get a list of properties from the database + Integer[][] databaseBendpoints = new Integer[((ArrayList)databaseObject.get("bendpoints")).size()][4]; + int i = 0; + for (DBBendpoint bp: (ArrayList)databaseObject.get("bendpoints") ) { + componentBendpoints[i] = new Integer[] { bp.getStartX(), bp.getStartY(), bp.getEndX(), bp.getEndY() }; + ++i; + } + //Arrays.sort(databaseBendpoints, this.integerComparator); + + int indexComponent = 0; + int indexDatabase = 0; + while ( (indexComponent < componentBendpoints.length) || (indexDatabase < databaseBendpoints.length) ) { + TreeItem subTreeItem = new TreeItem(bendpointsTreeItem, SWT.NONE); + subTreeItem.setText("Bendpoint "+Math.max(indexComponent, indexDatabase)+1); + subTreeItem.setExpanded(false); + if ( indexComponent >= componentBendpoints.length ) { // only the database has got the property + areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start X", null, String.valueOf(databaseBendpoints[indexDatabase][0])); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start Y", null, String.valueOf(databaseBendpoints[indexDatabase][1])); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "End X", null, String.valueOf(databaseBendpoints[indexDatabase][2])); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "End Y", null, String.valueOf(databaseBendpoints[indexDatabase][3])); + ++indexDatabase; + } else if ( indexDatabase >= databaseBendpoints.length ) { // only the component has got the property + areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start X", String.valueOf(componentBendpoints[indexComponent][0]), null); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start Y", String.valueOf(componentBendpoints[indexComponent][1]), null); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "End X", String.valueOf(componentBendpoints[indexComponent][2]), null); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "End Y", String.valueOf(componentBendpoints[indexComponent][3]), null); + ++indexComponent; + } else { + areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start X", String.valueOf(componentBendpoints[indexComponent][0]), String.valueOf(databaseBendpoints[indexDatabase][0])); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "Start Y", String.valueOf(componentBendpoints[indexComponent][1]), String.valueOf(databaseBendpoints[indexDatabase][1])); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "End X", String.valueOf(componentBendpoints[indexComponent][2]), String.valueOf(databaseBendpoints[indexDatabase][2])); + areIdentical &= addItemToCompareTable(tree, subTreeItem, "End Y", String.valueOf(componentBendpoints[indexComponent][3]), String.valueOf(databaseBendpoints[indexDatabase][3])); + ++indexComponent; + ++indexDatabase; + } + } + } + } + } + + // we show up the properties if both exist + if ( databaseObject.containsKey("properties") ) { + if ( memoryObject instanceof IProperties && ((IProperties)memoryObject).getProperties().size() != 0) { + TreeItem propertiesTreeItem; + if ( treeItem == null ) + propertiesTreeItem = new TreeItem(tree, SWT.NONE); + else + propertiesTreeItem = new TreeItem(treeItem, SWT.NONE); + propertiesTreeItem.setText("Properties"); + propertiesTreeItem.setExpanded(true); + + // we get a sorted list of component's properties + ArrayList componentProperties = new ArrayList(); + for (int i = 0; i < ((IProperties)memoryObject).getProperties().size(); ++i) { + componentProperties.add(new DBProperty(((IProperties)memoryObject).getProperties().get(i).getKey(), ((IProperties)memoryObject).getProperties().get(i).getValue())); + } + Collections.sort(componentProperties, this.propertyComparator); + + // we get a sorted list of properties from the database + ArrayList databaseProperties = (ArrayList)databaseObject.get("properties"); + Collections.sort(databaseProperties, this.propertyComparator); + + Collator collator = Collator.getInstance(); + int indexComponent = 0; + int indexDatabase = 0; + int compare; + while ( (indexComponent < componentProperties.size()) || (indexDatabase < databaseProperties.size()) ) { + if ( indexComponent >= componentProperties.size() ) + compare = 1; + else { + if ( indexDatabase >= databaseProperties.size() ) + compare = -1; + else + compare = collator.compare(componentProperties.get(indexComponent).getKey(), databaseProperties.get(indexDatabase).getKey()); + } + + if ( compare == 0 ) { // both have got the same property + areIdentical &= addItemToCompareTable(tree, propertiesTreeItem, componentProperties.get(indexComponent).getKey(), componentProperties.get(indexComponent).getValue(), databaseProperties.get(indexDatabase).getValue()); + ++indexComponent; + ++indexDatabase; + } else if ( compare < 0 ) { // only the component has got the property + areIdentical &= addItemToCompareTable(tree, propertiesTreeItem, componentProperties.get(indexComponent).getKey(), componentProperties.get(indexComponent).getValue(), null); + ++indexComponent; + } else { // only the database has got the property + areIdentical &= addItemToCompareTable(tree, propertiesTreeItem, componentProperties.get(indexDatabase).getKey(), null, databaseProperties.get(indexDatabase).getValue()); + ++indexDatabase; + } + } + } + } + + refreshDisplay(); + return areIdentical; + } + + Comparator propertyComparator = new Comparator() { + @Override + public int compare(final DBProperty row1, final DBProperty row2) { + return Collator.getInstance().compare(row1.getKey(),row2.getKey()); + } + }; + + Comparator integerComparator = new Comparator() { + @Override + public int compare(final Integer[] row1, final Integer[] row2) { + return Collator.getInstance().compare(row1[0],row2[0]); + } + }; + + + /** + * Helper function to fill in the compareTable + * @return true if col2 and col3 are equals, false if they differ + */ + private static boolean addItemToCompareTable(Tree tree, TreeItem treeItem, String col1, String col2, String col3) { + TreeItem subTreeItem; + boolean isIdentical; + + if ( treeItem != null ) + subTreeItem = new TreeItem(treeItem, SWT.NULL); + else + subTreeItem = new TreeItem(tree, SWT.NONE); + + subTreeItem.setText(new String[] {col1, col2, col3 }); + if ( !DBPlugin.areEqual(col2, col3) ) { + if ( treeItem != null ) + treeItem.setBackground(DBGui.LIGHT_RED_COLOR); + subTreeItem.setBackground(DBGui.LIGHT_RED_COLOR); + isIdentical = false; + } else + isIdentical = true; + + refreshDisplay(); + return isIdentical; + } + + public static byte[] createImage(IDiagramModel view, int scalePercent, int margin) { + byte[] imageContent = null; + DBMetadata dbMetadata = DBMetadata.getDBMetadata(view); + + logger.debug("Creating screenshot of view \""+view.getName()+"\""); + + try ( ByteArrayOutputStream out = new ByteArrayOutputStream() ) { + try ( DataOutputStream writeOut = new DataOutputStream(out) ) { + ImageLoader saver = new ImageLoader(); + ModelReferencedImage viewImage = DiagramUtils.createModelReferencedImage(view, scalePercent/100.0, margin); + Image image = viewImage.getImage(); + + saver.data = new ImageData[] { image.getImageData(ImageFactory.getDeviceZoom()) }; + image.dispose(); + + saver.save(writeOut, SWT.IMAGE_PNG); + imageContent = out.toByteArray(); + + org.eclipse.draw2d.geometry.Rectangle bounds = viewImage.getBounds(); + bounds.performScale(ImageFactory.getDeviceZoom() / 100); // Account for device zoom level + + dbMetadata.getScreenshot().setScreenshotBytes(imageContent); + dbMetadata.getScreenshot().setScaleFactor(scalePercent); + dbMetadata.getScreenshot().setBorderWidth(margin); + dbMetadata.getScreenshot().setBounds(bounds); + } catch (IOException err) { + logger.error("Failed to close DataOutputStream", err); + } + } catch (IOException err) { + logger.error("Failed to close ByteArrayOutputStream", err); + } + + return imageContent; + } + + /** + * Refreshes the display + */ + public static void refreshDisplay() { + while ( DBGui.display.readAndDispatch() ) { + // nothing to do + } + } + + public static void incrementText(Text txt) { + if ( txt != null ) { + try { + txt.setText(toString(toInt(txt.getText())+1)); + } catch (@SuppressWarnings("unused") Exception ign) { + // ignore + } + } + } + + public static void decrementText(Text txt) { + if ( txt != null ) { + try { + txt.setText(toString(toInt(txt.getText())-1)); + } catch (@SuppressWarnings("unused") Exception ign) { + // ignore + } + } + } + + public static String toString(int value) { + if ( (value == 0) && !DBPlugin.INSTANCE.getPreferenceStore().getBoolean("showZeroValues") ) + return ""; + return String.valueOf(value); + } + + public static int toInt(String value) { + if ( DBPlugin.isEmpty(value) ) + return 0; + return Integer.valueOf(value); + } + + protected DBDatabaseConnection getDatabaseConnection() { + return this.connection; + } } \ No newline at end of file diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiAdminDatabase.java b/sources/src/org/archicontribs/database/GUI/DBGuiAdminDatabase.java index e38c274b..c25c165e 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiAdminDatabase.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiAdminDatabase.java @@ -191,7 +191,7 @@ public void modifyText(ModifyEvent e) { tableItem.setData("id", model.get("id")); } } catch (Exception err) { - DBGui.popup(Level.ERROR, "Failed to get the list of models in the database.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get the list of models in the database.", err); } } }); @@ -231,7 +231,7 @@ public void handleEvent(Event e) { tableItem.setData("purpose", version.get("purpose")); } } catch (Exception err) { - DBGui.popup(Level.ERROR, "Failed to get model's versions from the database", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get model's versions from the database", err); } if ( DBGuiAdminDatabase.this.tblModelVersions.getItemCount() != 0 ) { @@ -450,7 +450,7 @@ void checkContentCallback() { // we start a new transaction this.importConnection.setAutoCommit(false); } catch (SQLException err) { - DBGui.popup(Level.ERROR, "Failed to start a new transaction.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to start a new transaction.", err); return; } @@ -475,12 +475,12 @@ void checkContentCallback() { this.importConnection.rollback(); this.importConnection.setAutoCommit(true); } catch (SQLException err2) { - DBGui.popup(Level.ERROR, "Failed to remove view_objects_in_views duplicates.", err); - DBGui.popup(Level.FATAL, "Failed to roll back the transaction. We suggest you close Archi and verify your database manually.", err2); + DBGuiUtils.popup(Level.ERROR, "Failed to remove view_objects_in_views duplicates.", err); + DBGuiUtils.popup(Level.FATAL, "Failed to roll back the transaction. We suggest you close Archi and verify your database manually.", err2); return; } - DBGui.popup(Level.ERROR, "Failed to remove view_objects_in_views duplicates. The transaction has been rolled back.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to remove view_objects_in_views duplicates. The transaction has been rolled back.", err); return; } @@ -502,12 +502,12 @@ void checkContentCallback() { this.importConnection.rollback(); this.importConnection.setAutoCommit(true); } catch (SQLException err2) { - DBGui.popup(Level.ERROR, "Failed to remove view_connections_in_views duplicates.", err); - DBGui.popup(Level.FATAL, "Failed to roll back the transaction. We suggest you close Archi and verify your database manually.", err2); + DBGuiUtils.popup(Level.ERROR, "Failed to remove view_connections_in_views duplicates.", err); + DBGuiUtils.popup(Level.FATAL, "Failed to roll back the transaction. We suggest you close Archi and verify your database manually.", err2); return; } - DBGui.popup(Level.ERROR, "Failed to remove view_connections_in_views duplicates. The transaction has been rolled back.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to remove view_connections_in_views duplicates. The transaction has been rolled back.", err); return; } @@ -515,11 +515,11 @@ void checkContentCallback() { this.importConnection.commit(); this.importConnection.setAutoCommit(true); } catch (SQLException err) { - DBGui.popup(Level.FATAL, "Failed to commit the transaction. We suggest you close Archi and verify your database manually.", err); + DBGuiUtils.popup(Level.FATAL, "Failed to commit the transaction. We suggest you close Archi and verify your database manually.", err); return; } - DBGui.popup(Level.INFO, duplicateObjectsStatus+"\n"+duplicateConnectionsStatus+"\n\nDatabase content successfully checked."); + DBGuiUtils.popup(Level.INFO, duplicateObjectsStatus+"\n"+duplicateConnectionsStatus+"\n\nDatabase content successfully checked."); } /** @@ -530,34 +530,34 @@ void deleteModelCallback() { String modelName = DBGuiAdminDatabase.this.tblModels.getSelection()[0].getText(); if ( modelId == null ) { - DBGui.popup(Level.ERROR, "Failed to get model ID."); + DBGuiUtils.popup(Level.ERROR, "Failed to get model ID."); return; } - if (DBGui.question("You are about to delete the model \""+modelName+"\" from the database.\n\nThis will delete the model as a container. However, the model content (elements, relationships, views, ...) will remain in the database so they can be imported from the database into other models.\n\nPlease note that this action cannot be undone.\n\nDo you confirm the deletion ?") ) { + if (DBGuiUtils.question("You are about to delete the model \""+modelName+"\" from the database.\n\nThis will delete the model as a container. However, the model content (elements, relationships, views, ...) will remain in the database so they can be imported from the database into other models.\n\nPlease note that this action cannot be undone.\n\nDo you confirm the deletion ?") ) { try { int deletedRows = this.importConnection.executeRequest("DELETE FROM "+this.importConnection.getDatabaseEntry().getSchemaPrefix()+"models WHERE id = ?", modelId); if (deletedRows == 0) - DBGui.popup(Level.WARN,"That's weird, no model with ID \""+modelId+"\" has been found in the database."); + DBGuiUtils.popup(Level.WARN,"That's weird, no model with ID \""+modelId+"\" has been found in the database."); else { connectedToDatabase(false); - DBGui.popup(Level.INFO, String.valueOf(deletedRows)+" version"+((deletedRows == 1)?"":"s")+" of the model \""+modelName+"\" "+((deletedRows == 1)?"has":"have")+" been deleted from the database."); + DBGuiUtils.popup(Level.INFO, String.valueOf(deletedRows)+" version"+((deletedRows == 1)?"":"s")+" of the model \""+modelName+"\" "+((deletedRows == 1)?"has":"have")+" been deleted from the database."); } } catch (SQLException err) { try { this.importConnection.rollback(); this.importConnection.setAutoCommit(true); } catch (SQLException err2) { - DBGui.popup(Level.ERROR, "Failed to delete model from the database.", err); - DBGui.popup(Level.FATAL, "Failed to roll back the transaction. We suggest you close Archi and verify your database manually.", err2); + DBGuiUtils.popup(Level.ERROR, "Failed to delete model from the database.", err); + DBGuiUtils.popup(Level.FATAL, "Failed to roll back the transaction. We suggest you close Archi and verify your database manually.", err2); return; } - DBGui.popup(Level.ERROR, "Failed to delete model from the database. The transaction has been rolled back.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to delete model from the database. The transaction has been rolled back.", err); } } else - DBGui.popup(Level.INFO, "Delete canceled by user."); + DBGuiUtils.popup(Level.INFO, "Delete canceled by user."); } ///** @@ -565,6 +565,6 @@ void deleteModelCallback() { // */ //@SuppressWarnings("static-method") //void deleteVersionCallback() { - // DBGui.popup(Level.INFO, "Not yet implemented."); + // DBGuiUtils.popup(Level.INFO, "Not yet implemented."); //} } diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java b/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java index d86d975c..75e9f5aa 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiComponentHistory.java @@ -227,12 +227,12 @@ else if ( importedComponent instanceof IArchimateDiagramModel || importedCompone throw command.getException(); ((CommandStack)importedModel.getAdapter(CommandStack.class)).execute((Command) command); - popup(Level.INFO, "The current version of the component has been replaced by the selected version from the database."); + DBGuiUtils.popup(Level.INFO, "The current version of the component has been replaced by the selected version from the database."); connectedToDatabase(true); } catch (Exception err) { - popup(Level.ERROR, "Failed to import component.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to import component.", err); } } @Override @@ -254,10 +254,10 @@ public void widgetSelected(SelectionEvent e) { ((DBArchimateModel)DBGuiComponentHistory.this.selectedComponent.getArchimateModel()).getCurrentVersion().setTimestamp(new Timestamp(Calendar.getInstance().getTime().getTime())); exportConnection.exportEObject(DBGuiComponentHistory.this.selectedComponent); - popup(Level.INFO, "The component has been updated in the database."); + DBGuiUtils.popup(Level.INFO, "The component has been updated in the database."); connectedToDatabase(true); } catch (Exception err) { - popup(Level.ERROR, "Failed to export component.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to export component.", err); } } @Override @@ -274,12 +274,12 @@ public void widgetSelected(SelectionEvent e) { */ @Override protected void connectedToDatabase(boolean forceCheck) { - this.dialog.setCursor(CURSOR_ARROW); + this.dialog.setCursor(DBGuiUtils.CURSOR_ARROW); try (DBDatabaseExportConnection exportConnection = new DBDatabaseExportConnection(getDatabaseConnection()) ) { exportConnection.getVersionFromDatabase(this.selectedComponent); } catch (Exception e) { - popup(Level.FATAL, "Cannot get version of selected component from the database.", e); + DBGuiUtils.popup(Level.FATAL, "Cannot get version of selected component from the database.", e); return ; } @@ -305,7 +305,7 @@ else if ( this.selectedComponent instanceof IDiagramModelObject ) else if ( this.selectedComponent instanceof IDiagramModelConnection ) tableName = "views_connections"; else { - popup(Level.FATAL, "Cannot get history for components of class "+this.selectedComponent.getClass().getSimpleName()); + DBGuiUtils.popup(Level.FATAL, "Cannot get history for components of class "+this.selectedComponent.getClass().getSimpleName()); return ; } @@ -318,7 +318,7 @@ else if ( this.selectedComponent instanceof IDiagramModelConnection ) } } catch (Exception err) { this.tblVersions.removeAll(); - popup(Level.FATAL, "Failed to search component versions in the database.", err); + DBGuiUtils.popup(Level.FATAL, "Failed to search component versions in the database.", err); } if ( this.tblVersions.getItemCount() > 1 ) { diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java b/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java index adaa1678..987c4bb2 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiExportModel.java @@ -30,8 +30,10 @@ import org.archicontribs.database.model.DBMetadata.DATABASE_STATUS; import org.archicontribs.database.model.commands.DBDeleteDiagramConnectionCommand; import org.archicontribs.database.model.commands.DBDeleteDiagramObjectCommand; +import org.archicontribs.database.model.commands.DBDeleteProfileCommand; import org.archicontribs.database.model.commands.DBImportElementFromIdCommand; import org.archicontribs.database.model.commands.DBImportFolderFromIdCommand; +import org.archicontribs.database.model.commands.DBImportProfileFromIdCommand; import org.archicontribs.database.model.commands.DBImportRelationshipFromIdCommand; import org.archicontribs.database.model.commands.DBImportViewConnectionFromIdCommand; import org.archicontribs.database.model.commands.DBImportViewFromIdCommand; @@ -150,13 +152,13 @@ public void run() { try { this.exportedModel.countAllObjects(); } catch (Exception err) { - popup(Level.ERROR, "Failed to count model's components", err); + DBGuiUtils.popup(Level.ERROR, "Failed to count model's components", err); return; } finally { closeMessage(); } - if ( logger.isDebugEnabled() ) logger.debug("The model has got "+this.exportedModel.getAllElements().size()+" elements and "+this.exportedModel.getAllRelationships().size()+" relationships and "+this.exportedModel.getAllFolders().size()+" folders and "+this.exportedModel.getAllViews().size()+" views and "+this.exportedModel.getAllViewObjects().size()+" objects and "+this.exportedModel.getAllViewConnections().size()+" connections."); + if ( logger.isDebugEnabled() ) logger.debug("The model has got "+this.exportedModel.getAllProfiles().size()+" specializations and "+this.exportedModel.getAllElements().size()+" elements and "+this.exportedModel.getAllRelationships().size()+" relationships and "+this.exportedModel.getAllFolders().size()+" folders and "+this.exportedModel.getAllViews().size()+" views and "+this.exportedModel.getAllViewObjects().size()+" objects and "+this.exportedModel.getAllViewConnections().size()+" connections."); this.txtTotalProfiles.setText(toString(this.exportedModel.getProfiles().size())); this.txtTotalElements.setText(toString(this.exportedModel.getAllElements().size())); @@ -170,7 +172,7 @@ public void run() { try { getDatabases(true, this.exportedModel.getImportDatabaseId(), null); } catch (Exception err) { - popup(Level.ERROR, "Failed to get the databases.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get the databases.", err); return; } } @@ -517,6 +519,7 @@ private void createGrpComponents() { this.txtTotalProfiles = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalProfiles.setEditable(false); + this.txtTotalProfiles.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -525,6 +528,7 @@ private void createGrpComponents() { this.txtNewProfilesInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewProfilesInModel.setEditable(false); + this.txtNewProfilesInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -533,6 +537,7 @@ private void createGrpComponents() { this.txtUpdatedProfilesInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedProfilesInModel.setEditable(false); + this.txtUpdatedProfilesInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelUpdated, 0, SWT.LEFT); @@ -541,6 +546,7 @@ private void createGrpComponents() { this.txtDeletedProfilesInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedProfilesInModel.setEditable(false); + this.txtDeletedProfilesInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelDeleted, 0, SWT.LEFT); @@ -549,6 +555,7 @@ private void createGrpComponents() { this.txtNewProfilesInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewProfilesInDatabase.setEditable(false); + this.txtNewProfilesInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -557,6 +564,7 @@ private void createGrpComponents() { this.txtUpdatedProfilesInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedProfilesInDatabase.setEditable(false); + this.txtUpdatedProfilesInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseUpdated, 0, SWT.LEFT); @@ -565,6 +573,7 @@ private void createGrpComponents() { this.txtDeletedProfilesInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedProfilesInDatabase.setEditable(false); + this.txtDeletedProfilesInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseDeleted, 0, SWT.LEFT); @@ -573,6 +582,7 @@ private void createGrpComponents() { this.txtConflictingProfiles = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtConflictingProfiles.setEditable(false); + this.txtConflictingProfiles.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblConflicts, 0, SWT.LEFT); @@ -583,6 +593,7 @@ private void createGrpComponents() { this.txtTotalElements = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalElements.setEditable(false); + this.txtTotalElements.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -591,6 +602,7 @@ private void createGrpComponents() { this.txtNewElementsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewElementsInModel.setEditable(false); + this.txtNewElementsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -599,6 +611,7 @@ private void createGrpComponents() { this.txtUpdatedElementsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedElementsInModel.setEditable(false); + this.txtUpdatedElementsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelUpdated, 0, SWT.LEFT); @@ -607,6 +620,7 @@ private void createGrpComponents() { this.txtDeletedElementsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedElementsInModel.setEditable(false); + this.txtDeletedElementsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelDeleted, 0, SWT.LEFT); @@ -615,6 +629,7 @@ private void createGrpComponents() { this.txtNewElementsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewElementsInDatabase.setEditable(false); + this.txtNewElementsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -623,6 +638,7 @@ private void createGrpComponents() { this.txtUpdatedElementsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedElementsInDatabase.setEditable(false); + this.txtUpdatedElementsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseUpdated, 0, SWT.LEFT); @@ -631,6 +647,7 @@ private void createGrpComponents() { this.txtDeletedElementsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedElementsInDatabase.setEditable(false); + this.txtDeletedElementsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseDeleted, 0, SWT.LEFT); @@ -639,6 +656,7 @@ private void createGrpComponents() { this.txtConflictingElements = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtConflictingElements.setEditable(false); + this.txtConflictingElements.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblConflicts, 0, SWT.LEFT); @@ -649,6 +667,7 @@ private void createGrpComponents() { this.txtTotalRelationships = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalRelationships.setEditable(false); + this.txtTotalRelationships.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -657,6 +676,7 @@ private void createGrpComponents() { this.txtNewRelationshipsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewRelationshipsInModel.setEditable(false); + this.txtNewRelationshipsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -665,6 +685,7 @@ private void createGrpComponents() { this.txtUpdatedRelationshipsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedRelationshipsInModel.setEditable(false); + this.txtUpdatedRelationshipsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelUpdated, 0, SWT.LEFT); @@ -673,6 +694,7 @@ private void createGrpComponents() { this.txtDeletedRelationshipsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedRelationshipsInModel.setEditable(false); + this.txtDeletedRelationshipsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelDeleted, 0, SWT.LEFT); @@ -681,6 +703,7 @@ private void createGrpComponents() { this.txtNewRelationshipsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewRelationshipsInDatabase.setEditable(false); + this.txtNewRelationshipsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -689,6 +712,7 @@ private void createGrpComponents() { this.txtUpdatedRelationshipsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedRelationshipsInDatabase.setEditable(false); + this.txtUpdatedRelationshipsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseUpdated, 0, SWT.LEFT); @@ -697,6 +721,7 @@ private void createGrpComponents() { this.txtDeletedRelationshipsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedRelationshipsInDatabase.setEditable(false); + this.txtDeletedRelationshipsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseDeleted, 0, SWT.LEFT); @@ -705,6 +730,7 @@ private void createGrpComponents() { this.txtConflictingRelationships = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtConflictingRelationships.setEditable(false); + this.txtConflictingRelationships.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblConflicts, 0, SWT.LEFT); @@ -715,6 +741,7 @@ private void createGrpComponents() { this.txtTotalFolders = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalFolders.setEditable(false); + this.txtTotalFolders.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -723,6 +750,7 @@ private void createGrpComponents() { this.txtNewFoldersInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewFoldersInModel.setEditable(false); + this.txtNewFoldersInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -731,6 +759,7 @@ private void createGrpComponents() { this.txtUpdatedFoldersInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedFoldersInModel.setEditable(false); + this.txtUpdatedFoldersInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelUpdated, 0, SWT.LEFT); @@ -739,6 +768,7 @@ private void createGrpComponents() { this.txtDeletedFoldersInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedFoldersInModel.setEditable(false); + this.txtDeletedFoldersInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelDeleted, 0, SWT.LEFT); @@ -747,6 +777,7 @@ private void createGrpComponents() { this.txtNewFoldersInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewFoldersInDatabase.setEditable(false); + this.txtNewFoldersInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -755,6 +786,7 @@ private void createGrpComponents() { this.txtUpdatedFoldersInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedFoldersInDatabase.setEditable(false); + this.txtUpdatedFoldersInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseUpdated, 0, SWT.LEFT); @@ -763,6 +795,7 @@ private void createGrpComponents() { this.txtDeletedFoldersInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedFoldersInDatabase.setEditable(false); + this.txtDeletedFoldersInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseDeleted, 0, SWT.LEFT); @@ -771,6 +804,7 @@ private void createGrpComponents() { this.txtConflictingFolders = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtConflictingFolders.setEditable(false); + this.txtConflictingFolders.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblConflicts, 0, SWT.LEFT); @@ -781,6 +815,7 @@ private void createGrpComponents() { this.txtTotalViews = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalViews.setEditable(false); + this.txtTotalViews.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -789,6 +824,7 @@ private void createGrpComponents() { this.txtNewViewsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewViewsInModel.setEditable(false); + this.txtNewViewsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -797,6 +833,7 @@ private void createGrpComponents() { this.txtUpdatedViewsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedViewsInModel.setEditable(false); + this.txtUpdatedViewsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelUpdated, 0, SWT.LEFT); @@ -805,6 +842,7 @@ private void createGrpComponents() { this.txtDeletedViewsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedViewsInModel.setEditable(false); + this.txtDeletedViewsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelDeleted, 0, SWT.LEFT); @@ -813,6 +851,7 @@ private void createGrpComponents() { this.txtNewViewsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewViewsInDatabase.setEditable(false); + this.txtNewViewsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -821,6 +860,7 @@ private void createGrpComponents() { this.txtUpdatedViewsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedViewsInDatabase.setEditable(false); + this.txtUpdatedViewsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseUpdated, 0, SWT.LEFT); @@ -829,6 +869,7 @@ private void createGrpComponents() { this.txtDeletedViewsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedViewsInDatabase.setEditable(false); + this.txtDeletedViewsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseDeleted, 0, SWT.LEFT); @@ -837,6 +878,7 @@ private void createGrpComponents() { this.txtConflictingViews = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtConflictingViews.setEditable(false); + this.txtConflictingViews.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblConflicts, 0, SWT.LEFT); @@ -847,6 +889,7 @@ private void createGrpComponents() { this.txtTotalViewObjects = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalViewObjects.setEditable(false); + this.txtTotalViewObjects.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -855,6 +898,7 @@ private void createGrpComponents() { this.txtNewViewObjectsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewViewObjectsInModel.setEditable(false); + this.txtNewViewObjectsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -863,6 +907,7 @@ private void createGrpComponents() { this.txtUpdatedViewObjectsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedViewObjectsInModel.setEditable(false); + this.txtUpdatedViewObjectsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelUpdated, 0, SWT.LEFT); @@ -871,6 +916,7 @@ private void createGrpComponents() { this.txtDeletedViewObjectsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedViewObjectsInModel.setEditable(false); + this.txtDeletedViewObjectsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelDeleted, 0, SWT.LEFT); @@ -879,6 +925,7 @@ private void createGrpComponents() { this.txtNewViewObjectsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewViewObjectsInDatabase.setEditable(false); + this.txtNewViewObjectsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -887,6 +934,7 @@ private void createGrpComponents() { this.txtUpdatedViewObjectsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedViewObjectsInDatabase.setEditable(false); + this.txtUpdatedViewObjectsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseUpdated, 0, SWT.LEFT); @@ -895,6 +943,7 @@ private void createGrpComponents() { this.txtDeletedViewObjectsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedViewObjectsInDatabase.setEditable(false); + this.txtDeletedViewObjectsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseDeleted, 0, SWT.LEFT); @@ -903,6 +952,7 @@ private void createGrpComponents() { this.txtConflictingViewObjects = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtConflictingViewObjects.setEditable(false); + this.txtConflictingViewObjects.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblConflicts, 0, SWT.LEFT); @@ -913,6 +963,7 @@ private void createGrpComponents() { this.txtTotalViewConnections = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalViewConnections.setEditable(false); + this.txtTotalViewConnections.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -921,6 +972,7 @@ private void createGrpComponents() { this.txtNewViewConnectionsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewViewConnectionsInModel.setEditable(false); + this.txtNewViewConnectionsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -929,6 +981,7 @@ private void createGrpComponents() { this.txtUpdatedViewConnectionsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedViewConnectionsInModel.setEditable(false); + this.txtUpdatedViewConnectionsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelUpdated, 0, SWT.LEFT); @@ -937,6 +990,7 @@ private void createGrpComponents() { this.txtDeletedViewConnectionsInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedViewConnectionsInModel.setEditable(false); + this.txtDeletedViewConnectionsInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelDeleted, 0, SWT.LEFT); @@ -945,6 +999,7 @@ private void createGrpComponents() { this.txtNewViewConnectionsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewViewConnectionsInDatabase.setEditable(false); + this.txtNewViewConnectionsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -953,6 +1008,7 @@ private void createGrpComponents() { this.txtUpdatedViewConnectionsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtUpdatedViewConnectionsInDatabase.setEditable(false); + this.txtUpdatedViewConnectionsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseUpdated, 0, SWT.LEFT); @@ -961,6 +1017,7 @@ private void createGrpComponents() { this.txtDeletedViewConnectionsInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtDeletedViewConnectionsInDatabase.setEditable(false); + this.txtDeletedViewConnectionsInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseDeleted, 0, SWT.LEFT); @@ -969,6 +1026,7 @@ private void createGrpComponents() { this.txtConflictingViewConnections = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtConflictingViewConnections.setEditable(false); + this.txtConflictingViewConnections.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblConflicts, 0, SWT.LEFT); @@ -979,6 +1037,7 @@ private void createGrpComponents() { this.txtTotalImages = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalImages.setEditable(false); + this.txtTotalImages.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblImages, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblTotal, 0, SWT.LEFT); @@ -987,6 +1046,7 @@ private void createGrpComponents() { this.txtNewImagesInModel = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewImagesInModel.setEditable(false); + this.txtNewImagesInModel.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblImages, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblModelNew, 0, SWT.LEFT); @@ -995,6 +1055,7 @@ private void createGrpComponents() { this.txtNewImagesInDatabase = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtNewImagesInDatabase.setEditable(false); + this.txtNewImagesInDatabase.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblImages, 0, SWT.CENTER); fd.left = new FormAttachment(this.lblDatabaseNew, 0, SWT.LEFT); @@ -1016,11 +1077,11 @@ private void createGrpComponents() { try { upToDate = DBGuiExportModel.this.compareModelToDatabase(true); } catch (Exception err) { - popup(Level.ERROR, "Failed to compare the model to the database.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to compare the model to the database.", err); } DBGuiExportModel.this.btnCompareModelToDatabase.setEnabled(true); if ( upToDate ) { - popup(Level.INFO, "Your database is already up to date."); + DBGuiUtils.popup(Level.INFO, "Your database is already up to date."); DBGuiExportModel.this.btnClose.setText("Close"); DBGuiExportModel.this.btnDoAction.setEnabled(false); } else @@ -1129,7 +1190,7 @@ protected void connectedToDatabase(boolean forceCheckDatabase) { } } } catch (Exception err) { - popup(Level.FATAL, "Failed to check existing components in database", err); + DBGuiUtils.popup(Level.FATAL, "Failed to check existing components in database", err); setActiveAction(STATUS.Error); return; } @@ -1152,13 +1213,13 @@ protected void connectedToDatabase(boolean forceCheckDatabase) { try { upToDate = compareModelToDatabase(true); } catch (Exception err) { - popup(Level.ERROR, "Failed to compare the model to the database.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to compare the model to the database.", err); } this.btnCompareModelToDatabase.setEnabled(true); closeMessage(); if ( upToDate ) { - popup(Level.INFO, "Your database is already up to date."); + DBGuiUtils.popup(Level.INFO, "Your database is already up to date."); DBGuiExportModel.this.btnClose.setText("Close"); this.btnDoAction.setEnabled(false); } else @@ -1269,13 +1330,13 @@ protected boolean compareModelToDatabase(boolean updateTextFields) throws Except int progressBarWidth = this.exportedModel.getAllElements().size() + this.exportedModel.getAllRelationships().size() + this.exportedModel.getAllFolders().size() + this.exportedModel.getAllViews().size() + this.exportedModel.getAllViewObjects().size() + this.exportedModel.getAllViewConnections().size(); createProgressBar("Comparing the model to the database ...", 1, progressBarWidth); - + try { // we compare the elements, relationships, folders and views this.exportConnection.getAllVersionFromDatabase(this.exportedModel, this); } catch (SQLException err ) { hideProgressBar(); - popup(Level.FATAL, "Failed to get latest version of components in the database.", err); + DBGuiUtils.popup(Level.FATAL, "Failed to get latest version of components in the database.", err); setActiveAction(STATUS.Error); doShowResult(STATUS.Error, "Error while exporting model.\n"+err.getMessage()); return false; @@ -1297,7 +1358,6 @@ protected boolean compareModelToDatabase(boolean updateTextFields) throws Except ) { setProgressBarLabel("Creating screenshot of view \""+view.getName()+"\""); createImage(view, this.exportConnection.getDatabaseEntry().getViewsImagesScaleFactor(), this.exportConnection.getDatabaseEntry().getViewsImagesBorderWidth()); - setProgressBarLabel("Checking if view screenshots are required"); } metadata.getScreenshot().setScreenshotActive(true); } else @@ -1777,21 +1837,23 @@ protected boolean compareModelToDatabase(boolean updateTextFields) throws Except // we log the values uniquely if the updateTextFields has been requestes, else the values are zero logger.info(String.format(" <------ In model ------> <----- In database ---->")); - logger.info(String.format(" Total New Updated Deleted New Updated Deleted Conflict")); - logger.info(String.format(" Elements: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllElements().size(), toInt(this.txtNewElementsInModel.getText()), toInt(this.txtUpdatedElementsInModel.getText()), toInt(this.txtDeletedElementsInModel.getText()), toInt(this.txtNewElementsInDatabase.getText()), toInt(this.txtUpdatedElementsInDatabase.getText()), toInt(this.txtDeletedElementsInDatabase.getText()), toInt(this.txtConflictingElements.getText())) ); - logger.info(String.format(" Relationships: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllRelationships().size(), toInt(this.txtNewRelationshipsInModel.getText()), toInt(this.txtUpdatedRelationshipsInModel.getText()), toInt(this.txtDeletedRelationshipsInModel.getText()), toInt(this.txtNewRelationshipsInDatabase.getText()), toInt(this.txtUpdatedRelationshipsInDatabase.getText()), toInt(this.txtDeletedRelationshipsInDatabase.getText()), toInt(this.txtConflictingRelationships.getText())) ); + logger.info(String.format(" Total New Updated Deleted New Updated Deleted Conflict")); + logger.info(String.format(" Specializations: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllProfiles().size(), toInt(this.txtNewProfilesInModel.getText()), toInt(this.txtUpdatedProfilesInModel.getText()), toInt(this.txtDeletedProfilesInModel.getText()), toInt(this.txtNewProfilesInDatabase.getText()), toInt(this.txtUpdatedProfilesInDatabase.getText()), toInt(this.txtDeletedProfilesInDatabase.getText()), toInt(this.txtConflictingProfiles.getText())) ); + logger.info(String.format(" Elements: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllElements().size(), toInt(this.txtNewElementsInModel.getText()), toInt(this.txtUpdatedElementsInModel.getText()), toInt(this.txtDeletedElementsInModel.getText()), toInt(this.txtNewElementsInDatabase.getText()), toInt(this.txtUpdatedElementsInDatabase.getText()), toInt(this.txtDeletedElementsInDatabase.getText()), toInt(this.txtConflictingElements.getText())) ); + logger.info(String.format(" Relationships: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllRelationships().size(), toInt(this.txtNewRelationshipsInModel.getText()), toInt(this.txtUpdatedRelationshipsInModel.getText()), toInt(this.txtDeletedRelationshipsInModel.getText()), toInt(this.txtNewRelationshipsInDatabase.getText()), toInt(this.txtUpdatedRelationshipsInDatabase.getText()), toInt(this.txtDeletedRelationshipsInDatabase.getText()), toInt(this.txtConflictingRelationships.getText())) ); if ( !DBPlugin.areEqual(this.selectedDatabase.getDriver().toLowerCase(), "neo4j") ) { - logger.info(String.format(" Folders: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllFolders().size(), toInt(this.txtNewFoldersInModel.getText()), toInt(this.txtUpdatedFoldersInModel.getText()), toInt(this.txtDeletedFoldersInModel.getText()), toInt(this.txtNewFoldersInDatabase.getText()), toInt(this.txtUpdatedFoldersInDatabase.getText()), toInt(this.txtDeletedFoldersInDatabase.getText()), toInt(this.txtConflictingFolders.getText())) ); - logger.info(String.format(" views: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllViews().size(), toInt(this.txtNewViewsInModel.getText()), toInt(this.txtUpdatedViewsInModel.getText()), toInt(this.txtDeletedViewsInModel.getText()), toInt(this.txtNewViewsInDatabase.getText()), toInt(this.txtUpdatedViewsInDatabase.getText()), toInt(this.txtDeletedViewsInDatabase.getText()), toInt(this.txtConflictingViews.getText())) ); - logger.info(String.format(" Objects: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllViewObjects().size(), toInt(this.txtNewViewObjectsInModel.getText()), toInt(this.txtUpdatedViewObjectsInModel.getText()), toInt(this.txtDeletedViewObjectsInModel.getText()), toInt(this.txtNewViewObjectsInDatabase.getText()), toInt(this.txtUpdatedViewObjectsInDatabase.getText()), toInt(this.txtDeletedViewObjectsInDatabase.getText()), toInt(this.txtConflictingViewObjects.getText())) ); - logger.info(String.format(" Connections: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllViewConnections().size(), toInt(this.txtNewViewConnectionsInModel.getText()), toInt(this.txtUpdatedViewConnectionsInModel.getText()), toInt(this.txtDeletedViewConnectionsInModel.getText()), toInt(this.txtNewViewConnectionsInDatabase.getText()), toInt(this.txtUpdatedViewConnectionsInDatabase.getText()), toInt(this.txtDeletedViewConnectionsInDatabase.getText()), toInt(this.txtConflictingViewConnections.getText())) ); - logger.info(String.format(" images: %6d %6d %16s %6d", ((IArchiveManager)this.exportedModel.getAdapter(IArchiveManager.class)).getLoadedImagePaths().size(), toInt(this.txtNewImagesInModel.getText()), "", toInt(this.txtNewImagesInDatabase.getText())) ); + logger.info(String.format(" Folders: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllFolders().size(), toInt(this.txtNewFoldersInModel.getText()), toInt(this.txtUpdatedFoldersInModel.getText()), toInt(this.txtDeletedFoldersInModel.getText()), toInt(this.txtNewFoldersInDatabase.getText()), toInt(this.txtUpdatedFoldersInDatabase.getText()), toInt(this.txtDeletedFoldersInDatabase.getText()), toInt(this.txtConflictingFolders.getText())) ); + logger.info(String.format(" views: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllViews().size(), toInt(this.txtNewViewsInModel.getText()), toInt(this.txtUpdatedViewsInModel.getText()), toInt(this.txtDeletedViewsInModel.getText()), toInt(this.txtNewViewsInDatabase.getText()), toInt(this.txtUpdatedViewsInDatabase.getText()), toInt(this.txtDeletedViewsInDatabase.getText()), toInt(this.txtConflictingViews.getText())) ); + logger.info(String.format(" Objects: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllViewObjects().size(), toInt(this.txtNewViewObjectsInModel.getText()), toInt(this.txtUpdatedViewObjectsInModel.getText()), toInt(this.txtDeletedViewObjectsInModel.getText()), toInt(this.txtNewViewObjectsInDatabase.getText()), toInt(this.txtUpdatedViewObjectsInDatabase.getText()), toInt(this.txtDeletedViewObjectsInDatabase.getText()), toInt(this.txtConflictingViewObjects.getText())) ); + logger.info(String.format(" Connections: %6d %6d %6d %6d %6d %6d %6d %6d", this.exportedModel.getAllViewConnections().size(), toInt(this.txtNewViewConnectionsInModel.getText()), toInt(this.txtUpdatedViewConnectionsInModel.getText()), toInt(this.txtDeletedViewConnectionsInModel.getText()), toInt(this.txtNewViewConnectionsInDatabase.getText()), toInt(this.txtUpdatedViewConnectionsInDatabase.getText()), toInt(this.txtDeletedViewConnectionsInDatabase.getText()), toInt(this.txtConflictingViewConnections.getText())) ); + logger.info(String.format(" images: %6d %6d %16s %6d", ((IArchiveManager)this.exportedModel.getAdapter(IArchiveManager.class)).getLoadedImagePaths().size(), toInt(this.txtNewImagesInModel.getText()), "", toInt(this.txtNewImagesInDatabase.getText())) ); } } - + + closeMessage(); - if ( total == 0 ) { + if ( total == 0 && (this.exportedModel.getCurrentVersion().getChecksum().toString().equals(this.exportedModel.getDatabaseVersion().getChecksum().toString()))) { logger.info("The model does not need to be exported to the database."); return true; } @@ -1847,6 +1909,7 @@ protected void export() { this.exportedModel.getCurrentVersion().setChecksum(DBChecksum.calculateChecksum(this.exportedModel, this.txtReleaseNote.getText())); // we reset the counters as they will be updated during the import and export process + this.txtTotalProfiles.setText(this.ZERO); this.txtNewProfilesInModel.setText(this.ZERO); this.txtUpdatedProfilesInModel.setText(this.ZERO); this.txtDeletedProfilesInModel.setText(this.ZERO); this.txtNewProfilesInDatabase.setText(this.ZERO); this.txtUpdatedProfilesInDatabase.setText(this.ZERO); this.txtDeletedProfilesInDatabase.setText(this.ZERO); this.txtConflictingProfiles.setText(this.ZERO); this.txtTotalElements.setText(this.ZERO); this.txtNewElementsInModel.setText(this.ZERO); this.txtUpdatedElementsInModel.setText(this.ZERO); this.txtDeletedElementsInModel.setText(this.ZERO); this.txtNewElementsInDatabase.setText(this.ZERO); this.txtUpdatedElementsInDatabase.setText(this.ZERO); this.txtDeletedElementsInDatabase.setText(this.ZERO); this.txtConflictingElements.setText(this.ZERO); this.txtTotalRelationships.setText(this.ZERO); this.txtNewRelationshipsInModel.setText(this.ZERO); this.txtUpdatedRelationshipsInModel.setText(this.ZERO); this.txtDeletedRelationshipsInModel.setText(this.ZERO); this.txtNewRelationshipsInDatabase.setText(this.ZERO); this.txtUpdatedRelationshipsInDatabase.setText(this.ZERO); this.txtDeletedRelationshipsInDatabase.setText(this.ZERO); this.txtConflictingRelationships.setText(this.ZERO); this.txtTotalFolders.setText(this.ZERO); this.txtNewFoldersInModel.setText(this.ZERO); this.txtUpdatedFoldersInModel.setText(this.ZERO); this.txtDeletedFoldersInModel.setText(this.ZERO); this.txtNewFoldersInDatabase.setText(this.ZERO); this.txtUpdatedFoldersInDatabase.setText(this.ZERO); this.txtDeletedFoldersInDatabase.setText(this.ZERO); this.txtConflictingFolders.setText(this.ZERO); @@ -1874,6 +1937,19 @@ protected void export() { hideGrpDatabase(); createGrpConflict(); + + Iterator> profilesIterator = this.exportedModel.getAllProfiles().entrySet().iterator(); + while ( profilesIterator.hasNext() ) { + IProfile profile = profilesIterator.next().getValue(); + if ( this.exportedModel.getDBMetadata(profile).getDatabaseStatus() == DATABASE_STATUS.isConflicting ) { + if ( this.exportedModel.getAllConflicts().get(profile) != null ) { + this.exportedModel.getAllConflicts().put(profile, CONFLICT_CHOICE.askUser); + TableItem item = new TableItem(this.tblListConflicts, SWT.NONE); + item.setText(profile.getId()); + item.setData(profile); + } + } + } Iterator> elementsIterator = this.exportedModel.getAllElements().entrySet().iterator(); while ( elementsIterator.hasNext() ) { @@ -1957,13 +2033,23 @@ protected void export() { //////////////////////////// PHASE 3 : we remove from the model the components that have been deleted in the database if ( !isNeo4JDatabase ) { - setMessage("Removing from the model the elements that have been deleted in the database ..."); - errorMessage = "Failed to remove from the model the elements that have been deleted in the database."; + setMessage("Removing from the model the components that have been deleted in the database ..."); + errorMessage = "Failed to remove from the model the components that have been deleted in the database."; // please be aware that the commands put in the undoableCommand are single operations // ie. when an element is deleted, the command does not delete at the same time the relationships connected to it, not the views objets that references it. // we do not use getException() method as Archi commands do not implement it + + Iterator> profilesIterator = this.exportedModel.getAllProfiles().entrySet().iterator(); + while ( profilesIterator.hasNext() ) { + IProfile profile = profilesIterator.next().getValue(); + if ( this.exportedModel.getDBMetadata(profile).getDatabaseStatus() == DATABASE_STATUS.isDeletedInDatabase ) { + undoableCommands.add(new DBDeleteProfileCommand(this.exportedModel, profile)); + incrementText(this.txtDeletedProfilesInDatabase); + decrementText(this.txtTotalProfiles); + } + } Iterator> elementsIterator = this.exportedModel.getAllElements().entrySet().iterator(); while ( elementsIterator.hasNext() ) { @@ -2038,6 +2124,9 @@ protected void export() { int progressBarWidth = this.exportConnection.getFoldersNotInModel().size() + this.exportConnection.getElementsNotInModel().size() + this.exportConnection.getRelationshipsNotInModel().size() + this.exportConnection.getViewsNotInModel().size() + this.exportConnection.getViewObjectsNotInModel().size() + this.exportConnection.getViewConnectionsNotInModel().size(); // we add the number of updated components to import from the database + Iterator> profilesIterator = this.exportedModel.getAllProfiles().entrySet().iterator(); + while ( profilesIterator.hasNext() ) if ( this.exportedModel.getDBMetadata(profilesIterator.next().getValue()).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) ++progressBarWidth; + Iterator> foldersIterator = this.exportedModel.getAllFolders().entrySet().iterator(); while ( foldersIterator.hasNext() ) if ( this.exportedModel.getDBMetadata(foldersIterator.next().getValue()).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) ++progressBarWidth; @@ -2071,7 +2160,36 @@ protected void export() { errorMessage = "Failed to import components from the database."; try ( DBDatabaseImportConnection importConnection = new DBDatabaseImportConnection(this.exportConnection) ) { + // IMPORT PROFILES (we import the profiles BEFORE the elements, relationships and views because they must exist when the elements, relationships are imported) + if ( this.exportConnection.getProfilesNotInModel().size() == 0 ) + logger.info("There is no specialization to import."); + else { + logger.info("Importing new specializations ..."); + setProgressBarLabel("Importing new specializations ..."); + for (String id : this.exportConnection.getProfilesNotInModel().keySet() ) { + DBMetadata versionToImport = this.exportConnection.getProfilesNotInModel().get(id); + if ( versionToImport.getInitialVersion().getVersion() == 0 ) { + if ( logger.isDebugEnabled() ) logger.debug("The specialization id "+id+" has been created in the database. We import it from the database."); + undoableCommands.checkAndExecute(new DBImportProfileFromIdCommand(importConnection, this.exportedModel, id, versionToImport.getLatestDatabaseVersion().getVersion(), DBImportMode.forceSharedMode)); + incrementText(this.txtNewProfilesInDatabase); + incrementText(this.txtTotalProfiles); + } else { + if ( logger.isDebugEnabled() ) logger.debug("The specialization id "+id+" is not imported as it has been deleted from the model."); + incrementText(this.txtDeletedProfilesInModel); + } + } + } + // UPDATE PROFILES + profilesIterator = this.exportedModel.getAllProfiles().entrySet().iterator(); + while ( profilesIterator.hasNext() ) { + IProfile profile = profilesIterator.next().getValue(); + if ( this.exportedModel.getDBMetadata(profile).getDatabaseStatus() == DATABASE_STATUS.isUpadtedInDatabase ) { + if ( logger.isDebugEnabled() ) logger.debug("The specialization id "+profile.getId()+" has been updated in the database. We import the new version from the database."); + undoableCommands.checkAndExecute(new DBImportProfileFromIdCommand(importConnection, this.exportedModel, profile.getId(), 0, DBImportMode.forceSharedMode)); + incrementText(this.txtUpdatedProfilesInDatabase); + } + } // IMPORT FOLDERS (we import the folders BEFORE the elements, relationships and views because they must exist when the elements, relationships and views are imported) if ( this.exportConnection.getFoldersNotInModel().size() == 0 ) @@ -2359,7 +2477,7 @@ protected void export() { this.exportConnection.setAutoCommit(false); if ( !isNeo4JDatabase ) { - logger.info("Exporting the model itslef ..."); + logger.info("Exporting the model itself ..."); this.exportConnection.exportModel(this.exportedModel, this.txtReleaseNote.getText()); } else { if ( this.selectedDatabase.shouldEmptyNeo4jDB() ) { @@ -2533,12 +2651,12 @@ else if ( dbStatus == DATABASE_STATUS.isUpdatedInModel ) rollbackAndCloseConnection(); doShowResult(STATUS.Error, errorMessage + "\n"+exportError.getMessage()); - popup(Level.ERROR, errorMessage + "\n\nThe transaction has been rolled back to leave the database in a coherent state. You may solve the issue and export again your components.", exportError); + DBGuiUtils.popup(Level.ERROR, errorMessage + "\n\nThe transaction has been rolled back to leave the database in a coherent state. You may solve the issue and export again your components.", exportError); } catch (SQLException closeDBError) { doShowResult(STATUS.Error, "Error while exporting model.\n"+exportError.getMessage()+"\nThe transaction failed to rollback, please check your database carrefully !"); - popup(Level.FATAL, "An error occurred while exporting the components."+exportError); - popup(Level.FATAL, "An exception has been detected during the rollback and closure of the database transaction.\n\nThe database is left in an unknown state.\n\nPlease check carrefully your database !", closeDBError); + DBGuiUtils.popup(Level.FATAL, "An error occurred while exporting the components."+exportError); + DBGuiUtils.popup(Level.FATAL, "An exception has been detected during the rollback and closure of the database transaction.\n\nThe database is left in an unknown state.\n\nPlease check carrefully your database !", closeDBError); } } @@ -2551,7 +2669,7 @@ else if ( dbStatus == DATABASE_STATUS.isUpdatedInModel ) Method getException = IDBCommand.class.getMethod("getException()"); Exception e = (Exception) getException.invoke(cmd); if ( e != null ) { - popup(Level.FATAL, "Failed to restore the model as it was before the export. Please verify it carefully.", e); + DBGuiUtils.popup(Level.FATAL, "Failed to restore the model as it was before the export. Please verify it carefully.", e); // a single message is sufficient to alert the user break; } @@ -2575,7 +2693,7 @@ else if ( dbStatus == DATABASE_STATUS.isUpdatedInModel ) } catch (Exception err) { setActiveAction(STATUS.Error); doShowResult(STATUS.Error, "Failed to commit the database transaction.\n"+err.getMessage()+"\nPlease check your database carrefully."); - popup(Level.FATAL, "The model has been successfully exported to the database, but an exception has been raised during the database connection commit and closure, thus your dabase may be left in an incoherent state.\n\nPlease check carrefully your database !", err); + DBGuiUtils.popup(Level.FATAL, "The model has been successfully exported to the database, but an exception has been raised during the database connection commit and closure, thus your dabase may be left in an incoherent state.\n\nPlease check carrefully your database !", err); return; } } @@ -2668,7 +2786,7 @@ public void handleEvent(Event event) { DBGuiExportModel.this.btnDoNotExport.setEnabled(false); DBGuiExportModel.this.btnImportDatabaseVersion.setEnabled(false); DBGuiExportModel.this.tblCompareComponent.removeAll(); - popup(Level.ERROR, "Do not know which component is conflicting !!! That's weird !!!"); + DBGuiUtils.popup(Level.ERROR, "Do not know which component is conflicting !!! That's weird !!!"); } else { DBGuiExportModel.this.btnExportMyVersion.setEnabled(true); DBGuiExportModel.this.btnDoNotExport.setEnabled(true); @@ -2823,7 +2941,7 @@ protected void tagComponentWithConflictResolutionChoice(CONFLICT_CHOICE required EObject component = (EObject)this.tblListConflicts.getSelection()[0].getData(); if ( component == null ) { - popup(Level.ERROR, "Can't get conflicting component \""+this.tblListConflicts.getSelection()[0].getText()+"\""); + DBGuiUtils.popup(Level.ERROR, "Can't get conflicting component \""+this.tblListConflicts.getSelection()[0].getText()+"\""); return; } diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java b/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java index 1e84e504..d306067c 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiImportComponents.java @@ -242,7 +242,7 @@ public void widgetSelected(SelectionEvent event) { try { doImport(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised during import.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised during import.", err); } } @Override @@ -346,7 +346,7 @@ else if ( this.radioOptionElement.getSelection() ) else if ( this.radioOptionView.getSelection() ) getViews(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } @@ -383,7 +383,7 @@ public void widgetSelected(SelectionEvent event) { try { getModels(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -406,7 +406,7 @@ public void widgetSelected(SelectionEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -428,7 +428,7 @@ public void widgetSelected(SelectionEvent event) { try { getViews(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -470,7 +470,7 @@ else if ( DBGuiImportComponents.this.radioOptionView.getSelection () ) getViews(); } } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } }); @@ -690,7 +690,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -757,7 +757,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -821,7 +821,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -877,7 +877,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -949,7 +949,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -1008,7 +1008,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -1063,7 +1063,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -1122,7 +1122,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -1172,7 +1172,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -1223,7 +1223,7 @@ public void mouseUp(MouseEvent event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } } @@ -1615,7 +1615,7 @@ else if ( DBGuiImportComponents.this.radioOptionView.getSelection() ) getViews(); } } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } @@ -2231,6 +2231,7 @@ void doImport() throws Exception { StringBuilder folderPathBuilder = new StringBuilder(); while ( !isRootFolder ) { try (DBSelect subResult = new DBSelect(DBGuiImportComponents.this.importConnection.getDatabaseEntry().getName(), DBGuiImportComponents.this.importConnection.getConnection(), "SELECT fim.folder_id, fim.folder_version, fim.parent_folder_id, f.type, f.root_type, f.name FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model fim JOIN "+this.selectedDatabase.getSchemaPrefix()+"folders f ON fim.folder_id = f.id and fim.folder_version = f.version WHERE fim.model_id = ? AND fim.model_version = (SELECT MAX(model_version) FROM "+this.selectedDatabase.getSchemaPrefix()+"folders_in_model WHERE model_id = ?) AND fim.folder_id = ?", id, id, folderId) ) { + subResult.next(); if ( folderPathBuilder.length() == 0 ) folderPathBuilder.append(subResult.getString("name")); else { @@ -2422,9 +2423,9 @@ else if ( this.radioOptionView.getSelection() ) { // we redraw the tblComponents table to unselect the items (and hide the newly imported components if the option is selected) this.hideAlreadyInModel.notifyListeners(SWT.Selection, new Event()); } catch(RuntimeException e) { - popup(Level.ERROR, "Couldn't import component.", e); + DBGuiUtils.popup(Level.ERROR, "Couldn't import component.", e); } finally { - // we do not catch the exception if any, but we need to close the popup + // we do not catch the exception if any, but we need to close the DBGuiUtils.popup closeMessage(); // We rename the "cancel" button to "close" this.btnClose.setText("Close"); @@ -2485,7 +2486,7 @@ public void handleEvent(Event event) { try { getElements(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } }; @@ -2497,7 +2498,7 @@ public void handleEvent(Event event) { try { getFolders(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } }; @@ -2509,7 +2510,7 @@ public void handleEvent(Event event) { try { getViews(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised.", err); } } }; diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiImportImage.java b/sources/src/org/archicontribs/database/GUI/DBGuiImportImage.java index 5fe8eca0..2ce0503a 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiImportImage.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiImportImage.java @@ -102,7 +102,7 @@ public void run() { try { getDatabases(false); } catch (Exception err) { - popup(Level.ERROR, "Failed to get the databases.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get the databases.", err); return; } } @@ -215,7 +215,7 @@ protected void connectedToDatabase(boolean forceCheckDatabase) { item.setData("imagePath", path); } } catch (Exception err) { - popup(Level.ERROR, "Failed to get images from the database", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get images from the database", err); } } diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiImportModel.java b/sources/src/org/archicontribs/database/GUI/DBGuiImportModel.java index dcbab212..fcb1ccfd 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiImportModel.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiImportModel.java @@ -136,11 +136,11 @@ public void widgetSelected(SelectionEvent e) { List allModels = IEditorModelManager.INSTANCE.getModels(); for ( IArchimateModel existingModel: allModels ) { if ( DBPlugin.areEqual(modelId, existingModel.getId()) ) { - popup(Level.ERROR, "A model with ID \""+modelId+"\" already exists. Cannot import it again ..."); + DBGuiUtils.popup(Level.ERROR, "A model with ID \""+modelId+"\" already exists. Cannot import it again ..."); return; } if ( checkName && DBPlugin.areEqual(modelName, existingModel.getName()) ) { - if ( !question("A model with name \""+modelName+"\" already exists.\n\nIt is possible to have two models with the same name as long as they've got distinct IDs but it is not recommended.\n\nDo you wish to force the import ?") ) { + if ( !DBGuiUtils.question("A model with name \""+modelName+"\" already exists.\n\nIt is possible to have two models with the same name as long as they've got distinct IDs but it is not recommended.\n\nDo you wish to force the import ?") ) { return; } checkName = false; // if a third model has got the same name, we do not ask again. @@ -242,7 +242,7 @@ public void modifyText(ModifyEvent e) { tableItem.setData("date", model.get("created_on")); } } catch (Exception err) { - DBGui.popup(Level.ERROR, "Failed to get the list of models in the database.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get the list of models in the database.", err); } } }); @@ -283,7 +283,7 @@ public void handleEvent(Event e) { tableItem.setData("purpose", version.get("purpose")); } } catch (Exception err) { - DBGui.popup(Level.ERROR, "Failed to get model's versions from the database", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get model's versions from the database", err); } if ( DBGuiImportModel.this.tblModelVersions.getItemCount() != 0 ) { @@ -424,7 +424,7 @@ public void handleEvent(Event e) { TableColumn colCreatedOn = new TableColumn(this.tblModelVersions, SWT.NONE); colCreatedOn.setText("Date"); - colCreatedOn.setWidth(120); + colCreatedOn.setWidth(130); TableColumn colCreatedBy = new TableColumn(this.tblModelVersions, SWT.NONE); colCreatedBy.setText("Author"); @@ -492,7 +492,7 @@ private void createGrpComponents() { this.grpComponents.setVisible(false); this.grpComponents.setBackground(GROUP_BACKGROUND_COLOR); this.grpComponents.setFont(GROUP_TITLE_FONT); - this.grpComponents.setText("Your model's components: "); + this.grpComponents.setText("Your model components: "); // we calculate the required height of the grpComponents group int requiredHeight = 10 * (getDefaultLabelHeight() + getDefaultMargin()); @@ -593,6 +593,7 @@ private void createGrpComponents() { this.txtTotalProfiles = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalProfiles.setEditable(false); + this.txtTotalProfiles.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -601,6 +602,7 @@ private void createGrpComponents() { this.txtImportedProfiles = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedProfiles.setEditable(false); + this.txtImportedProfiles.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblProfiles, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -609,6 +611,7 @@ private void createGrpComponents() { this.txtTotalElements = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalElements.setEditable(false); + this.txtTotalElements.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -617,6 +620,7 @@ private void createGrpComponents() { this.txtImportedElements = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedElements.setEditable(false); + this.txtImportedElements.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblElements, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -625,6 +629,7 @@ private void createGrpComponents() { this.txtTotalRelationships = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalRelationships.setEditable(false); + this.txtTotalRelationships.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -633,6 +638,7 @@ private void createGrpComponents() { this.txtImportedRelationships = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedRelationships.setEditable(false); + this.txtImportedRelationships.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblRelationships, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -641,6 +647,7 @@ private void createGrpComponents() { this.txtTotalFolders = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalFolders.setEditable(false); + this.txtTotalFolders.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -649,6 +656,7 @@ private void createGrpComponents() { this.txtImportedFolders = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedFolders.setEditable(false); + this.txtImportedFolders.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblFolders, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -657,6 +665,7 @@ private void createGrpComponents() { this.txtTotalViews = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalViews.setEditable(false); + this.txtTotalViews.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -665,6 +674,7 @@ private void createGrpComponents() { this.txtImportedViews = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedViews.setEditable(false); + this.txtImportedViews.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViews, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -673,6 +683,7 @@ private void createGrpComponents() { this.txtTotalViewObjects = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalViewObjects.setEditable(false); + this.txtTotalViewObjects.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -681,6 +692,7 @@ private void createGrpComponents() { this.txtImportedViewObjects = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedViewObjects.setEditable(false); + this.txtImportedViewObjects.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewObjects, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -689,6 +701,7 @@ private void createGrpComponents() { this.txtTotalViewConnections = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalViewConnections.setEditable(false); + this.txtTotalViewConnections.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -697,6 +710,7 @@ private void createGrpComponents() { this.txtImportedViewConnections = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedViewConnections.setEditable(false); + this.txtImportedViewConnections.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblViewConnections, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -705,6 +719,7 @@ private void createGrpComponents() { this.txtTotalImages = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtTotalImages.setEditable(false); + this.txtTotalImages.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblImages, 0, SWT.CENTER); fd.left = new FormAttachment(lblTotal, 0, SWT.LEFT); @@ -713,6 +728,7 @@ private void createGrpComponents() { this.txtImportedImages = new Text(this.grpComponents, SWT.BORDER | SWT.CENTER); this.txtImportedImages.setEditable(false); + this.txtImportedImages.setEnabled(false); fd = new FormData(26,18); fd.top = new FormAttachment(lblImages, 0, SWT.CENTER); fd.left = new FormAttachment(lblImported, 0, SWT.LEFT); @@ -741,45 +757,64 @@ public void doImport() { fd.right = new FormAttachment(100); fd.bottom = new FormAttachment(this.grpComponents, -getDefaultMargin()); this.grpModelVersions.setLayoutData(fd); + this.grpModelVersions.setText("Your model details: "); - fd = new FormData(); - fd.top = new FormAttachment(0, getDefaultMargin()); - fd.left = new FormAttachment(0, getDefaultMargin()); - fd.right = new FormAttachment(40, -getDefaultMargin()); - fd.bottom = new FormAttachment(100, -getDefaultMargin()); - this.tblModelVersions.setLayoutData(fd); + this.tblModelVersions.setVisible(false); + + Label lblModelVersion = new Label(this.grpModelVersions, SWT.NONE); fd = new FormData(); fd.top = new FormAttachment(0, getDefaultMargin()); - fd.left = new FormAttachment(40, 0); + fd.left = new FormAttachment(0, getDefaultMargin()); this.lblModelName.setLayoutData(fd); fd = new FormData(); fd.top = new FormAttachment(this.lblModelName, 0, SWT.CENTER); - fd.left = new FormAttachment(this.lblModelName, 80, SWT.LEFT); + fd.left = new FormAttachment(lblModelVersion, getDefaultMargin(), SWT.RIGHT); fd.right = new FormAttachment(100, -getDefaultMargin()); this.txtModelName.setLayoutData(fd); + lblModelVersion.setBackground(GROUP_BACKGROUND_COLOR); + lblModelVersion.setText("Model version:"); fd = new FormData(); - fd.top = new FormAttachment(this.txtModelName, getDefaultMargin()); - fd.left = new FormAttachment(40, 0); + fd.top = new FormAttachment(this.lblModelName, getDefaultMargin()); + fd.left = new FormAttachment(0, getDefaultMargin()); + lblModelVersion.setLayoutData(fd); + + Text txtModelVersion = new Text(this.grpModelVersions, SWT.BORDER); + txtModelVersion.setBackground(GROUP_BACKGROUND_COLOR); + txtModelVersion.setEnabled(false); + TableItem selectedVersion = this.tblModelVersions.getSelection()[0]; + if ( selectedVersion.getText(0).isEmpty() ) + txtModelVersion.setText("Latest version"); + else + txtModelVersion.setText(selectedVersion.getText(0)+" ("+selectedVersion.getText(1)+")"); + fd = new FormData(); + fd.top = new FormAttachment(lblModelVersion, 0, SWT.CENTER); + fd.left = new FormAttachment(lblModelVersion, getDefaultMargin(), SWT.RIGHT); + fd.right = new FormAttachment(100, -getDefaultMargin()); + txtModelVersion.setLayoutData(fd); + + fd = new FormData(); + fd.top = new FormAttachment(txtModelVersion, getDefaultMargin()); + fd.left = new FormAttachment(0, getDefaultMargin()); this.lblPurpose.setLayoutData(fd); fd = new FormData(); - fd.top = new FormAttachment(this.txtModelName, 5); - fd.left = new FormAttachment(this.txtModelName, 0, SWT.LEFT); + fd.top = new FormAttachment(txtModelVersion, 5); + fd.left = new FormAttachment(lblModelVersion, getDefaultMargin(), SWT.RIGHT); fd.right = new FormAttachment(100, -getDefaultMargin()); fd.bottom = new FormAttachment(55, -5); this.txtPurpose.setLayoutData(fd); fd = new FormData(); fd.top = new FormAttachment(this.txtPurpose, getDefaultMargin()); - fd.left = new FormAttachment(40, 0); + fd.left = new FormAttachment(0, getDefaultMargin()); this.lblReleaseNote.setLayoutData(fd); fd = new FormData(); fd.top = new FormAttachment(this.txtPurpose, 5); - fd.left = new FormAttachment(this.txtModelName, 0, SWT.LEFT); + fd.left = new FormAttachment(lblModelVersion, getDefaultMargin(), SWT.RIGHT); fd.right = new FormAttachment(100, -getDefaultMargin()); fd.bottom = new FormAttachment(100, -getDefaultMargin()); this.txtReleaseNote.setLayoutData(fd); @@ -823,14 +858,14 @@ public void doImport() { this.txtTotalViewConnections.setText(toString(this.importConnection.getCountViewConnectionsToImport())); this.txtTotalImages.setText(toString(this.importConnection.getCountImagesToImport())); - this.txtImportedProfiles.setText("0"); - this.txtImportedElements.setText("0"); - this.txtImportedRelationships.setText("0"); - this.txtImportedFolders.setText("0"); - this.txtImportedViews.setText("0"); - this.txtImportedViewObjects.setText("0"); - this.txtImportedViewConnections.setText("0"); - this.txtImportedImages.setText("0"); + this.txtImportedProfiles.setText(toString(0)); + this.txtImportedElements.setText(toString(0)); + this.txtImportedRelationships.setText(toString(0)); + this.txtImportedFolders.setText(toString(0)); + this.txtImportedViews.setText(toString(0)); + this.txtImportedViewObjects.setText(toString(0)); + this.txtImportedViewConnections.setText(toString(0)); + this.txtImportedImages.setText(toString(0)); // Import the model components from the database @@ -920,9 +955,9 @@ public void doImport() { } catch (@SuppressWarnings("unused") IOException ign) { // there is nothing we can do } - popup(Level.WARN, "The import has been cancelled."); + DBGuiUtils.popup(Level.WARN, "The import has been cancelled."); } else { - popup(Level.ERROR, "Failed to import model from database.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to import model from database.", err); setActiveAction(STATUS.Error); doShowResult(err); } @@ -1019,10 +1054,10 @@ protected void doShowResult(Exception err) { IEditorModelManager.INSTANCE.closeModel(this.modelToImport); } catch (IOException e) { - popup(Level.FATAL, "Failed to close the model partially imported.\n\nWe suggest you close and restart Archi.", e); + DBGuiUtils.popup(Level.FATAL, "Failed to close the model partially imported.\n\nWe suggest you close and restart Archi.", e); } } else { - popup(Level.ERROR, "Please be warn that the model you just imported is not concistent.\n\nYou choosed to keep it in the preferences, but should you export it back to the database, you may loose data.\n\nDo it at your own risk !"); + DBGuiUtils.popup(Level.ERROR, "Please be warn that the model you just imported is not concistent.\n\nYou choosed to keep it in the preferences, but should you export it back to the database, you may loose data.\n\nDo it at your own risk !"); } } } diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiReplaceElement.java b/sources/src/org/archicontribs/database/GUI/DBGuiReplaceElement.java index 3a553951..3c72a76f 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiReplaceElement.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiReplaceElement.java @@ -42,7 +42,7 @@ public void widgetSelected(SelectionEvent event) { try { doReplace(); } catch (Exception err) { - DBGui.popup(Level.ERROR, "An exception has been raised during import.", err); + DBGuiUtils.popup(Level.ERROR, "An exception has been raised during import.", err); } } @Override diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiShowDebug.java b/sources/src/org/archicontribs/database/GUI/DBGuiShowDebug.java index bf9d8987..9c73cba4 100644 --- a/sources/src/org/archicontribs/database/GUI/DBGuiShowDebug.java +++ b/sources/src/org/archicontribs/database/GUI/DBGuiShowDebug.java @@ -30,6 +30,7 @@ import com.archimatetool.model.IDiagramModelArchimateObject; import com.archimatetool.model.IDiagramModelConnection; import com.archimatetool.model.IDiagramModelObject; +import com.archimatetool.model.IDiagramModelContainer; import com.archimatetool.model.IIdentifier; /** @@ -91,7 +92,7 @@ public DBGuiShowDebug(EObject obj, String title) { this.model = (DBArchimateModel) ((IDiagramModelArchimateObject)obj).getArchimateConcept().getArchimateModel(); this.selectedMetadata = DBMetadata.getDBMetadata(obj); } else { - popup(Level.ERROR, "Do not know how to get debugging information about a "+obj.getClass().getSimpleName()); + DBGuiUtils.popup(Level.ERROR, "Do not know how to get debugging information about a "+obj.getClass().getSimpleName()); return; } @@ -130,7 +131,7 @@ private void createGrpDebug() { fd.left = new FormAttachment(0, 20); this.selectedComponentLbl.setLayoutData(fd); - // Name + // Name label this.selectedComponentNameLbl = new Label(this.grpDebug, SWT.NONE); this.selectedComponentNameLbl.setBackground(GROUP_BACKGROUND_COLOR); this.selectedComponentNameLbl.setText("Name:"); @@ -139,15 +140,7 @@ private void createGrpDebug() { fd.left = new FormAttachment(0, 70); this.selectedComponentNameLbl.setLayoutData(fd); - this.selectedComponentNameValueLbl = new Label(this.grpDebug, SWT.NONE); - this.selectedComponentNameValueLbl.setBackground(GROUP_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.selectedComponentNameLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.selectedComponentNameLbl, 70); - fd.right = new FormAttachment(100, -20); - this.selectedComponentNameValueLbl.setLayoutData(fd); - - // Id + // Id label this.selectedComponentIdLbl = new Label(this.grpDebug, SWT.NONE); this.selectedComponentIdLbl.setBackground(GROUP_BACKGROUND_COLOR); this.selectedComponentIdLbl.setText("Id:"); @@ -156,15 +149,7 @@ private void createGrpDebug() { fd.left = new FormAttachment(this.selectedComponentNameLbl, 0, SWT.LEFT); this.selectedComponentIdLbl.setLayoutData(fd); - this.selectedComponentIdValueLbl = new Label(this.grpDebug, SWT.NONE); - this.selectedComponentIdValueLbl.setBackground(GROUP_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.selectedComponentIdLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.selectedComponentNameValueLbl, 0, SWT.LEFT); - fd.right = new FormAttachment(100, -20); - this.selectedComponentIdValueLbl.setLayoutData(fd); - - // Class + // Class label this.selectedComponentClassLbl = new Label(this.grpDebug, SWT.NONE); this.selectedComponentClassLbl.setBackground(GROUP_BACKGROUND_COLOR); this.selectedComponentClassLbl.setText("Class:"); @@ -173,15 +158,7 @@ private void createGrpDebug() { fd.left = new FormAttachment(this.selectedComponentNameLbl, 0, SWT.LEFT); this.selectedComponentClassLbl.setLayoutData(fd); - this.selectedComponentClassValueLbl = new Label(this.grpDebug, SWT.NONE); - this.selectedComponentClassValueLbl.setBackground(GROUP_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.selectedComponentClassLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.selectedComponentNameValueLbl, 0, SWT.LEFT); - fd.right = new FormAttachment(100, -20); - this.selectedComponentClassValueLbl.setLayoutData(fd); - - // Image Path + // Image Path label this.selectedComponentImagePathLbl = new Label(this.grpDebug, SWT.NONE); this.selectedComponentImagePathLbl.setBackground(GROUP_BACKGROUND_COLOR); this.selectedComponentImagePathLbl.setText("Image Path:"); @@ -190,15 +167,7 @@ private void createGrpDebug() { fd.left = new FormAttachment(this.selectedComponentNameLbl, 0, SWT.LEFT); this.selectedComponentImagePathLbl.setLayoutData(fd); - this.selectedComponentImagePathValueLbl = new Label(this.grpDebug, SWT.NONE); - this.selectedComponentImagePathValueLbl.setBackground(GROUP_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.selectedComponentImagePathLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.selectedComponentNameValueLbl, 0, SWT.LEFT); - fd.right = new FormAttachment(100, -20); - this.selectedComponentImagePathValueLbl.setLayoutData(fd); - - // Database status + // Database status label this.selectedComponentDatabaseStatusLbl = new Label(this.grpDebug, SWT.BOLD); this.selectedComponentDatabaseStatusLbl.setBackground(GROUP_BACKGROUND_COLOR); this.selectedComponentDatabaseStatusLbl.setText("Database status:"); @@ -207,11 +176,51 @@ private void createGrpDebug() { fd.left = new FormAttachment(0, 70); this.selectedComponentDatabaseStatusLbl.setLayoutData(fd); + + + + // name value + this.selectedComponentNameValueLbl = new Label(this.grpDebug, SWT.NONE); + this.selectedComponentNameValueLbl.setBackground(GROUP_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.selectedComponentNameLbl, 0, SWT.TOP); + fd.left = new FormAttachment(this.selectedComponentDatabaseStatusLbl, 10); + fd.right = new FormAttachment(100, -20); + this.selectedComponentNameValueLbl.setLayoutData(fd); + + // ID value + this.selectedComponentIdValueLbl = new Label(this.grpDebug, SWT.NONE); + this.selectedComponentIdValueLbl.setBackground(GROUP_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.selectedComponentIdLbl, 0, SWT.TOP); + fd.left = new FormAttachment(this.selectedComponentDatabaseStatusLbl, 10); + fd.right = new FormAttachment(100, -20); + this.selectedComponentIdValueLbl.setLayoutData(fd); + + // class value + this.selectedComponentClassValueLbl = new Label(this.grpDebug, SWT.NONE); + this.selectedComponentClassValueLbl.setBackground(GROUP_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.selectedComponentClassLbl, 0, SWT.TOP); + fd.left = new FormAttachment(this.selectedComponentDatabaseStatusLbl, 10); + fd.right = new FormAttachment(100, -20); + this.selectedComponentClassValueLbl.setLayoutData(fd); + + // Image path value + this.selectedComponentImagePathValueLbl = new Label(this.grpDebug, SWT.NONE); + this.selectedComponentImagePathValueLbl.setBackground(GROUP_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.selectedComponentImagePathLbl, 0, SWT.TOP); + fd.left = new FormAttachment(this.selectedComponentDatabaseStatusLbl, 10); + fd.right = new FormAttachment(100, -20); + this.selectedComponentImagePathValueLbl.setLayoutData(fd); + + // Database status value this.selectedComponentDatabaseStatusValueLbl = new Label(this.grpDebug, SWT.BOLD); this.selectedComponentDatabaseStatusValueLbl.setBackground(GROUP_BACKGROUND_COLOR); fd = new FormData(); fd.top = new FormAttachment(this.selectedComponentDatabaseStatusLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.selectedComponentNameValueLbl, 0, SWT.LEFT); + fd.left = new FormAttachment(this.selectedComponentDatabaseStatusLbl, 10); fd.right = new FormAttachment(100, -20); this.selectedComponentDatabaseStatusValueLbl.setLayoutData(fd); @@ -229,30 +238,30 @@ private void createGrpDebug() { this.selectedComponentDebugTable.setLayoutData(fd); TableColumn column = new TableColumn(this.selectedComponentDebugTable, SWT.NONE); - column.setWidth(100); + column.setWidth(135); column = new TableColumn(this.selectedComponentDebugTable, SWT.CENTER); - column.setText("Version"); + column.setText("#"); column.setWidth(50); column = new TableColumn(this.selectedComponentDebugTable, SWT.CENTER); column.setText("Container checksum"); - column.setWidth(230); + column.setWidth(340); column = new TableColumn(this.selectedComponentDebugTable, SWT.CENTER); column.setText("Checksum"); - column.setWidth(230); + column.setWidth(340); column = new TableColumn(this.selectedComponentDebugTable, SWT.CENTER); column.setText("Created on"); - column.setWidth(140); + column.setWidth(220); // corresponding concept this.correspondingConceptLbl = new Label(this.grpDebug, SWT.NONE); this.correspondingConceptLbl.setBackground(GROUP_BACKGROUND_COLOR); - this.correspondingConceptLbl.setText("It is related to the following concept:"); + this.correspondingConceptLbl.setText("It is related to the following Archimate concept:"); fd = new FormData(); fd.top = new FormAttachment(50, 10); fd.left = new FormAttachment(0, 20); this.correspondingConceptLbl.setLayoutData(fd); - // Name + // Name label this.correspondingConceptNameLbl = new Label(this.grpDebug, SWT.NONE); this.correspondingConceptNameLbl.setBackground(GROUP_BACKGROUND_COLOR); this.correspondingConceptNameLbl.setText("Name:"); @@ -261,15 +270,7 @@ private void createGrpDebug() { fd.left = new FormAttachment(0, 70); this.correspondingConceptNameLbl.setLayoutData(fd); - this.correspondingConceptNameValueLbl = new Label(this.grpDebug, SWT.NONE); - this.correspondingConceptNameValueLbl.setBackground(GROUP_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.correspondingConceptNameLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.correspondingConceptNameLbl, 70); - fd.right = new FormAttachment(100, -20); - this.correspondingConceptNameValueLbl.setLayoutData(fd); - - // Id + // Id label this.correspondingConceptIdLbl = new Label(this.grpDebug, SWT.NONE); this.correspondingConceptIdLbl.setBackground(GROUP_BACKGROUND_COLOR); this.correspondingConceptIdLbl.setText("Id:"); @@ -277,16 +278,8 @@ private void createGrpDebug() { fd.top = new FormAttachment(this.correspondingConceptNameLbl, 2); fd.left = new FormAttachment(this.correspondingConceptNameLbl, 0, SWT.LEFT); this.correspondingConceptIdLbl.setLayoutData(fd); - - this.correspondingConceptIdValueLbl = new Label(this.grpDebug, SWT.NONE); - this.correspondingConceptIdValueLbl.setBackground(GROUP_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.correspondingConceptIdLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.correspondingConceptNameValueLbl, 0, SWT.LEFT); - fd.right = new FormAttachment(100, -20); - this.correspondingConceptIdValueLbl.setLayoutData(fd); - - // Class + + // Class label this.correspondingConceptClassLbl = new Label(this.grpDebug, SWT.NONE); this.correspondingConceptClassLbl.setBackground(GROUP_BACKGROUND_COLOR); this.correspondingConceptClassLbl.setText("Class:"); @@ -295,14 +288,7 @@ private void createGrpDebug() { fd.left = new FormAttachment(this.correspondingConceptNameLbl, 0, SWT.LEFT); this.correspondingConceptClassLbl.setLayoutData(fd); - this.correspondingConceptClassValueLbl = new Label(this.grpDebug, SWT.NONE); - this.correspondingConceptClassValueLbl.setBackground(GROUP_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(this.correspondingConceptClassLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.correspondingConceptNameValueLbl, 0, SWT.LEFT); - fd.right = new FormAttachment(100, -20); - this.correspondingConceptClassValueLbl.setLayoutData(fd); - + // Database status label this.correspondingConceptDatabaseStatusLbl = new Label(this.grpDebug, SWT.BOLD); this.correspondingConceptDatabaseStatusLbl.setBackground(GROUP_BACKGROUND_COLOR); this.correspondingConceptDatabaseStatusLbl.setText("Database status:"); @@ -311,11 +297,39 @@ private void createGrpDebug() { fd.left = new FormAttachment(this.correspondingConceptNameLbl, 0, SWT.LEFT); this.correspondingConceptDatabaseStatusLbl.setLayoutData(fd); + // Name value + this.correspondingConceptNameValueLbl = new Label(this.grpDebug, SWT.NONE); + this.correspondingConceptNameValueLbl.setBackground(GROUP_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.correspondingConceptNameLbl, 0, SWT.TOP); + fd.left = new FormAttachment(this.correspondingConceptDatabaseStatusLbl, 10); + fd.right = new FormAttachment(100, -20); + this.correspondingConceptNameValueLbl.setLayoutData(fd); + + // Id value + this.correspondingConceptIdValueLbl = new Label(this.grpDebug, SWT.NONE); + this.correspondingConceptIdValueLbl.setBackground(GROUP_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.correspondingConceptIdLbl, 0, SWT.TOP); + fd.left = new FormAttachment(this.correspondingConceptDatabaseStatusLbl, 10); + fd.right = new FormAttachment(100, -20); + this.correspondingConceptIdValueLbl.setLayoutData(fd); + + // Class value + this.correspondingConceptClassValueLbl = new Label(this.grpDebug, SWT.NONE); + this.correspondingConceptClassValueLbl.setBackground(GROUP_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(this.correspondingConceptClassLbl, 0, SWT.TOP); + fd.left = new FormAttachment(this.correspondingConceptDatabaseStatusLbl, 10); + fd.right = new FormAttachment(100, -20); + this.correspondingConceptClassValueLbl.setLayoutData(fd); + + // Database status value this.correspondingConceptDatabaseStatusValueLbl = new Label(this.grpDebug, SWT.BOLD); this.correspondingConceptDatabaseStatusValueLbl.setBackground(GROUP_BACKGROUND_COLOR); fd = new FormData(); fd.top = new FormAttachment(this.correspondingConceptDatabaseStatusLbl, 0, SWT.TOP); - fd.left = new FormAttachment(this.correspondingConceptNameValueLbl, 0, SWT.LEFT); + fd.left = new FormAttachment(this.correspondingConceptDatabaseStatusLbl, 10); fd.right = new FormAttachment(100, -20); this.correspondingConceptDatabaseStatusValueLbl.setLayoutData(fd); @@ -333,19 +347,19 @@ private void createGrpDebug() { this.correspondingConceptDebugTable.setLayoutData(fd); column = new TableColumn(this.correspondingConceptDebugTable, SWT.NONE); - column.setWidth(100); + column.setWidth(135); column = new TableColumn(this.correspondingConceptDebugTable, SWT.CENTER); - column.setText("Version"); + column.setText("#"); column.setWidth(50); column = new TableColumn(this.correspondingConceptDebugTable, SWT.CENTER); column.setText("Container checksum"); - column.setWidth(230); + column.setWidth(340); column = new TableColumn(this.correspondingConceptDebugTable, SWT.CENTER); column.setText("Checksum"); - column.setWidth(230); + column.setWidth(340); column = new TableColumn(this.correspondingConceptDebugTable, SWT.CENTER); column.setText("Created on"); - column.setWidth(140); + column.setWidth(220); } @Override @@ -357,7 +371,7 @@ public void run() { if ( this.selectedObject instanceof IDiagramModelArchimateComponent ) this.model.countObject(((IDiagramModelArchimateComponent)this.selectedObject).getArchimateConcept(), true); } catch (Exception e) { - popup(Level.ERROR, "Failed to calculate checksum for selected component.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to calculate checksum for selected component.", e); close(); return; } @@ -419,7 +433,7 @@ public void run() { this.correspondingConceptDebugTable.setVisible(false); } - if ( !(this.selectedObject instanceof IDiagramModel) ) { + if ( !(this.selectedObject instanceof IDiagramModelContainer) ) { TableColumn column = this.selectedComponentDebugTable.getColumn(2); column.setResizable(false); column.setText(""); @@ -436,7 +450,7 @@ public void run() { try { getDatabases(true); } catch (Exception err) { - popup(Level.ERROR, "Failed to get the databases.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get the databases.", err); return; } } @@ -469,7 +483,7 @@ else if ( this.selectedObject instanceof IDiagramModelConnection ) this.exportConnection.getVersionFromDatabase((IIdentifier)this.selectedObject); } catch (SQLException err) { - popup(Level.ERROR, "Failed to get information about component from the database.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get information about component from the database.", err); return; } @@ -494,7 +508,7 @@ else if ( this.selectedObject instanceof IDiagramModelConnection ) this.model.getAllViews().put(((IDiagramModel)this.selectedObject).getId(), (IDiagramModel)this.selectedObject); this.model.countObject(this.selectedObject, true); } catch (Exception err) { - popup(Level.ERROR, "Failed to recalculate view chekcsum.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to recalculate view chekcsum.", err); return; } } diff --git a/sources/src/org/archicontribs/database/GUI/DBGuiUtils.java b/sources/src/org/archicontribs/database/GUI/DBGuiUtils.java new file mode 100644 index 00000000..49a16031 --- /dev/null +++ b/sources/src/org/archicontribs/database/GUI/DBGuiUtils.java @@ -0,0 +1,446 @@ +package org.archicontribs.database.GUI; + +import java.awt.Toolkit; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import org.apache.log4j.Level; +import org.apache.log4j.Priority; +import org.archicontribs.database.DBLogger; +import org.archicontribs.database.DBPlugin; +import org.archicontribs.database.model.DBMetadata; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +/** + * The DBGuiUtils class hosts the static methods that create simple popups on screeen to communicate with user. + * Methods are thread safe as they call display.suncExec + * @author herve + */ +public class DBGuiUtils { + protected static final DBLogger logger = new DBLogger(DBGuiUtils.class); + protected static final Display display = Display.getCurrent() == null ? Display.getDefault() : Display.getCurrent(); + protected static final Color BLACK_COLOR = DBGui.BLACK_COLOR; + protected static final Color BG_COLOR = DBGui.COMPO_LEFT_COLOR; // light blue + protected static final Font TITLE_FONT = DBGui.TITLE_FONT; + protected static final Cursor CURSOR_WAIT = new Cursor(null, SWT.CURSOR_WAIT); + protected static final Cursor CURSOR_ARROW = new Cursor(null, SWT.CURSOR_ARROW); + + + /************** popup message ***********************/ + + static Shell popupShell = null; + static Composite popupComposite = null; + static Label popupLabel = null; + /** + * Shows up an on screen popup displaying a message to the user but does not wait for any user input
+ * The message can be changed in the popup window without closing the popup and opening a new one by calling several times the showPopupMessage method
+ * To dismiss the popup windows, it is the the responsibility of the caller to call the {@link #closePopupMessage()} method
+ * @param msg Message to show in the popup + * @return + */ + public static Shell showPopupMessage(String msg) { + logger.info(msg); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if ( popupShell == null ) { + popupShell = new Shell(display, SWT.APPLICATION_MODAL); + popupShell.setSize(500, 70); + popupShell.setBackground(BLACK_COLOR); + + // Use the active shell, if available, to determine the new shell placing + int locationX = 0; + int locationY = 0; + Rectangle shellSize = popupShell.getBounds(); + Shell parent = display.getActiveShell(); + if (parent!=null) { + Rectangle parentSize = parent.getBounds(); + locationX = (parentSize.width - shellSize.width)/2+parentSize.x; + locationY = (parentSize.height - shellSize.height)/2+parentSize.y; + } else { + locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - 500) / 4; + locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - 70) / 4; + } + popupShell.setLocation(new Point(locationX, locationY)); + + int borderWidth = (popupShell.getBorderWidth()+1)*2; + popupComposite = new Composite(popupShell, SWT.NONE); + popupComposite.setSize(500-borderWidth, 70-borderWidth); + popupComposite.setLocation(1, 1); + popupComposite.setBackground(BG_COLOR); + popupComposite.setLayout(new GridLayout( 1, false ) ); + + popupLabel = new Label(popupComposite, SWT.CENTER | SWT.WRAP); + popupLabel.setBackground(BG_COLOR); + popupLabel.setLayoutData( new GridData( SWT.CENTER, SWT.CENTER, true, true ) ); + popupLabel.setFont(TITLE_FONT); + } else { + restoreCursors(); + } + + popupLabel.setText(msg); + popupShell.layout(true); + popupShell.open(); + + popupComposite.layout(); + + setWaitCursor(); + } + }); + + return popupShell; + } + + /** + * dismiss the popupMessage window if it is displayed (else, does nothing) + */ + public static void closePopupMessage() { + if ( popupShell != null ) { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + popupShell.close(); + popupShell = null; + + restoreCursors(); + } + }); + } + } + + /******************** popup ***********************/ + + /** + * Shows up an on screen popup displaying the message and wait for the user to click on the "OK" button + * @param level Level of the message (INFO, ERROR, DEBUG, ...) + * @param msg Message to print in the popup + */ + public static void popup(Level level, String msg) { + popup(level,msg,null); + } + + /** + * Shows up an on screen popup, displaying the message (and the exception message if any) and wait for the user to click on the "OK" button
+ * The exception stacktrace is also printed on the standard error stream + * @param level Level of the message (INFO, ERROR, DEBUG, ...) + * @param msg Message to print in the popup + * @param e Exception to display in the popup + */ + public static void popup(Level level, String msg, Exception e) { + logger.debug(level.toString()+": "+msg, e); + + display.syncExec(new Runnable() { + @Override + public void run() { + String popupMessage = msg; + Throwable cause = e; + while ( cause != null ) { + if ( cause.getMessage() != null ) { + if ( !popupMessage.endsWith(cause.getMessage()) ) + popupMessage += "\n\n" + cause.getClass().getSimpleName() + ": " + cause.getMessage(); + } else + popupMessage += "\n\n" + cause.getClass().getSimpleName(); + cause = cause.getCause(); + } + + switch ( level.toInt() ) { + case Priority.FATAL_INT: + case Priority.ERROR_INT: + MessageDialog.openError(display.getActiveShell(), DBPlugin.pluginTitle, popupMessage); + break; + case Priority.WARN_INT: + MessageDialog.openWarning(display.getActiveShell(), DBPlugin.pluginTitle, popupMessage); + break; + default: + MessageDialog.openInformation(display.getActiveShell(), DBPlugin.pluginTitle, popupMessage); + break; + } + } + }); + + //refreshDisplay(); + } + + + /******************** question *********************/ + + /** The choice made by the user in the question window (0 = first choice, 1 = 2nd choice, ...) */ + protected static int questionResult; + + /** + * Shows up an on screen popup displaying a question to the user and defaults the possible answers to YRES or NO
+ * It is required to allows communication between threads + * @param msg The question to ask to the user + * @return true if the user selected YES and false if the user selected NO + */ + public static boolean question(String msg) { + return question(msg, new String[] {"Yes", "No"}) == 0; + } + + /** + * Open up an on screen popup displaying a question to the user and allows to choose the possible answers
+ * @param msg The question to ask to the user + * @param buttonLabels The list of choices to present to the user + * @return 0 if the user selected the first choice, 1 if the user selected the second choice, and so on + */ + public static int question(String msg, String[] buttonLabels) { + if ( logger.isDebugEnabled() ) logger.debug("Question: "+msg); + + display.syncExec(new Runnable() { + @Override + public void run() { + Shell questionShell = new Shell(display, SWT.SHELL_TRIM); + questionShell.setSize(0, 0); + questionShell.setBackground(BLACK_COLOR); + + // Use the active shell, if available, to determine the new shell placing + int locationX = 0; + int locationY = 0; + Rectangle shellSize = questionShell.getBounds(); + Shell parent = display.getActiveShell(); + if (parent!=null) { + Rectangle parentSize = parent.getBounds(); + locationX = (parentSize.width - shellSize.width)/2+parentSize.x; + locationY = (parentSize.height - shellSize.height)/2+parentSize.y; + } else { + locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - questionShell.getSize().x) / 4; + locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - questionShell.getSize().y) / 4; + } + questionShell.setLocation(new Point(locationX, locationY)); + MessageDialog messageDialog = new MessageDialog(questionShell, DBPlugin.pluginTitle, null, msg, MessageDialog.QUESTION, buttonLabels, 0); + questionResult = messageDialog.open(); + } + }); + + if ( logger.isDebugEnabled() ) logger.debug("Answer: "+buttonLabels[questionResult]); + return questionResult; + } + + + /******************** passwordDialog **********************/ + + /** The password entered by the user */ + protected static String answeredPassword; + + /** + * Open up an input dialog and ask for a password + * @param title the dialog title + * @param message the message on the password dialog + * @return the password entered by the user + */ + public static String passwordDialog(String title, String message) { + if ( logger.isDebugEnabled() ) logger.debug("Asking for password"); + answeredPassword = ""; + display.syncExec(new Runnable() { + @Override + public void run() { + Shell passwordDialogShell = new Shell(display, SWT.SHELL_TRIM); + passwordDialogShell.setText(title); + passwordDialogShell.setSize(0, 0); + passwordDialogShell.setBackground(BLACK_COLOR); + + // Use the active shell, if available, to determine the new shell placing + int locationX = 0; + int locationY = 0; + Rectangle shellSize = passwordDialogShell.getBounds(); + Shell parent = display.getActiveShell(); + if (parent!=null) { + Rectangle parentSize = parent.getBounds(); + locationX = (parentSize.width - shellSize.width)/2+parentSize.x; + locationY = (parentSize.height - shellSize.height)/2+parentSize.y; + } else { + locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - passwordDialogShell.getSize().x) / 4; + locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - passwordDialogShell.getSize().y) / 4; + } + passwordDialogShell.setLocation(new Point(locationX, locationY)); + + DBGuiPasswordDialog passwordDialog = new DBGuiPasswordDialog(passwordDialogShell); + if ( passwordDialog.open() == 0 ) + answeredPassword = passwordDialog.getPassword(); + else + answeredPassword = null; + passwordDialog.close(); + } + }); + + return answeredPassword; + } + + /********************* selectItemsDialog ******************/ + protected List selectedItemsToReturn = new ArrayList(); + + /** + * Open up an input dialog with a list of items and allow to select items in the list + * @param title the dialog title + * @param message the message on the dialog + * @param map the list to display under the form of Map + * @param singleMode true if only a single item in the list can be selected, false if multiple items can be selected + * @return the password entered by the user + */ + public static List selectItemsDialog(String title, String message, Map map, boolean singleMode) { + logger.info(message); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + setWaitCursor(); + + Shell selectItemsShell = new Shell(display, SWT.SHELL_TRIM | SWT.APPLICATION_MODAL); + selectItemsShell.setText(title); + selectItemsShell.setSize(1024, 768); + selectItemsShell.setBackground(BLACK_COLOR); + selectItemsShell.setLayout(new GridLayout(1, false)); + + + // Use the active shell, if available, to determine the new shell placing + int locationX = 0; + int locationY = 0; + Rectangle shellSize = selectItemsShell.getBounds(); + Shell parent = display.getActiveShell(); + if (parent!=null) { + Rectangle parentSize = parent.getBounds(); + locationX = (parentSize.width - shellSize.width)/2+parentSize.x; + locationY = (parentSize.height - shellSize.height)/2+parentSize.y; + } else { + locationX = (Toolkit.getDefaultToolkit().getScreenSize().width - shellSize.width) / 4; + locationY = (Toolkit.getDefaultToolkit().getScreenSize().height - shellSize.height) / 4; + } + selectItemsShell.setLocation(new Point(locationX, locationY)); + + Composite selectItemsComposite = new Composite(selectItemsShell, SWT.NONE); + selectItemsComposite.setBackground(BG_COLOR); + selectItemsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + selectItemsComposite.setLayout(new FormLayout()); + + Label label = new Label(selectItemsComposite, SWT.WRAP | SWT.BORDER); + label.setText(message); + label.setBackground(BG_COLOR); + label.pack(); + FormData fd = new FormData(); + fd.top = new FormAttachment(0, 5); + fd.left = new FormAttachment(0, 5); + fd.right = new FormAttachment(100, -5); + label.setLayoutData(fd); + + Button okButton = new Button(selectItemsComposite, SWT.NONE); + okButton.setText("OK"); + fd = new FormData(); + fd.right = new FormAttachment(100, -5); + fd.bottom = new FormAttachment(100, -5); + okButton.setLayoutData(fd); + + + Table table = new Table(selectItemsComposite, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL| SWT.H_SCROLL); + table.setLinesVisible(true); + table.setHeaderVisible(true); + fd = new FormData(); + fd.top = new FormAttachment(label, 5); + fd.left = new FormAttachment(0, 5); + fd.right = new FormAttachment(100, -5); + fd.bottom = new FormAttachment(okButton, -5); + table.setLayoutData(fd); + + + TableColumn column = new TableColumn(table, SWT.NULL); + column.setWidth(10); + column = new TableColumn(table, SWT.NULL); + column.setText("Component"); + column.setWidth(100); + column = new TableColumn(table, SWT.NULL); + column.setText("Comment"); + column.setWidth(100); + + for (var entry : map.entrySet()) { + TableItem tableItem = new TableItem(table, SWT.NONE); + DBMetadata metadata = DBMetadata.getDBMetadata(entry.getKey()); + tableItem.setText(1, metadata.getDebugName()); + tableItem.setText(2, entry.getValue()); + } + + okButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent arg0) { + selectItemsShell.dispose(); + } + }); + + selectItemsComposite.layout(true); + selectItemsShell.layout(true); + selectItemsShell.open(); + + while (!selectItemsShell.isDisposed()) { // the shell window is disposed in the selectionListener (i.e. when the user clicks on it) + if (!display.readAndDispatch()) + display.sleep(); + } + restoreCursors(); + } + }); + + return null; + } + + + /*************** cursors ******************/ + protected static Stack> cursorsStack = new Stack>(); + + /** + * Sets the mouse cursor as WAIT + */ + public static void setWaitCursor() { + display.syncExec(new Runnable() { + @Override + public void run() { + Map cursors = new HashMap(); + for ( Shell shell: display.getShells() ) { + cursors.put(shell, shell.getCursor()); + shell.setCursor(CURSOR_WAIT); + } + cursorsStack.push(cursors); + } + }); + //refreshDisplay(); + } + + /** + * Restores the mouse cursor as it was before beeing set as WAIT + */ + public static void restoreCursors() { + display.syncExec(new Runnable() { + @Override + public void run() { + Map cursors = cursorsStack.pop(); + for ( Shell shell: display.getShells() ) { + Cursor cursor = (cursors==null) ? null : cursors.get(shell); + shell.setCursor(cursor==null ? CURSOR_ARROW : cursor); + } + } + }); + //refreshDisplay(); + } +} diff --git a/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java b/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java index 15a4694e..68743550 100644 --- a/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java +++ b/sources/src/org/archicontribs/database/connection/DBDatabaseConnection.java @@ -33,6 +33,7 @@ import org.archicontribs.database.DBPlugin; import org.archicontribs.database.DBTable; import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.data.DBChecksum; import org.archicontribs.database.data.DBDatabase; import org.archicontribs.database.data.DBImportMode; @@ -194,12 +195,12 @@ private void openConnection() throws SQLException { try { password = this.databaseEntry.getDecryptedPassword(); } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchPaddingException err) { - DBGui.popup(Level.ERROR, "Failed to decrypt the password.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to decrypt the password.", err); } // if the username is set but not the password, then we show a popup to ask for the password if ( DBPlugin.isEmpty(password) ) { - password = DBGui.passwordDialog("Please provide the database password", "Database password:"); + password = DBGuiUtils.passwordDialog("Please provide the database password", "Database password:"); if ( password == null ) { // password is null if the user clicked on cancel throw new SQLException("No password provided."); @@ -208,7 +209,7 @@ private void openConnection() throws SQLException { try { this.databaseEntry.setDecryptedPassword(password); } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchPaddingException err) { - DBGui.popup(Level.ERROR, "Failed to decrypt the password.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to decrypt the password.", err); } } } @@ -302,7 +303,7 @@ public boolean checkDatabase(DBGui dbGui) throws Exception { currentVersion = result.getInt("version"); } catch (@SuppressWarnings("unused") SQLException err) { // if the table does not exist - if ( !DBGui.question("We successfully connected to the database but it seems that it has not been initialized.\n\nDo you wish to intialize the database ?") ) + if ( !DBGuiUtils.question("We successfully connected to the database but it seems that it has not been initialized.\n\nDo you wish to intialize the database ?") ) throw new SQLException("Database not initialized."); createTables(dbGui); @@ -313,9 +314,9 @@ public boolean checkDatabase(DBGui dbGui) throws Exception { throw new SQLException("The database has got an unknown model version (is "+currentVersion+" but should be between 200 and "+databaseVersion+")"); if ( currentVersion != databaseVersion ) { - if ( DBGui.question("The database needs to be upgraded. You will not loose any data during this operation.\n\nDo you wish to upgrade your database ?") ) { + if ( DBGuiUtils.question("The database needs to be upgraded. You will not loose any data during this operation.\n\nDo you wish to upgrade your database ?") ) { upgradeDatabase(currentVersion); - DBGui.popup(Level.INFO, "Database successfully upgraded."); + DBGuiUtils.popup(Level.INFO, "Database successfully upgraded."); } else throw new SQLException("The database needs to be upgraded."); @@ -348,7 +349,7 @@ public String checkDatabaseStructure(DBGui dbGui) throws Exception { if ( dbGui != null ) dbGui.setMessage("Checking the database structure..."); else - DBGui.popup("Checking the database structure..."); + DBGuiUtils.showPopupMessage("Checking the database structure..."); if ( !isConnected() ) openConnection(); @@ -464,7 +465,7 @@ public String checkDatabaseStructure(DBGui dbGui) throws Exception { logger.debug(" found column "+indexName+" in primary key"); } } catch (SQLException err) { - DBGui.popup(Level.ERROR, "Failed to get table primary keys.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to get table primary keys.", err); return; } */ @@ -480,14 +481,14 @@ public String checkDatabaseStructure(DBGui dbGui) throws Exception { if ( dbGui != null ) dbGui.closeMessage(); else - DBGui.closePopup(); + DBGuiUtils.closePopupMessage(); } if ( dbGui != null ) { if ( !isDatabaseStructureCorrect ) - DBGui.popup(Level.WARN, "You may have a look to the following items in your database:\n" + message.toString()); + DBGuiUtils.popup(Level.WARN, "You may have a look to the following items in your database:\n" + message.toString()); else - DBGui.popup(Level.INFO, "Tables name successfully checked.\nColumns name and type successfully checked"); + DBGuiUtils.popup(Level.INFO, "Tables name successfully checked.\nColumns name and type successfully checked"); } if ( isDatabaseStructureCorrect ) @@ -508,7 +509,7 @@ private void createTables(DBGui dbGui) throws SQLException { if ( dbGui != null ) dbGui.setMessage("Creating necessary database tables ..."); else - DBGui.popup("Creating necessary database tables ..."); + DBGuiUtils.showPopupMessage("Creating necessary database tables ..."); if ( !isConnected() ) openConnection(); @@ -604,7 +605,7 @@ private void createTables(DBGui dbGui) throws SQLException { commit(); setAutoCommit(true); - DBGui.popup(Level.INFO,"The database has been successfully initialized."); + DBGuiUtils.popup(Level.INFO,"The database has been successfully initialized."); } catch (SQLException err) { rollback(); @@ -614,7 +615,7 @@ private void createTables(DBGui dbGui) throws SQLException { if ( dbGui != null ) dbGui.closeMessage(); else - DBGui.closePopup(); + DBGuiUtils.closePopupMessage(); } } @@ -873,7 +874,7 @@ private void upgradeDatabase(int version) throws Exception { try { checksum = DBChecksum.calculateChecksum(checksumBuilder); } catch (Exception err) { - DBGui.popup(Level.FATAL, "Failed to calculate models checksum.", err); + DBGuiUtils.popup(Level.FATAL, "Failed to calculate models checksum.", err); rollback(); return; } @@ -890,7 +891,7 @@ private void upgradeDatabase(int version) throws Exception { if ( dbVersion == 204 ) { addColumn(this.schemaPrefix+"views", "container_checksum", objectIDColumn.getType(), false, ""); - DBGui.popup("Please wait while calculating new checksum on views table."); + DBGuiUtils.showPopupMessage("Please wait while calculating new checksum on views table."); DBArchimateModel tempModel = new DBArchimateModel(); try ( DBDatabaseImportConnection importConnection = new DBDatabaseImportConnection(this) ) { @@ -912,7 +913,7 @@ private void upgradeDatabase(int version) throws Exception { } tempModel = null; - DBGui.closePopup(); + DBGuiUtils.closePopupMessage(); dbVersion = 205; } @@ -1035,7 +1036,7 @@ private void upgradeDatabase(int version) throws Exception { // - create metadata table // - drop columns source_connections and target_connections from views_objects and views_connections tables if ( dbVersion == 207 ) { - DBGui.popup("Please wait while converting data."); + DBGuiUtils.showPopupMessage("Please wait while converting data."); if ( logger.isDebugEnabled() ) logger.debug("Creating table "+this.schemaPrefix+"metadata"); executeRequest("CREATE TABLE "+this.schemaPrefix+"metadata (" @@ -1053,7 +1054,7 @@ private void upgradeDatabase(int version) throws Exception { dropColumn(this.schemaPrefix+"views_connections", "source_connections"); dropColumn(this.schemaPrefix+"views_connections", "target_connections"); - DBGui.closePopup(); + DBGuiUtils.closePopupMessage(); dbVersion = 208; } @@ -1107,7 +1108,7 @@ private void upgradeDatabase(int version) throws Exception { dropColumn(this.schemaPrefix+"views_objects", "hint_content"); // we need to recalculate the checksums - DBGui.popup("Please wait while re-calculating checksums on views_objects and views tables."); + DBGuiUtils.showPopupMessage("Please wait while re-calculating checksums on views_objects and views tables."); DBArchimateModel tempModel = new DBArchimateModel(); @@ -1137,7 +1138,7 @@ private void upgradeDatabase(int version) throws Exception { } tempModel = null; - DBGui.closePopup(); + DBGuiUtils.closePopupMessage(); dbVersion = 211; } @@ -1187,20 +1188,70 @@ private void upgradeDatabase(int version) throws Exception { } // convert from version 212 to 213 - // - rename "rank" column to "pos" in all tables + // - rename "rank" column to "pos" in all tables where required // - change "strength" column from varchar(20) to blob if ( dbVersion == 212 ) { if ( logger.isDebugEnabled() ) logger.debug("Renaming \"rank\" column to \"pos\" in all tables."); - renameColumn(this.schemaPrefix+"properties", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"metadata", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"features", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"elements_in_model", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"relationships_in_model", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"folders_in_model", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"views_in_model", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"views_objects_in_view", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"views_connections_in_view", "rank", "pos", integerColumn.getType()); - renameColumn(this.schemaPrefix+"bendpoints", "rank", "pos", integerColumn.getType()); + try { + renameColumn(this.schemaPrefix+"properties", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in properties table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" properties table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"metadata", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in metadata table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" metadata table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"features", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in features table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" features table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"elements_in_model", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in elements_in_model table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" elements_in_model table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"relationships_in_model", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in relationships_in_model table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" relationships_in_model table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"folders_in_model", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in folders_in_model table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" folders_in_model table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"views_in_model", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in views_in_model table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" views_in_model table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"views_objects_in_view", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in views_objects_in_view table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" views_objects_in_view table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"views_connections_in_view", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in views_connections_in_view table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" views_connections_in_view table unmodified"); + } + try { + renameColumn(this.schemaPrefix+"bendpoints", "rank", "pos", integerColumn.getType()); + if ( logger.isDebugEnabled() ) logger.debug(" column renamed in bendpoints table"); + } catch(@SuppressWarnings("unused") Exception ign) { + if ( logger.isDebugEnabled() ) logger.debug(" bendpoints table unmodified"); + } if ( logger.isDebugEnabled() ) logger.debug("Changing strength column of relationships table from varchr(20) to clob."); renameColumn(this.schemaPrefix+"relationships", "strength", "old_strength", strengthColumn.getType()); diff --git a/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java b/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java index 0ced680f..7867475f 100644 --- a/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java +++ b/sources/src/org/archicontribs/database/connection/DBDatabaseImportConnection.java @@ -394,7 +394,7 @@ public int countModelComponents(DBArchimateModel model) throws Exception { + " FROM "+this.schemaPrefix+"elements_in_model" + " JOIN "+this.schemaPrefix+"elements ON elements.id = element_id AND version = "+versionToImport + " WHERE model_id = ? AND model_version = ?" - + " GROUP BY element_id, parent_folder_id, version, class, name, type, "+this.toCharDocumentation+", properties, features, created_on, checksum, pos"; + + " GROUP BY element_id, parent_folder_id, version, class, name, type, "+this.toCharDocumentation+", profile, created_on, properties, features, checksum"; try (DBSelect resultElements = new DBSelect(this.databaseEntry.getName(), this.connection, "SELECT COUNT(*) AS countElements FROM ("+this.importElementsRequest+") elts", model.getId(), model.getInitialVersion().getVersion()) ) { resultElements.next(); this.countElementsToImport = resultElements.getInt("countElements"); @@ -407,7 +407,7 @@ public int countModelComponents(DBArchimateModel model) throws Exception { + " FROM "+this.schemaPrefix+"relationships_in_model" + " INNER JOIN "+this.schemaPrefix+"relationships ON id = relationship_id AND version = "+versionToImport + " WHERE model_id = ? AND model_version = ?" - + " GROUP BY relationship_id, parent_folder_id, version, class, name, "+this.toCharDocumentation+", source_id, target_id, "+this.toCharStrength+", access_type, is_directed, properties, features, created_on, checksum"; + + " GROUP BY relationship_id, parent_folder_id, version, class, name, "+this.toCharDocumentation+", source_id, target_id, "+this.toCharStrength+", access_type, is_directed, profile, created_on, properties, features, checksum"; try ( DBSelect resultRelationships = new DBSelect(this.databaseEntry.getName(), this.connection, "SELECT COUNT(*) AS countRelationships FROM ("+this.importRelationshipsRequest+") relts" ,model.getId() ,model.getInitialVersion().getVersion() @@ -731,7 +731,7 @@ public boolean importRelationships(DBArchimateModel model) throws Exception { if ( logger.isDebugEnabled() ) logger.debug(" Importing "+relationship.getClass().getSimpleName()+" \""+relationship.getName()+"\" version "+dbMetadata.getInitialVersion().getVersion()); IFolder folder = null; - if ( this.currentResultSetRelationships.getString("parent_folder_id") == null ) { + if ( this.currentResultSetRelationships.getString("parent_folder_id") != null ) { folder = model.getAllFolders().get(this.currentResultSetRelationships.getString("parent_folder_id")); } @@ -739,10 +739,10 @@ public boolean importRelationships(DBArchimateModel model) throws Exception { folder = model.getDefaultFolderForObject(relationship); } + folder.getElements().add(relationship); + // profile must be set AFTER it is inserted into a folder, else it is not yet in the model dbMetadata.addProfileId(this.currentResultSetRelationships.getString("profile")); - - folder.getElements().add(relationship); IArchimateConcept source = model.getAllElements().get(this.currentResultSetRelationships.getString("source_id")); IArchimateConcept target = model.getAllElements().get(this.currentResultSetRelationships.getString("target_id")); diff --git a/sources/src/org/archicontribs/database/data/DBChecksum.java b/sources/src/org/archicontribs/database/data/DBChecksum.java index 41edb6a0..8091a342 100644 --- a/sources/src/org/archicontribs/database/data/DBChecksum.java +++ b/sources/src/org/archicontribs/database/data/DBChecksum.java @@ -12,7 +12,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.model.DBMetadata; import org.eclipse.emf.ecore.EObject; @@ -348,7 +348,7 @@ public static String calculateChecksum(byte[] bytes) throws NoSuchAlgorithmExcep } } } catch (NoSuchAlgorithmException e) { - DBGui.popup(Level.ERROR, "Failed to calculate checksum.", e); + DBGuiUtils.popup(Level.ERROR, "Failed to calculate checksum.", e); throw e; } diff --git a/sources/src/org/archicontribs/database/menu/DBMenuComponentHistoryHandler.java b/sources/src/org/archicontribs/database/menu/DBMenuComponentHistoryHandler.java index aaa0ebe7..19fbcee4 100644 --- a/sources/src/org/archicontribs/database/menu/DBMenuComponentHistoryHandler.java +++ b/sources/src/org/archicontribs/database/menu/DBMenuComponentHistoryHandler.java @@ -11,7 +11,7 @@ import org.archicontribs.database.model.DBMetadata; import org.archicontribs.database.DBLogger; import org.archicontribs.database.DBPlugin; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -51,12 +51,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException { DBGuiComponentHistory componentHistory = new DBGuiComponentHistory(selectedComponent); componentHistory.run(); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot get history from database.", e); + DBGuiUtils.popup(Level.ERROR,"Cannot get history from database.", e); } } else { // in all other cases, we do not know how to get its history from the database - DBGui.popup(Level.ERROR, "Cannot get history of a "+selectedObject.getClass().getSimpleName()); + DBGuiUtils.popup(Level.ERROR, "Cannot get history of a "+selectedObject.getClass().getSimpleName()); return null; } diff --git a/sources/src/org/archicontribs/database/menu/DBMenuComponentImportHandler.java b/sources/src/org/archicontribs/database/menu/DBMenuComponentImportHandler.java index 438a47c0..de6f2e36 100644 --- a/sources/src/org/archicontribs/database/menu/DBMenuComponentImportHandler.java +++ b/sources/src/org/archicontribs/database/menu/DBMenuComponentImportHandler.java @@ -8,7 +8,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.GUI.DBGuiImportComponents; import org.archicontribs.database.model.DBArchimateModel; import org.eclipse.core.commands.AbstractHandler; @@ -72,7 +72,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { DBGuiImportComponents importComponent = new DBGuiImportComponents(model, view, folder, "Import a component"); importComponent.run(); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot import model", e); + DBGuiUtils.popup(Level.ERROR,"Cannot import model", e); } return null; } diff --git a/sources/src/org/archicontribs/database/menu/DBMenuConvertIdsHandler.java b/sources/src/org/archicontribs/database/menu/DBMenuConvertIdsHandler.java index aef80aa2..11c43ba1 100644 --- a/sources/src/org/archicontribs/database/menu/DBMenuConvertIdsHandler.java +++ b/sources/src/org/archicontribs/database/menu/DBMenuConvertIdsHandler.java @@ -8,7 +8,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBPlugin; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.model.DBArchimateModel; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -60,7 +60,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { DBArchimateModel model = (DBArchimateModel) ((IStructuredSelection)HandlerUtil.getCurrentSelection(event)).getFirstElement(); int idsReplaced = 0; - DBGui.popup("Checking IDs ..."); + DBGuiUtils.showPopupMessage("Checking IDs ..."); try { model.countAllObjects(); @@ -112,13 +112,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException { } } } catch (Exception e) { - DBGui.closePopup(); - DBGui.popup(Level.ERROR, "Could not convert the IDs.\n\n"+idsReplaced+" IDs have been replaced.", e); + DBGuiUtils.closePopupMessage(); + DBGuiUtils.popup(Level.ERROR, "Could not convert the IDs.\n\n"+idsReplaced+" IDs have been replaced.", e); return null; } - DBGui.closePopup(); - DBGui.popup(Level.INFO, idsReplaced+" IDs have been replaced."); + DBGuiUtils.closePopupMessage(); + DBGuiUtils.popup(Level.INFO, idsReplaced+" IDs have been replaced."); return null; } diff --git a/sources/src/org/archicontribs/database/menu/DBMenuElementReplaceHandler.java b/sources/src/org/archicontribs/database/menu/DBMenuElementReplaceHandler.java index 4bfb03a4..43f876c8 100644 --- a/sources/src/org/archicontribs/database/menu/DBMenuElementReplaceHandler.java +++ b/sources/src/org/archicontribs/database/menu/DBMenuElementReplaceHandler.java @@ -8,7 +8,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.GUI.DBGuiReplaceElement; import org.archicontribs.database.model.DBArchimateModel; import org.archicontribs.database.model.DBMetadata; @@ -51,7 +51,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { DBGuiReplaceElement replaceElement = new DBGuiReplaceElement((DBArchimateModel)element.getArchimateModel(), element, "Replace element"); replaceElement.run(); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot import model", e); + DBGuiUtils.popup(Level.ERROR,"Cannot import model", e); } return null; } diff --git a/sources/src/org/archicontribs/database/menu/DBMenuModelExportHandler.java b/sources/src/org/archicontribs/database/menu/DBMenuModelExportHandler.java index a274a3f2..e5498da5 100644 --- a/sources/src/org/archicontribs/database/menu/DBMenuModelExportHandler.java +++ b/sources/src/org/archicontribs/database/menu/DBMenuModelExportHandler.java @@ -8,7 +8,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.GUI.DBGuiExportModel; import org.archicontribs.database.model.DBArchimateModel; import org.eclipse.core.commands.AbstractHandler; @@ -51,7 +51,7 @@ else if ( selection instanceof AbstractEditPart ) { DBGuiExportModel exportModel = new DBGuiExportModel(exportedModel, "Export model"); exportModel.run(); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot export model", e); + DBGuiUtils.popup(Level.ERROR,"Cannot export model", e); } } diff --git a/sources/src/org/archicontribs/database/menu/DBMenuModelImportHandler.java b/sources/src/org/archicontribs/database/menu/DBMenuModelImportHandler.java index 4b717643..fd8a5f65 100644 --- a/sources/src/org/archicontribs/database/menu/DBMenuModelImportHandler.java +++ b/sources/src/org/archicontribs/database/menu/DBMenuModelImportHandler.java @@ -8,7 +8,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.GUI.DBGuiImportModel; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -30,7 +30,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { DBGuiImportModel importModel = new DBGuiImportModel("Import model"); importModel.run(); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot import model", e); + DBGuiUtils.popup(Level.ERROR,"Cannot import model", e); } return null; diff --git a/sources/src/org/archicontribs/database/menu/DBMenuShowDebugHandler.java b/sources/src/org/archicontribs/database/menu/DBMenuShowDebugHandler.java index 3006350b..fd422f82 100644 --- a/sources/src/org/archicontribs/database/menu/DBMenuShowDebugHandler.java +++ b/sources/src/org/archicontribs/database/menu/DBMenuShowDebugHandler.java @@ -8,7 +8,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.GUI.DBGuiShowDebug; import org.archicontribs.database.model.DBMetadata; import org.eclipse.core.commands.AbstractHandler; @@ -50,7 +50,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { // if the user clicked on a graphical object in a view component = (EObject) ((EditPart)selection).getModel(); } else { - DBGui.popup(Level.ERROR, "Do not know which component you selected."); + DBGuiUtils.popup(Level.ERROR, "Do not know which component you selected."); return null; } @@ -64,7 +64,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { DBGuiShowDebug showDebug = new DBGuiShowDebug(component, "Debugging information"); showDebug.run(); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Failed to show debugging information.", e); + DBGuiUtils.popup(Level.ERROR,"Failed to show debugging information.", e); } } diff --git a/sources/src/org/archicontribs/database/model/DBArchimateModel.java b/sources/src/org/archicontribs/database/model/DBArchimateModel.java index 75e0c95b..3db80293 100644 --- a/sources/src/org/archicontribs/database/model/DBArchimateModel.java +++ b/sources/src/org/archicontribs/database/model/DBArchimateModel.java @@ -10,6 +10,7 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -17,9 +18,10 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; import org.archicontribs.database.DBPlugin.CONFLICT_CHOICE; -import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.data.DBChecksum; import org.archicontribs.database.data.DBVersion; import org.archicontribs.database.model.commands.DBDeleteDiagramConnectionCommand; @@ -46,6 +48,7 @@ import com.archimatetool.model.IIdentifier; import com.archimatetool.model.INameable; import com.archimatetool.model.IProfile; +import com.archimatetool.model.IProfiles; import com.archimatetool.model.ModelVersion; import lombok.Getter; import lombok.Setter; @@ -153,7 +156,7 @@ public EObject searchComponentFromId(String idOfTheComponent) { /** * List of all elements in the model.
*
- * Set by the @countAllObjects method. + * Set by the @countAllObjects method
*
* We use LinkedHashMap as the order is important */ @@ -162,7 +165,7 @@ public EObject searchComponentFromId(String idOfTheComponent) { /** * List of all relationships in the model.
*
- * Set by the @countAllObjects method. + * Set by the @countAllObjects method
*
* We use LinkedHashMap as the order is important */ @@ -171,7 +174,7 @@ public EObject searchComponentFromId(String idOfTheComponent) { /** * List of all views in the model.
*
- * Set by the @countAllObjects method. + * Set by the @countAllObjects method
*
* We use LinkedHashMap as the order is important */ @@ -180,7 +183,7 @@ public EObject searchComponentFromId(String idOfTheComponent) { /** * List of all objects in the model views.
*
- * Set by the @countAllObjects method. + * Set by the @countAllObjects method
*
* We use LinkedHashMap as the order is important */ @@ -189,7 +192,7 @@ public EObject searchComponentFromId(String idOfTheComponent) { /** * List of all connections in the model views.
*
- * Set by the @countAllObjects method. + * Set by the @countAllObjects method
*
* We use LinkedHashMap as the order is important */ @@ -198,20 +201,36 @@ public EObject searchComponentFromId(String idOfTheComponent) { /** * List of all folders in the model.
*
- * Set by the @countAllObjects method. + * Set by the @countAllObjects method
*
* We use LinkedHashMap as the order is important */ @Getter private Map allFolders = new LinkedHashMap(); + /** + * List of all faulty eObjects found in the model.
+ *
+ * Set by the @countAllObjects method when calculateChecksum throws a nullPointerException.
+ *
+ * At the moment, Faulty objects can be either relationships or connections without source or target
+ *
+ * We use HaspMap as the order is not important + */ + @Getter private Map allFaultyObjects = new HashMap(); + /** * List of all profiles in the model.
*
- * Set by the @countAllObjects method. + * Set by the @countAllObjects method
*
* We use LinkedHashMap as the order is important */ @Getter private Map allProfiles = new LinkedHashMap(); + + /** + * List of the profiles usage. + */ + @Getter private Map> allProfilesUsages = new LinkedHashMap>(); /** * List of the source relationships that have been imported but not yet created. @@ -286,6 +305,8 @@ public byte[] getImage(String path) { public void resetCounters() { if ( logger.isDebugEnabled() ) logger.debug(" Reseting model's counters."); + this.allProfiles.clear(); + this.allProfilesUsages.clear(); this.allSourceRelationshipsToResolve.clear(); this.allTargetRelationshipsToResolve.clear(); this.allSourceConnectionsToResolve.clear(); @@ -297,6 +318,7 @@ public void resetCounters() { this.allViewConnections.clear(); this.allFolders.clear(); this.allConflicts.clear(); + this.allFaultyObjects.clear(); } /** @@ -331,15 +353,29 @@ private IFolder getFolder(EObject eObject, IFolder folder) { return null; } + + /** + * Counts the number of objects in the model.
+ * At the same time, we calculate the current checksums + * @throws NoSuchAlgorithmException + * @throws UnsupportedEncodingException + * @throws Exception + * @return true if all components have been counted, or false if inconstancy has been detected + */ + public boolean countAllObjects() throws NoSuchAlgorithmException, UnsupportedEncodingException, Exception { + return countAllObjects(true); + } /** * Counts the number of objects in the model.
* At the same time, we calculate the current checksums + * @param deleteFaultyComponents true if the method should ask the user which faulty component he wishes to delete, false if the faulty components are all kept * @throws NoSuchAlgorithmException * @throws UnsupportedEncodingException - * @throws Exception + * @throws Exception + * @return true if all components have been counted, or false if inconstancy has been detected */ - public void countAllObjects() throws NoSuchAlgorithmException, UnsupportedEncodingException, Exception { + public boolean countAllObjects(boolean deleteFaultyComponents) throws NoSuchAlgorithmException, UnsupportedEncodingException, Exception { // First, we reset all the counters as they can be be re-populated resetCounters(); @@ -357,19 +393,68 @@ public void countAllObjects() throws NoSuchAlgorithmException, UnsupportedEncodi this.allFolders.put(folder.getId(), folder); } - try { - for (IFolder folder: getFolders()) - countObject(folder, true); - for ( IProfile profile: getProfiles() ) - countObject(profile, true); - } catch (@SuppressWarnings("unused") NullPointerException err) { - // in case the NullPointerException is propagated here, then it means that the model was inconsistent and the user has hosen to delete the relationship or connection, so we need to re-count all the objects - countAllObjects(); + for (IFolder folder: getFolders()) + countObject(folder, true); + for ( IProfile profile: getProfiles() ) + countObject(profile, true); + + if ( !this.allFaultyObjects.isEmpty() ) { + if ( !deleteFaultyComponents ) + return false; + + CompoundCommand deleteCommand = new NonNotifyingCompoundCommand("remove inconsistant components"); + + // if here, it means that we detected relationships or connections that miss source or target. So we need to ask the user what to do with them (i.e. keep or delete them) + List faultyEObjectSelected = DBGuiUtils.selectItemsDialog("Faulty objects to Delete", "Hummm, that's weird ... We detetected inconcistencies in your model.\n\n Please choose the faulty components to delete from your model to fix those inconcistencies.", this.allFaultyObjects, false); + + for ( EObject objToBeDeleted: faultyEObjectSelected) { + // Stores the list of objects that needs to be removed from the model + Set toBeDeleted = new HashSet(); + + // We delete the object from the model, using a command that can be rolled-back + if (objToBeDeleted instanceof IArchimateElement) { + for (IDiagramModelObject obj : ((IArchimateElement)objToBeDeleted).getReferencingDiagramObjects()) + toBeDeleted.add(obj); + } else if ( objToBeDeleted instanceof IArchimateRelationship) { + for (IDiagramModelArchimateConnection conn : ((IArchimateRelationship)objToBeDeleted).getReferencingDiagramConnections()) + toBeDeleted.add(conn); + } + // then we delete the eObject itself + toBeDeleted.add(objToBeDeleted); + + // if the objToBeDeleted is an archimate element or relationship, we need to delete the corresponding graphical objects and connections in all the views + + for (EObject objectToDelete: toBeDeleted) { + if (objectToDelete instanceof IArchimateElement) + deleteCommand.add(new DeleteArchimateElementCommand((IArchimateElement)objectToDelete)); + else if ( objectToDelete instanceof IArchimateRelationship) + deleteCommand.add(new DeleteArchimateRelationshipCommand((IArchimateRelationship)objectToDelete)); + else if (objectToDelete instanceof IDiagramModelObject) + deleteCommand.add(new DBDeleteDiagramObjectCommand(this, (IDiagramModelObject)objectToDelete)); + else if (objectToDelete instanceof IDiagramModelConnection) + deleteCommand.add(new DBDeleteDiagramConnectionCommand(this, (IDiagramModelConnection)objectToDelete)); + } + } + + // execute the command to effectively delete the component from the model + if ( !deleteCommand.isEmpty() && deleteCommand.canExecute() ) + deleteCommand.execute(); + + DBGuiUtils.popup(Level.INFO, "The inconsitant components have been removed from your model.\n\nYou may use Archi's \"undo\" functionality to restore them if needed."); + + // we re-count components, without asking again if some faulty components remain + return countAllObjects(false); } + + // we return true to indicate that all model components have been counted correctly + return true; } - // the viewChecksum variable is a trick to include the connections checksums in the view checksum + /** + * The viewChecksum variable is a trick to include the connections checksums in the view checksum + */ private StringBuilder viewChecksum = null; + /** * Adds a specific object in the corresponding counter
* At the same time, we calculate the current checksums @@ -382,7 +467,7 @@ public void countAllObjects() throws NoSuchAlgorithmException, UnsupportedEncodi * @throws NullPointerException when the calculateChecksum method raised a NullPointerException and the corresponding eObject has been removed from the model */ @SuppressWarnings("null") - public String countObject(EObject eObject, boolean mustCalculateChecksum) throws NoSuchAlgorithmException, UnsupportedEncodingException, NullPointerException, Exception { + public String countObject(EObject eObject, boolean mustCalculateChecksum) throws NoSuchAlgorithmException, UnsupportedEncodingException, Exception { StringBuilder checksumBuilder = null; DBMetadata objectMetadata = getDBMetadata(eObject); int len = 0; @@ -394,46 +479,8 @@ public String countObject(EObject eObject, boolean mustCalculateChecksum) throws try { checksumBuilder = new StringBuilder(DBChecksum.calculateChecksum(eObject)); } catch (NullPointerException err) { - if ( DBGui.question("Hummm, that's weird !\n\nAn inconsistency has been detected on "+objectMetadata.getDebugName()+":\n "+err.getMessage()+"\n\nWhat do you wish to do ?\n - Ignore -> Keep the faulty component untouched and try to fix the issue manually\n - Delete -> Delete the faulty component to fix the model consistency", new String[] {"Ignore","Delete"}) == 0 ) { - // We must ignore the error, so we just set the checksum to empty (as we couldn't calculate it) - checksumBuilder = new StringBuilder(); - } else { - // We delete the object from the model, using a command that can be rolled-back - - // Stores the list of objects that needs to be removed from the model - Set toBeDeleted = new HashSet(); - - // if the eObject is an archimate element or relationship, we need to delete the corresponding graphical objects and connections in all the views - if (eObject instanceof IArchimateElement) { - for (IDiagramModelObject obj : ((IArchimateElement)eObject).getReferencingDiagramObjects()) - toBeDeleted.add(obj); - } else if ( eObject instanceof IArchimateRelationship) { - for (IDiagramModelArchimateConnection conn : ((IArchimateRelationship)eObject).getReferencingDiagramConnections()) - toBeDeleted.add(conn); - } - // then we delete the eObject itself - toBeDeleted.add(eObject); - - // loop that effectively delete things - CompoundCommand deleteCommand = new NonNotifyingCompoundCommand("inconsistant object"); - for (EObject objectToDelete: toBeDeleted) { - if (objectToDelete instanceof IArchimateElement) - deleteCommand.add(new DeleteArchimateElementCommand((IArchimateElement)objectToDelete)); - else if ( objectToDelete instanceof IArchimateRelationship) - deleteCommand.add(new DeleteArchimateRelationshipCommand((IArchimateRelationship)objectToDelete)); - else if (objectToDelete instanceof IDiagramModelObject) - deleteCommand.add(new DBDeleteDiagramObjectCommand(this, (IDiagramModelObject)objectToDelete)); - else if (objectToDelete instanceof IDiagramModelConnection) - deleteCommand.add(new DBDeleteDiagramConnectionCommand(this, (IDiagramModelConnection)objectToDelete)); - } - - // execute the command to effectively delete the component from the model - if ( deleteCommand.canExecute() ) - deleteCommand.execute(); - - // we forward the exception that the countAllObject can re-count - throw new NullPointerException("Components have been removed from the model."); - } + this.allFaultyObjects.put(eObject, err.getMessage()); + checksumBuilder = new StringBuilder(); } len = checksumBuilder.length(); } @@ -552,8 +599,20 @@ else if (objectToDelete instanceof IDiagramModelConnection) default: // here, the class is too detailed (Node, Artefact, BusinessActor, etc ...), so we use "instanceof" to distinguish elements from relationships if ( eObject instanceof IArchimateElement ) { this.allElements.put(((IIdentifier)eObject).getId(), (IArchimateElement)eObject); + for ( IProfile profile: ((IProfiles)eObject).getProfiles() ) { + List list = this.allProfilesUsages.get(profile); + if ( list == null ) list = new ArrayList(); + list.add((IProfiles)eObject); + this.allProfilesUsages.put(profile, list); + } } else if ( eObject instanceof IArchimateRelationship ) { this.allRelationships.put(((IIdentifier)eObject).getId(), (IArchimateRelationship)eObject); + for ( IProfile profile: ((IProfiles)eObject).getProfiles() ) { + List list = this.allProfilesUsages.get(profile); + if ( list == null ) list = new ArrayList(); + list.add((IProfiles)eObject); + this.allProfilesUsages.put(profile, list); + } } else { //we should never be there, but just in case ... throw new Exception("Unknown "+eObject.eClass().getName()+" object."); } @@ -791,9 +850,12 @@ public void resolveSourceAndTargetConnections() throws Exception { if ( source == null ) source = this.getAllViewObjects().get(getNewViewObjectId(entry.getValue())); - if ( source == null ) + if ( source == null ) { + logger.error("Failed to resolve source connection for "+getDBMetadata(connection).getDebugName()); throw new Exception("Failed to resolve source connection for "+getDBMetadata(connection).getDebugName()); + } + logger.trace("source connection resolved for "+DBMetadata.getDBMetadata(source).getDebugName()); connection.setSource(source); source.addConnection(connection); } @@ -807,10 +869,13 @@ public void resolveSourceAndTargetConnections() throws Exception { if ( target == null ) target = this.getAllViewObjects().get(getNewViewObjectId(entry.getValue())); - if ( target == null ) + if ( target == null ) { + logger.error("Failed to resolve target connection for "+getDBMetadata(connection).getDebugName()); throw new Exception("Failed to resolve target connection for "+getDBMetadata(connection).getDebugName()); + } - connection.setSource(target); + logger.trace("target connection resolved for "+DBMetadata.getDBMetadata(target).getDebugName()); + connection.setTarget(target); target.addConnection(connection); } diff --git a/sources/src/org/archicontribs/database/model/DBMetadata.java b/sources/src/org/archicontribs/database/model/DBMetadata.java index cbe14725..d84e5151 100644 --- a/sources/src/org/archicontribs/database/model/DBMetadata.java +++ b/sources/src/org/archicontribs/database/model/DBMetadata.java @@ -647,7 +647,6 @@ public Integer getImagePosition() { return null; } catch ( NoClassDefFoundError | ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException err) { - this.logger.trace("IIconic is not com.archimatetool.model.canvas.IIconic"); // com.archimatetool.model.canvas.IIconic class exists in Archi until version 4.8 } @@ -660,10 +659,11 @@ public Integer getImagePosition() { return null; } catch ( NoClassDefFoundError | ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException err) { - this.logger.trace("IIconic is not com.archimatetool.model.IIconic"); // com.archimatetool.model.IIconic class exists in Archi from version 4.9 } + this.logger.trace("IIconic is not com.archimatetool.model.canvas.IIconic nor com.archimatetool.model.IIconic"); + return null; } @@ -677,7 +677,6 @@ public void setImagePosition(Integer imagePosition) { return; } catch ( NoClassDefFoundError | ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException err) { - this.logger.trace("IIconic is not com.archimatetool.model.canvas.IIconic"); // com.archimatetool.model.canvas.IIconic class exists in Archi until version 4.8 } @@ -690,9 +689,10 @@ public void setImagePosition(Integer imagePosition) { return; } catch ( NoClassDefFoundError | ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException err) { - this.logger.trace("IIconic is not com.archimatetool.model.IIconic"); // com.archimatetool.model.IIconic class exists in Archi from version 4.9 } + + this.logger.trace("IIconic is not com.archimatetool.model.canvas.IIconic nor com.archimatetool.model.IIconic"); } // LineColor @@ -1107,6 +1107,17 @@ public int getNumberOfProfiles() { return 0; } + public String getConceptType() { + if ( this.component instanceof IProfile ) + return ((IProfile)this.component).getConceptType(); + return null; + } + + public void setConceptType(String conceptType) { + if ( this.component instanceof IProfile ) + ((IProfile)this.component).setConceptType(conceptType); + } + /** * Gets the DBMetadata associated with an archimate object. * @param obj the archimate object diff --git a/sources/src/org/archicontribs/database/model/commands/DBDeleteProfileCommand.java b/sources/src/org/archicontribs/database/model/commands/DBDeleteProfileCommand.java new file mode 100644 index 00000000..f9592922 --- /dev/null +++ b/sources/src/org/archicontribs/database/model/commands/DBDeleteProfileCommand.java @@ -0,0 +1,36 @@ +package org.archicontribs.database.model.commands; + +import java.util.List; + +import org.archicontribs.database.model.DBArchimateModel; +import org.eclipse.gef.commands.CompoundCommand; + +import com.archimatetool.editor.model.commands.RemoveListMemberCommand; +import com.archimatetool.model.IProfile; +import com.archimatetool.model.IProfiles; + +/** + * This class is base upon Archi class deleteProfileCommand. It calls Archi's RemoveListMemberCommand to delete a profile (ie specialization) in the model.
+ *
+ * It is necessary as Archi declares its own class as private so we cannot instantiate it :( + */ +public class DBDeleteProfileCommand extends CompoundCommand { + /** + * Deletes a profile in a model, including all the profile usages + * @param model + * @param profile + */ + public DBDeleteProfileCommand(DBArchimateModel model, IProfile profile) { + + // Delete profile from Model + add(new RemoveListMemberCommand(profile.getArchimateModel().getProfiles(), profile)); + + // Delete profile usages + List usages = model.getAllProfilesUsages().get(profile); + if(usages != null) { + for(IProfiles owner: usages) { + add(new RemoveListMemberCommand(owner.getProfiles(), profile)); + } + } + } +} diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java index 3dc59499..01b04a9a 100644 --- a/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java +++ b/sources/src/org/archicontribs/database/model/commands/DBImportElementFromIdCommand.java @@ -232,9 +232,11 @@ public void execute() { } } - if ( this.newFolder == null ) - metadata.setParentFolder(this.model.getDefaultFolderForObject(this.importedElement)); - else + if ( this.newFolder == null ) { + if ( this.oldFolder == null) + metadata.setParentFolder(this.model.getDefaultFolderForObject(this.importedElement)); + // else we keep the existing folder + } else metadata.setParentFolder(this.newFolder); if ( this.view != null && metadata.findConnectables(this.view).isEmpty() ) { diff --git a/sources/src/org/archicontribs/database/model/commands/DBImportProfileFromIdCommand.java b/sources/src/org/archicontribs/database/model/commands/DBImportProfileFromIdCommand.java new file mode 100644 index 00000000..af1f280c --- /dev/null +++ b/sources/src/org/archicontribs/database/model/commands/DBImportProfileFromIdCommand.java @@ -0,0 +1,195 @@ +/** + * This program and the accompanying materials + * are made available under the terms of the License + * which accompanies this distribution in the file LICENSE.txt + */ + +package org.archicontribs.database.model.commands; + +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.HashMap; + +import org.archicontribs.database.DBLogger; +import org.archicontribs.database.DBPlugin; +import org.archicontribs.database.connection.DBDatabaseImportConnection; +import org.archicontribs.database.data.DBImportMode; +import org.archicontribs.database.data.DBVersion; +import org.archicontribs.database.model.DBArchimateModel; +import org.archicontribs.database.model.DBMetadata; +import org.eclipse.gef.commands.Command; +import com.archimatetool.model.IArchimateFactory; +import com.archimatetool.model.IProfile; +import com.archimatetool.model.util.Logger; + +/** + * Command for importing a profile from it's ID. + * + * @author Herve Jouin + */ +public class DBImportProfileFromIdCommand extends Command implements IDBImportCommand { + private static final DBLogger logger = new DBLogger(DBImportProfileFromIdCommand.class); + + private IProfile importedProfile= null; + + private boolean commandHasBeenExecuted = false; // to avoid being executed several times + private Exception exception = null; + + private DBArchimateModel model = null; + + private String id; + private boolean mustCreateCopy; + private boolean isNew; + + // new values that are retrieved from the database + private HashMap newValues = null; + + // old values that need to be retain to allow undo + private DBVersion oldInitialVersion; + private DBVersion oldCurrentVersion; + private DBVersion oldDatabaseVersion; + private DBVersion oldLatestDatabaseVersion; + private String oldName = null; + private String oldConceptType = null; + + /** + * Imports a profile into the model
+ * @param importConnection connection to the database + * @param archimateModel model into which the profile will be imported + * @param idToImport id of the profile to import + * @param versionToImport version of the profile to import (0 if the latest version must be imported) + * @param importMode specifies if the profile must be copied or shared + */ + public DBImportProfileFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String idToImport, int versionToImport, DBImportMode importMode) { + this.model = archimateModel; + this.id = idToImport; + + if ( logger.isDebugEnabled() ) + logger.debug(" Importing profile id " + idToImport + " version " + versionToImport + " in " + importMode.getLabel()+"."); + + try { + // we get the new values from the database to allow execute and redo + this.newValues = importConnection.getObjectFromDatabase(idToImport, "IProfile", versionToImport); + + this.mustCreateCopy = importMode.shouldCreateCopy(null); + + if ( this.mustCreateCopy ) { + this.newValues.put("id", DBPlugin.createID()); + this.newValues.put("name", (String)this.newValues.get("name") + DBPlugin.INSTANCE.getPreferenceStore().getString("copySuffix")); + } + + if ( DBPlugin.isEmpty((String)this.newValues.get("name")) ) { + setLabel("import profile"); + } else { + if ( ((String)this.newValues.get("name")).length() > 20 ) + setLabel("import \""+((String)this.newValues.get("name")).substring(0,16)+"...\""); + else + setLabel("import \""+(String)this.newValues.get("name")+"\""); + } + } catch (Exception err) { + Logger.logError("Got Exception "+err.getMessage()); + this.importedProfile = null; + this.exception = err; + } + } + + @Override + public void execute() { + if ( this.commandHasBeenExecuted ) + return; // we do not execute it twice + + this.commandHasBeenExecuted = true; + + try { + this.importedProfile = this.model.getAllProfiles().get(this.id); + + if ( this.importedProfile == null ) { + this.importedProfile = IArchimateFactory.eINSTANCE.createProfile(); + this.model.getProfiles().add(this.importedProfile); + + this.isNew = true; + } else { + // we must save the old values to allow undo + DBMetadata dbMetadata = this.model.getDBMetadata(this.importedProfile); + + this.oldInitialVersion = dbMetadata.getInitialVersion(); + this.oldCurrentVersion = dbMetadata.getCurrentVersion(); + this.oldDatabaseVersion = dbMetadata.getDatabaseVersion(); + this.oldLatestDatabaseVersion = dbMetadata.getLatestDatabaseVersion(); + + this.oldName = dbMetadata.getName(); + this.oldConceptType = dbMetadata.getConceptType(); + + this.isNew = false; + } + + DBMetadata dbMetadata = this.model.getDBMetadata(this.importedProfile); + + if ( this.mustCreateCopy ) + dbMetadata.getInitialVersion().set(0, null, new Timestamp(Calendar.getInstance().getTime().getTime())); + else + dbMetadata.getInitialVersion().set((int)this.newValues.get("version"), (String)this.newValues.get("checksum"), (Timestamp)this.newValues.get("created_on")); + + dbMetadata.setId((String)this.newValues.get("id")); + dbMetadata.setName((String)this.newValues.get("name")); + dbMetadata.setConceptType((String)this.newValues.get("conceptType")); + + dbMetadata.getCurrentVersion().set(dbMetadata.getInitialVersion()); + dbMetadata.getDatabaseVersion().set(dbMetadata.getInitialVersion()); + dbMetadata.getLatestDatabaseVersion().set(dbMetadata.getInitialVersion()); + + if ( this.isNew ) + this.model.countObject(this.importedProfile, false); + + } catch (Exception err) { + Logger.logError("Got Exception "+err.getMessage()); + this.exception = err; + } + } + + @Override + public void undo() { + if ( !this.commandHasBeenExecuted ) + return; + + if ( this.importedProfile != null ) { + if ( this.isNew ) { + // if the profile has been created by the execute() method, we just delete it + this.model.getProfiles().remove(this.importedProfile); + + this.model.getAllProfiles().remove(this.importedProfile.getId()); + } else { + // else, we need to restore the old properties + DBMetadata dbMetadata = this.model.getDBMetadata(this.importedProfile); + + dbMetadata.getInitialVersion().set(this.oldInitialVersion); + dbMetadata.getCurrentVersion().set(this.oldCurrentVersion); + dbMetadata.getDatabaseVersion().set(this.oldDatabaseVersion); + dbMetadata.getLatestDatabaseVersion().set(this.oldLatestDatabaseVersion); + + dbMetadata.setName(this.oldName); + dbMetadata.setConceptType(this.oldConceptType); + } + } + + // we allow the command to be executed again + this.commandHasBeenExecuted = false; + } + + /** + * @return the element that has been imported by the command (of course, the command must have been executed before)
+ * if the value is null, the exception that has been raised can be get using {@link getException} + */ + @Override + public IProfile getImported() { + return this.importedProfile; + } + + /** + * @return the exception that has been raised during the import process, if any. + */ + @Override + public Exception getException() { + return this.exception; + } +} diff --git a/sources/src/org/archicontribs/database/model/propertysections/CanvasModelBlockSection.java b/sources/src/org/archicontribs/database/model/propertysections/CanvasModelBlockSection.java index 8a2533c4..e2e1c070 100644 --- a/sources/src/org/archicontribs/database/model/propertysections/CanvasModelBlockSection.java +++ b/sources/src/org/archicontribs/database/model/propertysections/CanvasModelBlockSection.java @@ -17,6 +17,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.GUI.DBGuiImportImage; import org.archicontribs.database.model.DBArchimateModel; import org.eclipse.emf.ecore.EObject; @@ -170,7 +171,7 @@ protected void chooseImage() { if ( guiImportImage.getImage() != null ) setImage(guiImportImage.getImage(), guiImportImage.getImagePath()); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot import image", e); + DBGuiUtils.popup(Level.ERROR,"Cannot import image", e); } } } diff --git a/sources/src/org/archicontribs/database/model/propertysections/DiagramModelImageSection.java b/sources/src/org/archicontribs/database/model/propertysections/DiagramModelImageSection.java index 2d398c81..c2aabd72 100644 --- a/sources/src/org/archicontribs/database/model/propertysections/DiagramModelImageSection.java +++ b/sources/src/org/archicontribs/database/model/propertysections/DiagramModelImageSection.java @@ -17,6 +17,7 @@ import org.apache.log4j.Level; import org.archicontribs.database.DBLogger; import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.GUI.DBGuiImportImage; import org.archicontribs.database.model.DBArchimateModel; import org.eclipse.emf.common.notify.Notification; @@ -181,7 +182,7 @@ protected void chooseImage() { if ( guiImportImage.getImage() != null ) setImage(guiImportImage.getImage(), guiImportImage.getImagePath()); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot import image", e); + DBGuiUtils.popup(Level.ERROR,"Cannot import image", e); } } } diff --git a/sources/src/org/archicontribs/database/preferences/DBDatabaseEntryTableEditor.java b/sources/src/org/archicontribs/database/preferences/DBDatabaseEntryTableEditor.java index 7aa816f4..354c91a9 100644 --- a/sources/src/org/archicontribs/database/preferences/DBDatabaseEntryTableEditor.java +++ b/sources/src/org/archicontribs/database/preferences/DBDatabaseEntryTableEditor.java @@ -23,6 +23,7 @@ import org.archicontribs.database.DBPlugin; import org.archicontribs.database.GUI.DBGui; import org.archicontribs.database.GUI.DBGuiAdminDatabase; +import org.archicontribs.database.GUI.DBGuiUtils; import org.archicontribs.database.connection.DBDatabaseImportConnection; import org.archicontribs.database.data.DBDatabase; import org.eclipse.jface.preference.FieldEditor; @@ -1076,7 +1077,7 @@ void newCallback() throws SQLException { */ void saveCallback() throws SQLException { if ( this.txtName.getText().isEmpty() ) { - DBGui.popup(Level.ERROR, "Please provide a name for your configuration."); + DBGuiUtils.popup(Level.ERROR, "Please provide a name for your configuration."); return; } @@ -1092,7 +1093,7 @@ void saveCallback() throws SQLException { tableItem = new TableItem(this.tblDatabases, SWT.NONE); } } catch (Exception e) { - DBGui.popup(Level.ERROR, "Please verify the information you provided", e); + DBGuiUtils.popup(Level.ERROR, "Please verify the information you provided", e); return; } tableItem.setText(this.txtName.getText()); @@ -1169,7 +1170,7 @@ void setDatabaseDetails(boolean editMode) { try { this.txtPassword.setText(databaseEntry.getDecryptedPassword()); } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchPaddingException err) { - DBGui.popup(Level.ERROR, "Failed to decrypt the password.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to decrypt the password.", err); this.txtPassword.setText(""); } this.btnExpertMode.setSelection(databaseEntry.isExpertMode()); @@ -1260,15 +1261,15 @@ void checkCallback() { try { databaseEntry = getDatabaseDetails(null); } catch (Exception e) { - DBGui.popup(Level.ERROR, "Please verify the information you provided", e); + DBGuiUtils.popup(Level.ERROR, "Please verify the information you provided", e); return; } try ( DBDatabaseImportConnection connection = new DBDatabaseImportConnection(databaseEntry) ) { connection.checkDatabase(null); - DBGui.popup(Level.INFO, "Database successfully checked."); + DBGuiUtils.popup(Level.INFO, "Database successfully checked."); } catch (Exception err) { - DBGui.popup(Level.ERROR, "Failed to check the database.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to check the database.", err); } } @@ -1280,7 +1281,7 @@ void adminCallback() { try { databaseEntry = getDatabaseDetails(null); } catch (Exception e) { - DBGui.popup(Level.ERROR, "Please verify the information you provided", e); + DBGuiUtils.popup(Level.ERROR, "Please verify the information you provided", e); return; } @@ -1293,7 +1294,7 @@ void adminCallback() { DBGuiAdminDatabase adminDatabase = new DBGuiAdminDatabase(connection, entries, "Administer database \""+databaseEntry.getName()+"\""); adminDatabase.run(); } catch (Exception e) { - DBGui.popup(Level.ERROR,"Cannot admin the database", e); + DBGuiUtils.popup(Level.ERROR,"Cannot admin the database", e); } } @@ -1419,7 +1420,7 @@ public void showOrHidePasswordCallback() { */ public void close() throws SQLException { if ( this.txtName.isVisible() && this.txtName.isEnabled() ) { - if ( DBGui.question("Do you wish to save or discard your currents updates ?", new String[] {"save", "discard"}) == 0 ) { + if ( DBGuiUtils.question("Do you wish to save or discard your currents updates ?", new String[] {"save", "discard"}) == 0 ) { saveCallback(); } } diff --git a/sources/src/org/archicontribs/database/preferences/DBPreferencePage.java b/sources/src/org/archicontribs/database/preferences/DBPreferencePage.java index ff17a98f..5f382779 100644 --- a/sources/src/org/archicontribs/database/preferences/DBPreferencePage.java +++ b/sources/src/org/archicontribs/database/preferences/DBPreferencePage.java @@ -14,6 +14,7 @@ import org.archicontribs.database.DBLogger; import org.archicontribs.database.DBPlugin; import org.archicontribs.database.GUI.DBGui; +import org.archicontribs.database.GUI.DBGuiUtils; import org.eclipse.jface.preference.*; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.util.PropertyChangeEvent; @@ -75,7 +76,7 @@ public class DBPreferencePage extends FieldEditorPreferencePage implements IWork private Button btnRemoveDirtyFlag; private Button btnCompareToDatabaseBeforeExport; private Button btnKeepPartiallyImportedModel; - private Button btnShoIdInContextMenu; + private Button btnShowIdInContextMenu; private Text txtCopySuffix; private Button btnTemplateImportMode; private Button btnSharedImportMode; @@ -110,9 +111,9 @@ protected void createFieldEditors() { this.tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); this.tabFolder.setBackground(DBGui.GROUP_BACKGROUND_COLOR); - // ******************************** */ - // * Behaviour tab **************** */ - // ******************************** */ + // ******************************** + // * Behaviour tab **************** + // ******************************** Composite behaviourComposite = new Composite(this.tabFolder, SWT.NULL); RowLayout rowLayout = new RowLayout(); rowLayout.type = SWT.VERTICAL; @@ -121,6 +122,7 @@ protected void createFieldEditors() { rowLayout.marginBottom = 5; rowLayout.justify = false; rowLayout.fill = false; + behaviourComposite.setLayoutData(rowLayout); behaviourComposite.setBackground(DBGui.GROUP_BACKGROUND_COLOR); @@ -151,7 +153,6 @@ protected void createFieldEditors() { versionValue.setLayoutData(fd); Button checkUpdateButton = new Button(grpVersion, SWT.NONE); - //checkUpdateButton.setBackground(DBGui.COMPO_BACKGROUND_COLOR); checkUpdateButton.setText("Check for update"); fd = new FormData(); fd.top = new FormAttachment(versionValue, -3, SWT.TOP); @@ -170,6 +171,7 @@ protected void createFieldEditors() { this.btnCheckForUpdateAtStartupButton.setText("Automatically check for update at startup"); fd = new FormData(); fd.top = new FormAttachment(versionLbl, 5); + fd.bottom = new FormAttachment(100, -3); fd.left = new FormAttachment(0, 10); this.btnCheckForUpdateAtStartupButton.setLayoutData(fd); this.btnCheckForUpdateAtStartupButton.setSelection(preferenceStore.getBoolean("checkForUpdateAtStartup")); @@ -182,20 +184,77 @@ protected void createFieldEditors() { this.table = new DBDatabaseEntryTableEditor("databases", "", behaviourComposite); addField(this.table); - - Group grpMiscellaneous = new Group(behaviourComposite, SWT.NONE); - grpMiscellaneous.setBackground(DBGui.COMPO_BACKGROUND_COLOR); - grpMiscellaneous.setText("Miscellaneous:"); - grpMiscellaneous.setLayout(new FormLayout()); - - gd = new GridData(); - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - grpMiscellaneous.setLayoutData(gd); - + + Group grpHelp = new Group(behaviourComposite, SWT.NONE); + grpHelp.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + grpHelp.setLayout(new FormLayout()); + grpHelp.setText("Online help: "); + + gd = new GridData(); + //gd.heightHint = 40; + gd.horizontalAlignment = GridData.FILL; + gd.grabExcessHorizontalSpace = true; + grpHelp.setLayoutData(gd); + + Label btnHelp = new Label(grpHelp, SWT.MULTI); + btnHelp.setText(" \n "); + //btnHelp.setBounds(11,10,30,30); + btnHelp.addListener(SWT.MouseEnter, new Listener() { @Override public void handleEvent(Event event) { DBPreferencePage.this.mouseOverHelpButton = true; btnHelp.redraw(); } }); + btnHelp.addListener(SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { DBPreferencePage.this.mouseOverHelpButton = false; btnHelp.redraw(); } }); + btnHelp.addPaintListener(new PaintListener() { + @Override + public void paintControl(PaintEvent e) + { + if ( DBPreferencePage.this.mouseOverHelpButton ) e.gc.drawRoundRectangle(0, 0, 29, 29, 10, 10); + e.gc.drawImage(DBGui.HELP_ICON, 2, 2); + } + }); + btnHelp.addListener(SWT.MouseUp, new Listener() { @Override public void handleEvent(Event event) { if ( DBPreferencePage.this.logger.isDebugEnabled() ) DBPreferencePage.this.logger.debug("Showing help: /"+DBPlugin.PLUGIN_ID+"/help/html/configurePlugin.html"); PlatformUI.getWorkbench().getHelpSystem().displayHelpResource("/"+DBPlugin.PLUGIN_ID+"/help/html/configurePlugin.html"); } }); + fd = new FormData(30,30); + fd.top = new FormAttachment(0, 11); + fd.bottom = new FormAttachment(0, 41); + fd.left = new FormAttachment(0, 10); + fd.right= new FormAttachment(0, 40); + btnHelp.setLayoutData(fd); + + Label helpLbl1 = new Label(grpHelp, SWT.NONE); + helpLbl1.setText("Please be informed that a help button like this one is available on every plugin window."); + helpLbl1.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(0, 10); + fd.left = new FormAttachment(btnHelp, 10); + helpLbl1.setLayoutData(fd); + + Label helpLbl2 = new Label(grpHelp, SWT.NONE); + helpLbl2.setText("The online help is also available at any time using the menu Help / Help content."); + helpLbl2.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + fd = new FormData(); + fd.top = new FormAttachment(helpLbl1, 5); + fd.left = new FormAttachment(btnHelp, 10); + helpLbl2.setLayoutData(fd); + + // ******************************** + // * Options tab ****************** + // ******************************** + Composite optionsComposite = new Composite(this.tabFolder, SWT.NONE); + optionsComposite.setLayout(new FormLayout()); + optionsComposite.setBackground(DBGui.GROUP_BACKGROUND_COLOR); + + TabItem optionsTabItem = new TabItem(this.tabFolder, SWT.NONE); + optionsTabItem.setText(" Options "); + optionsTabItem.setControl(optionsComposite); + + Group grpMiscellaneous = new Group(optionsComposite, SWT.NONE); + grpMiscellaneous.setLayout(new FormLayout()); + fd = new FormData(); + fd.top = new FormAttachment(0, 10); + fd.left = new FormAttachment(0, 10); + fd.right = new FormAttachment(100, -10); + fd.bottom = new FormAttachment(100, -10); + grpMiscellaneous.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnExportWithDefaultValues = new Button(grpMiscellaneous, SWT.CHECK); - this.btnExportWithDefaultValues.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnExportWithDefaultValues.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnExportWithDefaultValues.setText("Automatically start to export to default database"); this.btnExportWithDefaultValues.setSelection(preferenceStore.getBoolean("exportWithDefaultValues")); fd = new FormData(); @@ -204,7 +263,7 @@ protected void createFieldEditors() { this.btnExportWithDefaultValues.setLayoutData(fd); this.btnCloseIfSuccessful = new Button(grpMiscellaneous, SWT.CHECK); - this.btnCloseIfSuccessful.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnCloseIfSuccessful.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnCloseIfSuccessful.setText("Automatically close import and export windows on success"); this.btnCloseIfSuccessful.setSelection(preferenceStore.getBoolean("closeIfSuccessful")); fd = new FormData(); @@ -213,7 +272,7 @@ protected void createFieldEditors() { this.btnCloseIfSuccessful.setLayoutData(fd); this.btnShowZeroValues = new Button(grpMiscellaneous, SWT.CHECK); - this.btnShowZeroValues.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnShowZeroValues.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnShowZeroValues.setText("Show zero values on import and export windows"); this.btnShowZeroValues.setSelection(preferenceStore.getBoolean("showZeroValues")); fd = new FormData(); @@ -222,7 +281,7 @@ protected void createFieldEditors() { this.btnShowZeroValues.setLayoutData(fd); this.btnCheckMaxMemoryAtStartup = new Button(grpMiscellaneous, SWT.CHECK); - this.btnCheckMaxMemoryAtStartup.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnCheckMaxMemoryAtStartup.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnCheckMaxMemoryAtStartup.setText("Check max memory available at startup"); this.btnCheckMaxMemoryAtStartup.setSelection(preferenceStore.getBoolean("checkMaxMemory")); fd = new FormData(); @@ -231,7 +290,7 @@ protected void createFieldEditors() { this.btnCheckMaxMemoryAtStartup.setLayoutData(fd); this.btnCheckNotNullConstraintInDatabase = new Button(grpMiscellaneous, SWT.CHECK); - this.btnCheckNotNullConstraintInDatabase.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnCheckNotNullConstraintInDatabase.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnCheckNotNullConstraintInDatabase.setText("Check for NOT NULL constraints while checking database structure"); this.btnCheckNotNullConstraintInDatabase.setSelection(preferenceStore.getBoolean("checkNotNullConstraints")); fd = new FormData(); @@ -240,7 +299,7 @@ protected void createFieldEditors() { this.btnCheckNotNullConstraintInDatabase.setLayoutData(fd); this.btnRemoveDirtyFlag = new Button(grpMiscellaneous, SWT.CHECK); - this.btnRemoveDirtyFlag.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnRemoveDirtyFlag.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnRemoveDirtyFlag.setText("Remove model's dirty flag after successful export"); this.btnRemoveDirtyFlag.setSelection(preferenceStore.getBoolean("removeDirtyFlag")); fd = new FormData(); @@ -249,7 +308,7 @@ protected void createFieldEditors() { this.btnRemoveDirtyFlag.setLayoutData(fd); this.btnCompareToDatabaseBeforeExport = new Button(grpMiscellaneous, SWT.CHECK); - this.btnCompareToDatabaseBeforeExport.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnCompareToDatabaseBeforeExport.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnCompareToDatabaseBeforeExport.setText("Compare model to the database before export"); this.btnCompareToDatabaseBeforeExport.setSelection(preferenceStore.getBoolean("compareBeforeExport")); fd = new FormData(); @@ -258,7 +317,7 @@ protected void createFieldEditors() { this.btnCompareToDatabaseBeforeExport.setLayoutData(fd); this.btnKeepPartiallyImportedModel = new Button(grpMiscellaneous, SWT.CHECK); - this.btnKeepPartiallyImportedModel.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnKeepPartiallyImportedModel.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnKeepPartiallyImportedModel.setText("Keep partially imported model in case of error"); this.btnKeepPartiallyImportedModel.setSelection(!preferenceStore.getBoolean("deleteIfImportError")); fd = new FormData(); @@ -266,20 +325,20 @@ protected void createFieldEditors() { fd.left = new FormAttachment(0, 10); this.btnKeepPartiallyImportedModel.setLayoutData(fd); - this.btnShoIdInContextMenu = new Button(grpMiscellaneous, SWT.CHECK); - this.btnShoIdInContextMenu.setBackground(DBGui.COMPO_BACKGROUND_COLOR); - this.btnShoIdInContextMenu.setText("Show debugging information in context menu"); - this.btnShoIdInContextMenu.setSelection(preferenceStore.getBoolean("showIdInContextMenu")); + this.btnShowIdInContextMenu = new Button(grpMiscellaneous, SWT.CHECK); + this.btnShowIdInContextMenu.setBackground(DBGui.GROUP_BACKGROUND_COLOR); + this.btnShowIdInContextMenu.setText("Show debugging information in context menu"); + this.btnShowIdInContextMenu.setSelection(preferenceStore.getBoolean("showIdInContextMenu")); fd = new FormData(); fd.top = new FormAttachment(this.btnKeepPartiallyImportedModel, 5); fd.left = new FormAttachment(0, 10); - this.btnShoIdInContextMenu.setLayoutData(fd); + this.btnShowIdInContextMenu.setLayoutData(fd); Label lblCopySuffix = new Label(grpMiscellaneous, SWT.NONE); - lblCopySuffix.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + lblCopySuffix.setBackground(DBGui.GROUP_BACKGROUND_COLOR); lblCopySuffix.setText("Append suffix when import component in copy mode:"); fd = new FormData(); - fd.top = new FormAttachment(this.btnShoIdInContextMenu, 5); + fd.top = new FormAttachment(this.btnShowIdInContextMenu, 5); fd.left = new FormAttachment(0, 10); lblCopySuffix.setLayoutData(fd); @@ -291,14 +350,9 @@ protected void createFieldEditors() { fd.left = new FormAttachment(lblCopySuffix, 10); fd.right = new FormAttachment(lblCopySuffix, 150, SWT.RIGHT); this.txtCopySuffix.setLayoutData(fd); - - Group grpHelp = new Group(behaviourComposite, SWT.NONE); - grpHelp.setBackground(DBGui.COMPO_BACKGROUND_COLOR); - grpHelp.setLayout(new FormLayout()); - grpHelp.setText("Online help: "); Label lblDefaultImportMode = new Label(grpMiscellaneous, SWT.NONE); - lblDefaultImportMode.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + lblDefaultImportMode.setBackground(DBGui.GROUP_BACKGROUND_COLOR); lblDefaultImportMode.setText("Default components import mode:"); fd = new FormData(); fd.top = new FormAttachment(lblCopySuffix, 5); @@ -306,7 +360,7 @@ protected void createFieldEditors() { lblDefaultImportMode.setLayoutData(fd); this.btnTemplateImportMode = new Button(grpMiscellaneous, SWT.RADIO); - this.btnTemplateImportMode.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnTemplateImportMode.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnTemplateImportMode.setText("Template mode"); this.btnTemplateImportMode.setSelection(preferenceStore.getString("defaultImportMode").equals("template")); fd = new FormData(); @@ -315,7 +369,7 @@ protected void createFieldEditors() { this.btnTemplateImportMode.setLayoutData(fd); this.btnSharedImportMode = new Button(grpMiscellaneous, SWT.RADIO); - this.btnSharedImportMode.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnSharedImportMode.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnSharedImportMode.setText("Force shared mode"); this.btnSharedImportMode.setSelection(preferenceStore.getString("defaultImportMode").equals("shared")); fd = new FormData(); @@ -324,56 +378,15 @@ protected void createFieldEditors() { this.btnSharedImportMode.setLayoutData(fd); this.btnCopyImportMode = new Button(grpMiscellaneous, SWT.RADIO); - this.btnCopyImportMode.setBackground(DBGui.COMPO_BACKGROUND_COLOR); + this.btnCopyImportMode.setBackground(DBGui.GROUP_BACKGROUND_COLOR); this.btnCopyImportMode.setText("Force copy mode"); this.btnCopyImportMode.setSelection(preferenceStore.getString("defaultImportMode").equals("copy")); fd = new FormData(); fd.top = new FormAttachment(this.btnSharedImportMode, 0, SWT.CENTER); fd.left = new FormAttachment(this.btnSharedImportMode, 10); this.btnCopyImportMode.setLayoutData(fd); - - gd = new GridData(); - //gd.heightHint = 40; - gd.horizontalAlignment = GridData.FILL; - gd.grabExcessHorizontalSpace = true; - grpHelp.setLayoutData(gd); - - Label btnHelp = new Label(grpHelp, SWT.MULTI); - btnHelp.setText(" \n "); - //btnHelp.setBounds(11,10,30,30); - btnHelp.addListener(SWT.MouseEnter, new Listener() { @Override public void handleEvent(Event event) { DBPreferencePage.this.mouseOverHelpButton = true; btnHelp.redraw(); } }); - btnHelp.addListener(SWT.MouseExit, new Listener() { @Override public void handleEvent(Event event) { DBPreferencePage.this.mouseOverHelpButton = false; btnHelp.redraw(); } }); - btnHelp.addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent e) - { - if ( DBPreferencePage.this.mouseOverHelpButton ) e.gc.drawRoundRectangle(0, 0, 29, 29, 10, 10); - e.gc.drawImage(DBGui.HELP_ICON, 2, 2); - } - }); - btnHelp.addListener(SWT.MouseUp, new Listener() { @Override public void handleEvent(Event event) { if ( DBPreferencePage.this.logger.isDebugEnabled() ) DBPreferencePage.this.logger.debug("Showing help: /"+DBPlugin.PLUGIN_ID+"/help/html/configurePlugin.html"); PlatformUI.getWorkbench().getHelpSystem().displayHelpResource("/"+DBPlugin.PLUGIN_ID+"/help/html/configurePlugin.html"); } }); - fd = new FormData(30,30); - fd.top = new FormAttachment(0, 11); - fd.bottom = new FormAttachment(0, 41); - fd.left = new FormAttachment(0, 10); - fd.right= new FormAttachment(0, 40); - btnHelp.setLayoutData(fd); - - Label helpLbl1 = new Label(grpHelp, SWT.NONE); - helpLbl1.setText("Please be informed that a help button like this one is available on every plugin window."); - helpLbl1.setBackground(DBGui.COMPO_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(0, 10); - fd.left = new FormAttachment(btnHelp, 10); - helpLbl1.setLayoutData(fd); - - Label helpLbl2 = new Label(grpHelp, SWT.NONE); - helpLbl2.setText("The online help is also available at any time using the menu Help / Help content."); - helpLbl2.setBackground(DBGui.COMPO_BACKGROUND_COLOR); - fd = new FormData(); - fd.top = new FormAttachment(helpLbl1, 5); - fd.left = new FormAttachment(btnHelp, 10); - helpLbl2.setLayoutData(fd); + + grpMiscellaneous.layout(true); // ********************************* */ // * Logger tab ******************* */ @@ -407,7 +420,6 @@ public void paintControl(PaintEvent e) this.simpleModeGroup = new Group(this.loggerComposite, SWT.NONE); this.simpleModeGroup.setLayout(new GridLayout()); gd = new GridData(GridData.FILL_HORIZONTAL); - //gd.widthHint = 300; this.simpleModeGroup.setLayoutData(gd); this.simpleModeGroup.setBackground(DBGui.GROUP_BACKGROUND_COLOR); @@ -433,9 +445,10 @@ public void paintControl(PaintEvent e) addField(this.expertTextFieldEditor); // We activate the Eclipse Help framework - PlatformUI.getWorkbench().getHelpSystem().setHelp(getFieldEditorParent().getParent(), HELP_ID); - PlatformUI.getWorkbench().getHelpSystem().setHelp(behaviourComposite, HELP_ID); - PlatformUI.getWorkbench().getHelpSystem().setHelp(this.loggerComposite, HELP_ID); + PlatformUI.getWorkbench().getHelpSystem().setHelp(getFieldEditorParent().getParent(), HELP_ID); + PlatformUI.getWorkbench().getHelpSystem().setHelp(behaviourComposite, HELP_ID); + PlatformUI.getWorkbench().getHelpSystem().setHelp(optionsComposite, HELP_ID); + PlatformUI.getWorkbench().getHelpSystem().setHelp(this.loggerComposite, HELP_ID); showLogger(); @@ -507,7 +520,7 @@ public boolean performOk() { preferenceStore.setValue("removeDirtyFlag", this.btnRemoveDirtyFlag.getSelection()); preferenceStore.setValue("compareBeforeExport", this.btnCompareToDatabaseBeforeExport.getSelection()); preferenceStore.setValue("deleteIfImportError", !this.btnKeepPartiallyImportedModel.getSelection()); - preferenceStore.setValue("showIdInContextMenu", this.btnShoIdInContextMenu.getSelection()); + preferenceStore.setValue("showIdInContextMenu", this.btnShowIdInContextMenu.getSelection()); preferenceStore.setValue("copySuffix", this.txtCopySuffix.getText()); preferenceStore.setValue("defaultImportMode", this.btnTemplateImportMode.getSelection() ? "template" : (this.btnSharedImportMode.getSelection() ? "shared" : "copy")); @@ -548,13 +561,13 @@ public boolean performOk() { if ( this.logger.isDebugEnabled() ) this.logger.debug("Saving the preference store to disk."); preferenceStore.save(); } catch (IOException err) { - DBGui.popup(Level.ERROR, "Failed to save the preference store to disk.", err); + DBGuiUtils.popup(Level.ERROR, "Failed to save the preference store to disk.", err); } try { this.logger.configure(); } catch (Exception e) { - DBGui.popup(Level.ERROR, "Faied to configure logger", e); + DBGuiUtils.popup(Level.ERROR, "Faied to configure logger", e); } return true;