Skip to content

Commit

Permalink
v4.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
herve91 committed Apr 26, 2023
1 parent 727aa61 commit 4f256ff
Show file tree
Hide file tree
Showing 19 changed files with 261 additions and 299 deletions.
2 changes: 1 addition & 1 deletion sources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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.2
Bundle-Version: 4.9.3
Bundle-Vendor: Herve Jouin
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-11
Expand Down
5 changes: 0 additions & 5 deletions sources/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@
defaultHandler="org.archicontribs.database.menu.DBMenuShowDebugHandler"
id="org.archicontribs.database.showDebugCommand"
name="showDebugCommand">
</command>
<command
defaultHandler="org.archicontribs.database.menu.DBMenuConvertIdsHandler"
id="org.archicontribs.database.convertIdsCommand"
name="convertIdsCommand">
</command>
</extension>
<extension
Expand Down
26 changes: 17 additions & 9 deletions sources/src/org/archicontribs/database/DBPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
*
* v4.9.2 01/12/2021 Fix nullPointerExceptions when model has got null properties or features
*
* v4.9.3 08/12/2021 Fix created_on date for folders during export
* Ignore difference between null and empty string during comparison
* Fix created_by information on "get history" spreadsheet
* Fix Archimate concepts version on debug screens
* Fix Browse button which was not functioning on Preferences / Logger tab
* Few other GUI improvements
* Remove ID conversion from former size to new one as it is not needed anymore
*
* -----------------------------------------------------------------------------------------
*
* TO-DO list:
Expand Down Expand Up @@ -276,15 +284,15 @@ public IPersistentPreferenceStore getPreferenceStore() {
* <br><br>
* Replaces string.equals() to avoid nullPointerException
* @param str1 first string to compare
* @param str2 secong string to compare
* @param str2 second string to compare
* @return true if the strings are both null or have the same content, false if they are different
*/
public static boolean areEqual(String str1, String str2) {
if ( str1 == null )
return str2 == null;
if ( isEmpty(str1) )
return isEmpty(str2);

if ( str2 == null )
return false; // as str1 cannot be null at this stage
if ( isEmpty(str2) )
return false; // as str1 cannot be empty at this stage

return str1.equals(str2);
}
Expand All @@ -298,11 +306,11 @@ public static boolean areEqual(String str1, String str2) {
* @return true if the strings are both null or have the same content, false if they are different
*/
public static boolean areEqualIgnoreCase(String str1, String str2) {
if ( str1 == null )
return str2 == null;
if ( isEmpty(str1) )
return isEmpty(str2);

if ( str2 == null )
return false; // as str1 cannot be null at this stage
if ( isEmpty(str2) )
return false; // as str1 cannot be empty at this stage

return str1.equalsIgnoreCase(str2);
}
Expand Down
86 changes: 75 additions & 11 deletions sources/src/org/archicontribs/database/GUI/DBGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.archimatetool.model.FolderType;
import com.archimatetool.model.IAccessRelationship;
import com.archimatetool.model.IArchimateDiagramModel;
import com.archimatetool.model.IArchimateModel;
import com.archimatetool.model.IArchimateRelationship;
import com.archimatetool.model.IBorderObject;
import com.archimatetool.model.IBounds;
Expand All @@ -90,6 +91,7 @@
import com.archimatetool.model.ILineObject;
import com.archimatetool.model.ILockable;
import com.archimatetool.model.INameable;
import com.archimatetool.model.IProfiles;
import com.archimatetool.model.IProperties;
import com.archimatetool.model.ISketchModel;
import com.archimatetool.model.ITextAlignment;
Expand Down Expand Up @@ -612,9 +614,9 @@ protected void getDatabases(boolean mustIncludeNeo4j, String defaultDatabaseId,
if ( mustIncludeNeo4j || !databaseEntry.getDriver().equals(DBDatabase.NEO4J.getDriverName()) ) {
this.comboDatabases.add(databaseEntry.getName());
this.comboDatabaseEntries.add(databaseEntry);
if ( defaultDatabaseId != null && databaseEntry.getId().equals(defaultDatabaseId) )
if ( !DBPlugin.isEmpty(defaultDatabaseId) && databaseEntry.getId().equals(defaultDatabaseId) )
databaseToSelect = line;
if ( defaultDatabaseName != null && databaseToSelect != 0 && databaseEntry.getName().equals(defaultDatabaseName) )
else if ( !DBPlugin.isEmpty(defaultDatabaseName) && databaseEntry.getName().equals(defaultDatabaseName) )
databaseToSelect = line;
++line;
}
Expand All @@ -623,12 +625,10 @@ protected void getDatabases(boolean mustIncludeNeo4j, String defaultDatabaseId,
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 )
if ( databaseToSelect == -1 )
databaseToSelect = 0;
if ( databaseToSelect != -1 ) {
this.comboDatabases.select(databaseToSelect);
this.comboDatabases.notifyListeners(SWT.Selection, new Event()); // calls the databaseSelected() method
}
this.comboDatabases.select(databaseToSelect);
this.comboDatabases.notifyListeners(SWT.Selection, new Event()); // calls the databaseSelected() method
}
}
}
Expand Down Expand Up @@ -1185,10 +1185,12 @@ protected Boolean fillInCompareTable(Tree tree, TreeItem treeItem, EObject memor

TreeItem item = new TreeItem(tree, SWT.NONE);
item.setText(new String[] {"Version", String.valueOf(dbMetadata.getInitialVersion().getVersion()), String.valueOf(databaseObject.get("version"))});


areIdentical &= addItemToCompareTable(tree, treeItem, "Checksum", String.valueOf(dbMetadata.getInitialVersion().getChecksum()), String.valueOf(databaseObject.get("checksum")));

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")});
item.setText(new String[] {"Created by", dbMetadata.getInitialVersion().getUsername(), (String)databaseObject.get("created_by")});
}

if ( databaseObject.get("created_on") != null ) {
Expand All @@ -1199,10 +1201,21 @@ protected Boolean fillInCompareTable(Tree tree, TreeItem treeItem, EObject memor
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"));
// we replace the DBArchimateModel class name by a simple ArchimateModel
String className = memoryObject.getClass().getSimpleName();
if ( className.equals("DBArchimateModel") ) className = "ArchimateModel";
areIdentical &= addItemToCompareTable(tree, treeItem, "Class", className, (String)databaseObject.get("class"));

areIdentical &= addItemToCompareTable(tree, treeItem, "Name", ((INameable)memoryObject).getName(), (String)databaseObject.get("name"));

if (memoryObject instanceof IArchimateModel ) {
areIdentical &= addItemToCompareTable(tree, treeItem, "Purpose", ((IArchimateModel)memoryObject).getPurpose(), (String)databaseObject.get("purpose"));
// the note does not participate to the model comparison
addItemToCompareTable(tree, treeItem, "Note", "", (String)databaseObject.get("note"));
}

if ( memoryObject instanceof IDocumentable )
areIdentical &= addItemToCompareTable(tree, treeItem, "Documentation", ((IDocumentable)memoryObject).getDocumentation(), (String)databaseObject.get("documentation"));

Expand Down Expand Up @@ -1331,7 +1344,7 @@ protected Boolean fillInCompareTable(Tree tree, TreeItem treeItem, EObject memor
}
//Arrays.sort(componentBendpoints, this.integerComparator);www

// we get a list of properties from the database
// we get a list of bendpoints from the database
Integer[][] databaseBendpoints = new Integer[((ArrayList<DBBendpoint>)databaseObject.get("bendpoints")).size()][4];
int i = 0;
for (DBBendpoint bp: (ArrayList<DBBendpoint>)databaseObject.get("bendpoints") ) {
Expand Down Expand Up @@ -1370,6 +1383,57 @@ protected Boolean fillInCompareTable(Tree tree, TreeItem treeItem, EObject memor
}
}
}

// we show up the profiles if both exist
if ( databaseObject.containsKey("profiles") ) {
if ( memoryObject instanceof IProfiles && ((IProfiles)memoryObject).getProfiles().size() != 0) {
TreeItem profilesTreeItem;
if ( treeItem == null )
profilesTreeItem = new TreeItem(tree, SWT.NONE);
else
profilesTreeItem = new TreeItem(treeItem, SWT.NONE);
profilesTreeItem.setText("Spécializations");
profilesTreeItem.setExpanded(true);

// we get a sorted list of component's profiles
ArrayList<DBProperty> componentProfiles = new ArrayList<DBProperty>();
for (int i = 0; i < ((IProfiles)memoryObject).getProfiles().size(); ++i) {
componentProfiles.add(new DBProperty(((IProfiles)memoryObject).getProfiles().get(i).getName(), ((IProfiles)memoryObject).getProfiles().get(i).getImagePath()));
}
Collections.sort(componentProfiles, this.propertyComparator);

// we get a sorted list of profiles from the database
ArrayList<DBProperty> databaseProfiles = (ArrayList<DBProperty>)databaseObject.get("profiles");
Collections.sort(databaseProfiles, this.propertyComparator);

Collator collator = Collator.getInstance();
int indexComponent = 0;
int indexDatabase = 0;
int compare;
while ( (indexComponent < componentProfiles.size()) || (indexDatabase < databaseProfiles.size()) ) {
if ( indexComponent >= componentProfiles.size() )
compare = 1;
else {
if ( indexDatabase >= databaseProfiles.size() )
compare = -1;
else
compare = collator.compare(componentProfiles.get(indexComponent).getKey(), databaseProfiles.get(indexDatabase).getKey());
}

if ( compare == 0 ) { // both have got the same property
areIdentical &= addItemToCompareTable(tree, profilesTreeItem, componentProfiles.get(indexComponent).getKey(), componentProfiles.get(indexComponent).getValue(), databaseProfiles.get(indexDatabase).getValue());
++indexComponent;
++indexDatabase;
} else if ( compare < 0 ) { // only the component has got the property
areIdentical &= addItemToCompareTable(tree, profilesTreeItem, componentProfiles.get(indexComponent).getKey(), componentProfiles.get(indexComponent).getValue(), null);
++indexComponent;
} else { // only the database has got the property
areIdentical &= addItemToCompareTable(tree, profilesTreeItem, componentProfiles.get(indexDatabase).getKey(), null, databaseProfiles.get(indexDatabase).getValue());
++indexDatabase;
}
}
}
}

// we show up the properties if both exist
if ( databaseObject.containsKey("properties") ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.archicontribs.database.connection.DBDatabaseExportConnection;
import org.archicontribs.database.connection.DBDatabaseImportConnection;
import org.archicontribs.database.connection.DBSelect;
import org.archicontribs.database.data.DBChecksum;
import org.archicontribs.database.data.DBImportMode;
import org.archicontribs.database.model.commands.DBImportElementFromIdCommand;
import org.archicontribs.database.model.commands.DBImportFolderFromIdCommand;
Expand Down Expand Up @@ -51,6 +52,7 @@
import com.archimatetool.model.IDiagramModelObject;
import com.archimatetool.model.IFolder;
import com.archimatetool.model.ISketchModel;
import com.archimatetool.model.impl.ArchimateModel;

/**
* This class manages the GUI that shows a component history
Expand Down Expand Up @@ -83,10 +85,15 @@ public DBGuiComponentHistory(IArchimateModelObject component) throws Exception {

this.includeNeo4j = false;

((DBArchimateModel)this.selectedComponent.getArchimateModel()).countObject(component, true);

if ( logger.isDebugEnabled() ) logger.debug("Setting up GUI for showing history of "+DBMetadata.getDBMetadata(component).getDebugName()+" (plugin version "+DBPlugin.pluginVersion.toString()+").");

// we calculate the checksum of the component
if ( component instanceof ArchimateModel )
((DBArchimateModel)this.selectedComponent).getCurrentVersion().setChecksum(DBChecksum.calculateChecksum(this.selectedComponent));
else
((DBArchimateModel)this.selectedComponent.getArchimateModel()).countObject(component, true);


setCompoRight();
this.compoRightBottom.setVisible(true);
this.compoRightBottom.layout();
Expand Down Expand Up @@ -138,7 +145,12 @@ public void handleEvent(Event e) {
DBGuiComponentHistory.this.lblCompareComponents.setText("Versions are identical");
else
DBGuiComponentHistory.this.lblCompareComponents.setText("Versions are different (check highlighted lines):");

// the export button is activated if the component is different from the latest version in the database
// so the latest database version must be selected to activate the export button
DBGuiComponentHistory.this.btnExportModelVersion.setEnabled(!areIdentical.booleanValue() && DBGuiComponentHistory.this.tblVersions.getSelectionIndex() == 0);

// the import button is activated if the component is different from the selected version of the database
DBGuiComponentHistory.this.btnImportDatabaseVersion.setEnabled(!areIdentical.booleanValue());
}
}
Expand All @@ -151,15 +163,15 @@ public void handleEvent(Event e) {
this.tblVersions.setLayoutData(fd);

TableColumn colVersion = new TableColumn(this.tblVersions, SWT.NONE);
colVersion.setWidth(47);
colVersion.setWidth(70);
colVersion.setText("Version");

TableColumn colCreatedBy = new TableColumn(this.tblVersions, SWT.NONE);
colCreatedBy.setWidth(121);
colCreatedBy.setWidth(150);
colCreatedBy.setText("Created by");

TableColumn colCreatedOn = new TableColumn(this.tblVersions, SWT.NONE);
colCreatedOn.setWidth(145);
colCreatedOn.setWidth(220);
colCreatedOn.setText("Created on");

this.lblCompareComponents = new Label(grpComponents, SWT.NONE);
Expand All @@ -183,15 +195,15 @@ public void handleEvent(Event e) {
this.tblContent.setLayoutData(fd);

TreeColumn colItem = new TreeColumn(this.tblContent, SWT.NONE);
colItem.setWidth(120);
colItem.setWidth(160);
colItem.setText("Items");

TreeColumn colYourVersion = new TreeColumn(this.tblContent, SWT.NONE);
colYourVersion.setWidth(220);
colYourVersion.setText("Your version");
colYourVersion.setWidth(320);
colYourVersion.setText("Local version");

TreeColumn colDatabaseVersion = new TreeColumn(this.tblContent, SWT.NONE);
colDatabaseVersion.setWidth(220);
colDatabaseVersion.setWidth(320);
colDatabaseVersion.setText("Database version");

this.btnImportDatabaseVersion = new Button(grpComponents, SWT.NONE);
Expand Down Expand Up @@ -230,7 +242,6 @@ else if ( importedComponent instanceof IArchimateDiagramModel || importedCompone
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) {
DBGuiUtils.popup(Level.ERROR, "Failed to import component.", err);
}
Expand All @@ -245,7 +256,7 @@ else if ( importedComponent instanceof IArchimateDiagramModel || importedCompone

this.btnExportModelVersion = new Button(grpComponents, SWT.NONE);
this.btnExportModelVersion.setImage(EXPORT_TO_DATABASE_IMAGE);
this.btnExportModelVersion.setText("Export your version to the database");
this.btnExportModelVersion.setText("Export local version to the database");
this.btnExportModelVersion.setEnabled(false);
this.btnExportModelVersion.addSelectionListener(new SelectionListener() {
@Override
Expand Down Expand Up @@ -292,7 +303,9 @@ protected void connectedToDatabase(boolean forceCheck) {
this.btnExportModelVersion.setEnabled(false);

String tableName = null;
if ( this.selectedComponent instanceof IArchimateElement )
if ( this.selectedComponent instanceof ArchimateModel )
tableName = "models";
else if ( this.selectedComponent instanceof IArchimateElement )
tableName = "elements";
else if ( this.selectedComponent instanceof IArchimateRelationship )
tableName = "relationships";
Expand Down Expand Up @@ -325,6 +338,7 @@ else if ( this.selectedComponent instanceof IDiagramModelConnection )
this.lblVersions.setText(this.tblVersions.getItemCount()+" versions have been found in the database:");
} else {
this.lblVersions.setText(this.tblVersions.getItemCount()+" version has been found in the database:");
this.lblCompareComponents.setText("");
}

if ( this.tblVersions.getItemCount() != 0 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,7 @@ public void widgetSelected(SelectionEvent e) {
@Override
public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); }
});
fd = new FormData(80,25);
fd = new FormData();
fd.right = new FormAttachment(100, -getDefaultMargin());
fd.bottom = new FormAttachment(100, -getDefaultMargin());
this.btnImportDatabaseVersion.setLayoutData(fd);
Expand All @@ -2885,7 +2885,7 @@ public void widgetSelected(SelectionEvent e) {
@Override
public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); }
});
fd = new FormData(80,25);
fd = new FormData();
fd.right = new FormAttachment(this.btnImportDatabaseVersion, -getDefaultMargin());
fd.bottom = new FormAttachment(100, -getDefaultMargin());
this.btnExportMyVersion.setLayoutData(fd);
Expand Down
Loading

0 comments on commit 4f256ff

Please sign in to comment.