├── MS SQL sqljdbc_auth.dll ├── README.md ├── version 11.2.0 (for plugin 4.9.6 and newer) │ ├── x64 │ │ └── mssql-jdbc_auth-11.2.0.x64.dll │ └── x86 │ │ └── mssql-jdbc_auth-11.2.0.x86.dll └── version 8.2.2 (for plugin up to 4.9.5) │ ├── x64 │ └── mssql-jdbc_auth-8.2.2.x64.dll │ └── x86 │ └── mssql-jdbc_auth-8.2.2.x86.dll ├── README.md ├── license.txt └── sources ├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.jdt.launching.prefs ├── META-INF └── MANIFEST.MF ├── build.properties ├── help ├── help.xml ├── html │ ├── componentsHistory.html │ ├── configurePlugin.html │ ├── databaseStructure.html │ ├── exportModel.html │ ├── importComponent.html │ ├── importModel.html │ ├── index.html │ ├── installPlugin.html │ ├── pluginObjectives.html │ ├── releaseNotes.html │ ├── showDebug.html │ └── style.css └── img │ ├── already-latest-version.png │ ├── archi-preferences-menu.png │ ├── archi-preferences-window.png │ ├── component-history.png │ ├── database-plugin-upgraded.png │ ├── database-successfully-initialized.png │ ├── databaseStructure.jpg │ ├── debugging-information.png │ ├── downloading-latest-version.png │ ├── export-gui.png │ ├── help.png │ ├── import-gui.png │ ├── import_individual_element.png │ ├── import_individual_model.png │ ├── import_individual_view.png │ ├── manage-plugins-menu.png │ ├── manage-plugins-restart.png │ ├── manage-plugins-window.png │ ├── model-up-to-date.png │ ├── new-version-available.png │ ├── new-version-downloaded.png │ ├── not_selected.png │ ├── please_wait_counting_model_s_components.png │ ├── please_wait_while_comparing_model_from_the_database.png │ ├── preferences-behaviour-tab.png │ ├── preferences-database-edition.png │ ├── preferences-databases-section.png │ ├── preferences-expert-mode.png │ ├── preferences-logger-disabled.png │ ├── preferences-logger-expertmode.png │ ├── preferences-logger-simplemode.png │ ├── preferences-logger-tab.png │ ├── preferences-neo4j-database.png │ ├── preferences-neo4j.png │ ├── preferences-online-help.png │ ├── preferences-options-tab.png │ ├── preferences-relational.png │ ├── preferences-sqlite-database.png │ ├── preferences-sqlite.png │ ├── preferences-version-section.png │ ├── request-initialize-database.png │ ├── selected.png │ ├── upgrade-database-plugin.png │ └── welcome-database-plugin.png ├── help_contexts.xml ├── img ├── 10x10 │ ├── bypassed.png │ ├── clock.png │ ├── error.png │ ├── lock.png │ ├── ok.png │ ├── right_arrow.png │ ├── unlock.png │ └── warning.png ├── 16x16 │ ├── debug.png │ ├── export.png │ ├── history.png │ ├── import.png │ └── replace.png ├── 22x22 │ ├── export.png │ └── import.png ├── 28x28 │ └── help.png ├── grey.png └── logo.png ├── lib ├── json-simple-1.1.1.jar ├── lombok.jar ├── mssql-jdbc-11.2.0.jre11.jar ├── mysql-connector-j-8.0.31.jar ├── neo4j-jdbc-driver-4.0.9.jar ├── ojdbc11.jar ├── orai18n-21.7.0.0.jar ├── postgresql-42.5.0.jar ├── reload4j-1.2.25.jar └── sqlite-jdbc-3.39.3.0.jar ├── plugin.xml └── src └── org └── archicontribs └── database ├── DBCheckAndUpdatePlugin.java ├── DBColumn.java ├── DBColumnType.java ├── DBDatabaseDriver.java ├── DBDatabaseEntry.java ├── DBException.java ├── DBExporter.java ├── DBImporter.java ├── DBLogger.java ├── DBPlugin.java ├── DBScript.java ├── DBTable.java ├── DropinsPluginHandler.java ├── commandline ├── DBExportModelProvider.java └── DBImportModelProvider.java ├── connection ├── DBDatabaseConnection.java ├── DBDatabaseExportConnection.java ├── DBDatabaseImportConnection.java ├── DBRequest.java ├── DBSelect.java └── DBStatement.java ├── data ├── DBBendpoint.java ├── DBChecksum.java ├── DBCompoundCommand.java ├── DBDatabase.java ├── DBImportMode.java ├── DBProfile.java ├── DBProperty.java ├── DBScreenshot.java └── DBVersion.java ├── gui ├── DBGui.java ├── DBGuiAdminDatabase.java ├── DBGuiComponentHistory.java ├── DBGuiExportModel.java ├── DBGuiImportComponents.java ├── DBGuiImportImage.java ├── DBGuiImportModel.java ├── DBGuiPasswordDialog.java ├── DBGuiReplaceElement.java ├── DBGuiShowDebug.java └── DBGuiUtils.java ├── help └── ApplicationActionBarAdvisor.java ├── menu ├── DBMenu.java ├── DBMenuComponentHistoryHandler.java ├── DBMenuComponentImportHandler.java ├── DBMenuElementReplaceHandler.java ├── DBMenuModelExportHandler.java ├── DBMenuModelImportHandler.java └── DBMenuShowDebugHandler.java ├── model ├── DBArchimateFactory.java ├── DBArchimateModel.java ├── DBMetadata.java ├── commands │ ├── DBDeleteDiagramConnectionCommand.java │ ├── DBDeleteDiagramObjectCommand.java │ ├── DBDeleteProfileCommand.java │ ├── DBImportElementFromIdCommand.java │ ├── DBImportFolderFromIdCommand.java │ ├── DBImportProfileFromIdCommand.java │ ├── DBImportRelationshipFromIdCommand.java │ ├── DBImportViewConnectionFromIdCommand.java │ ├── DBImportViewFromIdCommand.java │ ├── DBImportViewObjectFromIdCommand.java │ ├── DBResolveConnectionsCommand.java │ ├── DBResolveRelationshipsCommand.java │ ├── DBSetFolderToLastKnownCommand.java │ ├── IDBCommand.java │ └── IDBImportCommand.java └── propertysections │ ├── CanvasModelBlockSection.java │ ├── DBAbstractPropertySection.java │ ├── DiagramModelImageSection.java │ ├── IObjectFilter.java │ └── ObjectFilter.java └── preferences ├── DBDatabaseEntryTableEditor.java ├── DBFileFieldEditor.java ├── DBPreferencePage.java └── DBTextFieldEditor.java /MS SQL sqljdbc_auth.dll/README.md: -------------------------------------------------------------------------------- 1 | The mssql-jdbc_auth DLL file is necessary to enable the Active Directory integrated authentication of MS SQL Server. It must be copied in Archi's JRE/bin folder. You may use the one provided here or download it from Microsoft. Please pick up the DLL file corresponding to the version of the Archi plugin you're using (version 8.2.2 for plugin up to 4.9.5, version 11.2.0 for plugin 4.9.6 and newer), and to your computer architecture (x86 or x64). -------------------------------------------------------------------------------- /MS SQL sqljdbc_auth.dll/version 11.2.0 (for plugin 4.9.6 and newer)/x64/mssql-jdbc_auth-11.2.0.x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/MS SQL sqljdbc_auth.dll/version 11.2.0 (for plugin 4.9.6 and newer)/x64/mssql-jdbc_auth-11.2.0.x64.dll -------------------------------------------------------------------------------- /MS SQL sqljdbc_auth.dll/version 11.2.0 (for plugin 4.9.6 and newer)/x86/mssql-jdbc_auth-11.2.0.x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/MS SQL sqljdbc_auth.dll/version 11.2.0 (for plugin 4.9.6 and newer)/x86/mssql-jdbc_auth-11.2.0.x86.dll -------------------------------------------------------------------------------- /MS SQL sqljdbc_auth.dll/version 8.2.2 (for plugin up to 4.9.5)/x64/mssql-jdbc_auth-8.2.2.x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/MS SQL sqljdbc_auth.dll/version 8.2.2 (for plugin up to 4.9.5)/x64/mssql-jdbc_auth-8.2.2.x64.dll -------------------------------------------------------------------------------- /MS SQL sqljdbc_auth.dll/version 8.2.2 (for plugin up to 4.9.5)/x86/mssql-jdbc_auth-8.2.2.x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/MS SQL sqljdbc_auth.dll/version 8.2.2 (for plugin up to 4.9.5)/x86/mssql-jdbc_auth-8.2.2.x86.dll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Archimate Tool Database-Plugin 2 | Database export/import plugin that store models in a central repository. 3 | 4 | ### The plugin adds the following functionalities to Archi 5 | * Export and import models to a relational database (PostGreSQL, MySQL, MS SQL Server, Oracle or SQLite) 6 | * Export elements and relationships to a graph database (Neo4J) 7 | * Version the models and all their components (keep an history and allow to retrieve a former version) 8 | * Share elements, relationships and views between models 9 | 10 | -------------------------------------------------------------------------------- /sources/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sources/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /sources/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.archicontribs.database 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /sources/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.builder.cleanOutputFolder=clean 3 | org.eclipse.jdt.core.builder.duplicateResourceTask=error 4 | org.eclipse.jdt.core.builder.invalidClasspath=abort 5 | org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore 6 | org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch 7 | org.eclipse.jdt.core.circularClasspath=error 8 | org.eclipse.jdt.core.classpath.exclusionPatterns=enabled 9 | org.eclipse.jdt.core.classpath.mainOnlyProjectHasTestOnlyDependency=error 10 | org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled 11 | org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error 12 | org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled 13 | org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore 14 | org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull 15 | org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= 16 | org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault 17 | org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= 18 | org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable 19 | org.eclipse.jdt.core.compiler.annotation.nullable.secondary= 20 | org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled 21 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 22 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 23 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 24 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 25 | org.eclipse.jdt.core.compiler.compliance=11 26 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 27 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 28 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 29 | org.eclipse.jdt.core.compiler.doc.comment.support=enabled 30 | org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 31 | org.eclipse.jdt.core.compiler.problem.APILeak=error 32 | org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info 33 | org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=error 34 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 35 | org.eclipse.jdt.core.compiler.problem.autoboxing=ignore 36 | org.eclipse.jdt.core.compiler.problem.comparingIdentical=error 37 | org.eclipse.jdt.core.compiler.problem.deadCode=error 38 | org.eclipse.jdt.core.compiler.problem.deprecation=error 39 | org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled 40 | org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled 41 | org.eclipse.jdt.core.compiler.problem.discouragedReference=error 42 | org.eclipse.jdt.core.compiler.problem.emptyStatement=error 43 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 44 | org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=error 45 | org.eclipse.jdt.core.compiler.problem.fallthroughCase=error 46 | org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled 47 | org.eclipse.jdt.core.compiler.problem.fieldHiding=error 48 | org.eclipse.jdt.core.compiler.problem.finalParameterBound=error 49 | org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error 50 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=error 51 | org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=error 52 | org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled 53 | org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=error 54 | org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=error 55 | org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=error 56 | org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore 57 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled 58 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled 59 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled 60 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private 61 | org.eclipse.jdt.core.compiler.problem.localVariableHiding=error 62 | org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error 63 | org.eclipse.jdt.core.compiler.problem.missingDefaultCase=error 64 | org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=error 65 | org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=enabled 66 | org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=error 67 | org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning 68 | org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled 69 | org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public 70 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=all_standard_tags 71 | org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning 72 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled 73 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled 74 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private 75 | org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error 76 | org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled 77 | org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning 78 | org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=error 79 | org.eclipse.jdt.core.compiler.problem.noEffectAssignment=error 80 | org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=error 81 | org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore 82 | org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=error 83 | org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=error 84 | org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error 85 | org.eclipse.jdt.core.compiler.problem.nullReference=error 86 | org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error 87 | org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=error 88 | org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error 89 | org.eclipse.jdt.core.compiler.problem.parameterAssignment=error 90 | org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=error 91 | org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=error 92 | org.eclipse.jdt.core.compiler.problem.potentialNullReference=error 93 | org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning 94 | org.eclipse.jdt.core.compiler.problem.rawTypeReference=error 95 | org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=error 96 | org.eclipse.jdt.core.compiler.problem.redundantNullCheck=error 97 | org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore 98 | org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=error 99 | org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=error 100 | org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=error 101 | org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=enabled 102 | org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error 103 | org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=enabled 104 | org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled 105 | org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info 106 | org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled 107 | org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=error 108 | org.eclipse.jdt.core.compiler.problem.terminalDeprecation=error 109 | org.eclipse.jdt.core.compiler.problem.typeParameterHiding=error 110 | org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled 111 | org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore 112 | org.eclipse.jdt.core.compiler.problem.unclosedCloseable=error 113 | org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=error 114 | org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=error 115 | org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=error 116 | org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=enabled 117 | org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=error 118 | org.eclipse.jdt.core.compiler.problem.unnecessaryElse=error 119 | org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=error 120 | org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=error 121 | org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=error 122 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=error 123 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled 124 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled 125 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 126 | org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=error 127 | org.eclipse.jdt.core.compiler.problem.unusedImport=error 128 | org.eclipse.jdt.core.compiler.problem.unusedLabel=error 129 | org.eclipse.jdt.core.compiler.problem.unusedLocal=error 130 | org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=error 131 | org.eclipse.jdt.core.compiler.problem.unusedParameter=error 132 | org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled 133 | org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled 134 | org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled 135 | org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error 136 | org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=error 137 | org.eclipse.jdt.core.compiler.problem.unusedWarningToken=error 138 | org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error 139 | org.eclipse.jdt.core.compiler.release=enabled 140 | org.eclipse.jdt.core.compiler.source=11 141 | org.eclipse.jdt.core.incompatibleJDKLevel=info 142 | org.eclipse.jdt.core.incompleteClasspath=error 143 | -------------------------------------------------------------------------------- /sources/.settings/org.eclipse.jdt.launching.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.launching.PREF_COMPILER_COMPLIANCE_DOES_NOT_MATCH_JRE=error 3 | org.eclipse.jdt.launching.PREF_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE=error 4 | -------------------------------------------------------------------------------- /sources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Database export / import plugin for Archimate Tool 4 | Bundle-SymbolicName: org.archicontribs.database;singleton:=true 5 | Bundle-Version: 4.9.8 6 | Bundle-Vendor: Herve Jouin 7 | Bundle-Localization: plugin 8 | Bundle-RequiredExecutionEnvironment: JavaSE-17 9 | Bundle-ClassPath: ., 10 | lib/json-simple-1.1.1.jar, 11 | lib/lombok.jar, 12 | lib/mssql-jdbc-11.2.0.jre11.jar, 13 | lib/mysql-connector-j-8.0.31.jar, 14 | lib/ojdbc11.jar, 15 | lib/orai18n-21.7.0.0.jar, 16 | lib/postgresql-42.5.0.jar, 17 | lib/sqlite-jdbc-3.39.3.0.jar, 18 | lib/neo4j-jdbc-driver-4.0.9.jar, 19 | lib/reload4j-1.2.25.jar 20 | Bundle-ActivationPolicy: lazy 21 | Bundle-Activator: org.archicontribs.database.DBPlugin 22 | Require-Bundle: org.eclipse.core.runtime, 23 | com.archimatetool.editor, 24 | com.archimatetool.canvas, 25 | com.archimatetool.help, 26 | org.eclipse.swt, 27 | com.archimatetool.model, 28 | org.eclipse.emf.ecore, 29 | org.eclipse.help, 30 | com.archimatetool.commandline 31 | Export-Package: org.archicontribs.database 32 | Import-Package: org.eclipse.nebula.widgets.gallery 33 | -------------------------------------------------------------------------------- /sources/build.properties: -------------------------------------------------------------------------------- 1 | output.. = bin/ 2 | jars.compile.order = . 3 | bin.includes = META-INF/,\ 4 | plugin.xml,\ 5 | help/,\ 6 | img/,\ 7 | build.properties,\ 8 | help_contexts.xml,\ 9 | bin/,\ 10 | .,\ 11 | lib/,\ 12 | lib/neo4j-jdbc-driver-4.0.9.jar,\ 13 | lib/reload4j-1.2.25.jar 14 | src.includes = src/ 15 | source.. = src/ 16 | -------------------------------------------------------------------------------- /sources/help/help.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /sources/help/html/componentsHistory.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Preference page 7 | 8 | 9 | 10 | 11 |

Components history

12 | It is possible to gather any component's history in the database by selecting the get history option in the context menu (right click).
13 |
14 |
15 |
16 | It is possible to get the history from any database declared in the preference page: 17 | 22 | 23 | -------------------------------------------------------------------------------- /sources/help/html/exportModel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Model export 6 | 7 | 8 | 9 |

Export a model to a database

10 |
11 | This page describes how to export a model in a database.
12 |
13 | To export a model to a database, you first need to select the model to export, then either access the File / Export / Export model to database menu option of Archi, or right-click on the model's name and select the Export model to database context menu option.
14 |

The graphical interface

15 | As every window of the database plugin, the export window is split in 5 zones: 16 | 26 |
27 |
28 |

The database selection

29 | This section allows to select the database where the model should be exported. The databases are presented in the order defined on the preferences page and the first one is pre-selected as the default database.
30 |
31 | The Set preferences button allows to directly open the preference page to update the database list or set preferences.
32 |
33 | Please note that it is possible to export any model in any database, even if the model has been imported from another database or loaded from an Archimate file.
34 |

The model versions

35 | This section lists the versions of the model that already exist in the selected database. As every database is independent of the others, it may contain different versions of your model. Thus changing the database in the database selection drop list will of course impact the model versions.
36 |
37 | The "Now" line represents the version that will be exported in the database. It allows to change the model name and purpose, but also to set a release note to help remembering the changes that have been done in this model version.
38 |
39 |

The model's components

40 |

41 | This section shows statistics about the model, as it is in Archi and how it compares to the selected database.

42 |

The Total column indicates how many components are present in your current model in Archi.

43 |

If the plugin preferences states that the it should automatically compare the model to the database, then the other columns are filled in, otherwise they are empty. The Compare model to the database allows to (re)launch the comparison process and to fill-in the comparison columns. This comparison is read-only, it keeps your database untouched.

44 |

To achieve this comparison, the plugin uses Archi's internal IDs to check if those components already exists in the database. A checksum is automatically calculated by the plugin and allows to determine if the current component in Archi is identical or different from the database.

45 |

The Archi columns summarize how the current Archi model compares to the database:

46 | 51 |

The Database columns summarize are used in the situation where you and other people imported the same model in Archi and export their own model updates to the database while the other are still working on their own copy of the model. In this scenario, the columns summarize how the latest version of the model in the database compares to your current version in Archi:

52 | 57 |

A specific procedure is in place to detect and solve conflicts:

58 | 61 | 63 | At this stage, it is not possible to have more details about which components are new, updated, deleted or conflicting.
64 |
65 |

The export process

66 | When the user clicks on the "export" button, the plugin: 67 |
    68 |
  1. Recalculates the status of all the components as it may have changed since the last comparison,
  2. 69 |
  3. Imports missing components from the database and update those that have been updated in the database,
  4. 70 |
  5. Exports components that have been updated in Archi,
  6. 71 |
  7. References all the model components as been pat of the model (even those that do not need to be exported),
  8. 72 |
  9. If conflicts are detected, the user is invited to resolve them.
  10. 73 |
74 | As the export process may take some time, the databases list is replaced by a progress bar to show the export progress. 75 |
76 | At the end of the export process, the progress bar is replaced by a status message with a color that highlights the export status (green if successful, yellow in case of error). In case of any error, the export is rolled-back and the database is left untouched. This behavior allows to guarantee the database coherence.
77 |
78 | The export to the database cannot be undone, but in case some components have been imported or updated during the export process, the whole import/update can be undone using Archi undo/redo mechanism (menu Undo/Redo or keys ctrl-Z/ctrl-Y).
79 |
80 |

Version management

81 |

If the component does not exist in the database:

82 | 85 | If the component does exist in the database: 86 | 120 |

Conflict resolution

121 |


122 |

123 |

Undo / redo

124 | All the modifications done on your model during the export process, because of new, updated, deleted or conflicting components in the database, can be undone using the Ctrl-Z key or Archi's Edit / Undo menu, and redone using the Ctrl-Y key or Archi's Edit / Redo menu.
125 |
126 | Exports to a database cannot be undone. Nevertheless, as all models and components are versioned in the database, it is always possible to open a previous version of a model or a component. 127 | 128 | 129 | -------------------------------------------------------------------------------- /sources/help/html/importComponent.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Single component import 7 | 8 | 9 | 10 | 11 |

Import components from a database

12 | This page describes how to import components from a database.
13 |
14 | To import a component, you need to right-click on any existing model's component and select the Import components from database context menu option. 15 |
16 |

The graphical interface

17 | As every window of the database plugin, the export window is split in 5 zones: 18 | 26 |

The database selection

27 | This section allows to select the database from where the components should be imported. The databases are presented in the order defined on the preference page.
28 |
29 | The "set preferences" button allows to directly open the preference page to update the database list or set preferences.
30 |
31 | Please note that the Neo4j databases are not presented here as only exporting is supported to Neo4j databases. 32 |
33 |

The class of components to import

34 | At this stage, you need to choose if you wish to import a model (i.e. merge a model), an element or a view (at this time, folders are not supported):
35 | 36 |
37 | 38 |
39 | 40 |
41 | A filter allows to show up the components whose name contain the content of the filter (the case is ignored). It is possible to use the percent sign (%) as a wildcard.
42 |
43 | When the elements type is selected, you may choose as well the classes to list in the components table. You may select/unselect a class, a complete row or a complete column by clicking on it. Please be aware that the elements list can become huge, so it would be wise not to select too mny classes at the same time if you've got many elements in your database.
44 |
45 |

The components to import

46 | The bottom part of the window lists the models, elements or views that correspond to your choice. You may then select one or several of them.
47 |
48 | When a view is selected, a screenshot of the view is shown next to the table if the database contains views screenshots.When the mouse stands over a component, then a popup is shown with the component's properties (if it has got any).
49 |
50 | To import the selected component(s), you may either double click in the table or click on the "Import" button.
51 |

The import modes

52 | The import mode allows to specify how the components will be imported. Three modes are available: 53 | 61 | A "(copy)" mention is appended to all the components imported in copy mode. This mention can be modified or removed in the plugin's preferences. 62 |

Undo / redo

63 | All the imports can be undone using the Ctrl-Z key or Archi's menu, and redone using the Ctrl-Y key or Archi's menu. 64 | 65 | -------------------------------------------------------------------------------- /sources/help/html/importModel.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Model import 7 | 8 | 9 | 10 | 11 |

Import a model from a database

12 |
13 | This page describes how to import a model from a database.
14 |
15 | To import a model from a database, you can access the File / Import / Import model from database menu option of Archi, or if no model exist in Archi, right-click on model's tree area and select the Import model from database context menu option.
16 |

The graphical interface

17 | As every window of the database plugin, the import window is split in 5 zones: 18 | 27 |
28 |

The database selection

29 | This section allows to select the database from where the model should be imported. The databases are presented in the order defined on the preference page.
30 |
31 | The "set preferences" button allows to directly open the preference page to update the database list or set preferences.
32 |
33 | Please note that the Neo4j databases are not presented here as the plugin uniquely allows exports to Neo4j databases. 34 |
35 |

The models

36 | The models that are found in the database are presented in alphabetical order. A filter allows to limit the list to models having the specified string in their name (case insensitive). You may use the percent sign (%) as a wildcard. 37 |
38 |

The versions of the selected model

39 | Once you select a model, the versions of the selected model are displayed.
40 |
41 | Once on select a version, it's name, purpose and release note are displayed.
42 |
43 |

Importing a model

44 | It is possible to import a model by a double-click on the desired version, or by a simple click on the "Import" button: 45 | 49 | 50 | -------------------------------------------------------------------------------- /sources/help/html/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/html/index.html -------------------------------------------------------------------------------- /sources/help/html/installPlugin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Install the plugin 6 | 7 | 8 | 9 |

Install the plugin

10 |

Download the plugin from Github

11 |

The plugin is available on Github at the following address: https://github.com/archi-contribs/database-plugin/tree/master/v2

13 |

Please download the org.archicontribs.database_4.9.4.archiplugin file.

14 |

Install the plugin

15 |

The easiest way to install the plugin is to use Archi's integrated mechanism which is accessible through the Help / Manage Plug-ins... menu:

16 | Manage plug-ins menu 18 |


19 |

20 |

The Manage Archi Plug-ins window displays all the plugins installed in Archi. The procedure works the same to install a new plugin or update an existing plugin. Please click on the Install New ... button:

21 |

Manage plugins window

23 |


24 |

25 |

Please select the archiplugin file you've downloaded previously.

26 |

To complete the plugin installation, Archi needs to be restarted. Please click on the Yes button to restart Archi immediately, or press No if you prefer to restart later on.

27 |

Archi requires to restart
29 |

30 |

Once Archi restarts, a welcome message indicates if the plugin has been correctly installed:

31 | Welcome database plugin 33 |

Or upgraded:

34 |

Database plugin upgraded

36 |

Update the plugin

37 |

To update the plugin to a newer version, you may follow the same procedure used to install the plugin (ie download a new version of the archiplugin file and install it through Archi's Manage plugin-ins mechanism.

38 |

Alternatively, if your computer has got a direct access to the Internet, the plugin is able to automatically download updates from Github and install them. To activate this mechanism, please refer to the Version section of the preferences help page.

41 | 42 | 43 | -------------------------------------------------------------------------------- /sources/help/html/pluginObjectives.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Plugin objectives 7 | 8 | 9 | 10 | 11 |

Plugin's objectives

12 | The main objective of the database plugin, as its name states, is to use a database as a central model repository.
13 |
14 | The key functionalities are: 15 | 28 | 29 | -------------------------------------------------------------------------------- /sources/help/html/releaseNotes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release notes 6 | 7 | 8 | 9 |

Database plugin

10 |

Release notes

11 |
12 | This page describes the release notes of the 4.9.x branch. The release notes of previous branches can be found on Github. 13 |

v4.9.4 (04/01/2022)

14 | 23 |

v4.9.3 (16/12/2021)

24 | 33 |

v4.9.2 (01/12/2021)

34 | 37 |

v4.9.1 (30/06/2021)

38 | 41 |

v4.9.0 beta (16/10/2021)

42 | 51 |

v4.9.0 alpha (22/09/2021)

52 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /sources/help/html/showDebug.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Configure plugin 7 | 8 | 9 | 10 | 11 |

Debugging information

12 |
13 | The plugin can show detailed information any component in the model. 14 |
15 |
16 | This debugging information can be accessed using the context menu (right-click) of the component. 17 |
18 |
19 | 20 |
21 |
22 | You may choose a database to compare the component to the database content. 23 |
24 | The fields provided are: 25 | 40 |
41 | The array provides the following columns: 42 | 48 |
49 | These columns are provided for several states of the component: 50 | 69 |
70 | When the selected component is a graphical object or connection, the corresponding Archimate concept is also shown. 71 | -------------------------------------------------------------------------------- /sources/help/html/style.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/html/style.css -------------------------------------------------------------------------------- /sources/help/img/already-latest-version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/already-latest-version.png -------------------------------------------------------------------------------- /sources/help/img/archi-preferences-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/archi-preferences-menu.png -------------------------------------------------------------------------------- /sources/help/img/archi-preferences-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/archi-preferences-window.png -------------------------------------------------------------------------------- /sources/help/img/component-history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/component-history.png -------------------------------------------------------------------------------- /sources/help/img/database-plugin-upgraded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/database-plugin-upgraded.png -------------------------------------------------------------------------------- /sources/help/img/database-successfully-initialized.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/database-successfully-initialized.png -------------------------------------------------------------------------------- /sources/help/img/databaseStructure.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/databaseStructure.jpg -------------------------------------------------------------------------------- /sources/help/img/debugging-information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/debugging-information.png -------------------------------------------------------------------------------- /sources/help/img/downloading-latest-version.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/downloading-latest-version.png -------------------------------------------------------------------------------- /sources/help/img/export-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/export-gui.png -------------------------------------------------------------------------------- /sources/help/img/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/help.png -------------------------------------------------------------------------------- /sources/help/img/import-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/import-gui.png -------------------------------------------------------------------------------- /sources/help/img/import_individual_element.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/import_individual_element.png -------------------------------------------------------------------------------- /sources/help/img/import_individual_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/import_individual_model.png -------------------------------------------------------------------------------- /sources/help/img/import_individual_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/import_individual_view.png -------------------------------------------------------------------------------- /sources/help/img/manage-plugins-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/manage-plugins-menu.png -------------------------------------------------------------------------------- /sources/help/img/manage-plugins-restart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/manage-plugins-restart.png -------------------------------------------------------------------------------- /sources/help/img/manage-plugins-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/manage-plugins-window.png -------------------------------------------------------------------------------- /sources/help/img/model-up-to-date.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/model-up-to-date.png -------------------------------------------------------------------------------- /sources/help/img/new-version-available.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/new-version-available.png -------------------------------------------------------------------------------- /sources/help/img/new-version-downloaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/new-version-downloaded.png -------------------------------------------------------------------------------- /sources/help/img/not_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/not_selected.png -------------------------------------------------------------------------------- /sources/help/img/please_wait_counting_model_s_components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/please_wait_counting_model_s_components.png -------------------------------------------------------------------------------- /sources/help/img/please_wait_while_comparing_model_from_the_database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/please_wait_while_comparing_model_from_the_database.png -------------------------------------------------------------------------------- /sources/help/img/preferences-behaviour-tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-behaviour-tab.png -------------------------------------------------------------------------------- /sources/help/img/preferences-database-edition.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-database-edition.png -------------------------------------------------------------------------------- /sources/help/img/preferences-databases-section.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-databases-section.png -------------------------------------------------------------------------------- /sources/help/img/preferences-expert-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-expert-mode.png -------------------------------------------------------------------------------- /sources/help/img/preferences-logger-disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-logger-disabled.png -------------------------------------------------------------------------------- /sources/help/img/preferences-logger-expertmode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-logger-expertmode.png -------------------------------------------------------------------------------- /sources/help/img/preferences-logger-simplemode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-logger-simplemode.png -------------------------------------------------------------------------------- /sources/help/img/preferences-logger-tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-logger-tab.png -------------------------------------------------------------------------------- /sources/help/img/preferences-neo4j-database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-neo4j-database.png -------------------------------------------------------------------------------- /sources/help/img/preferences-neo4j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-neo4j.png -------------------------------------------------------------------------------- /sources/help/img/preferences-online-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-online-help.png -------------------------------------------------------------------------------- /sources/help/img/preferences-options-tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-options-tab.png -------------------------------------------------------------------------------- /sources/help/img/preferences-relational.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-relational.png -------------------------------------------------------------------------------- /sources/help/img/preferences-sqlite-database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-sqlite-database.png -------------------------------------------------------------------------------- /sources/help/img/preferences-sqlite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-sqlite.png -------------------------------------------------------------------------------- /sources/help/img/preferences-version-section.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/preferences-version-section.png -------------------------------------------------------------------------------- /sources/help/img/request-initialize-database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/request-initialize-database.png -------------------------------------------------------------------------------- /sources/help/img/selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/selected.png -------------------------------------------------------------------------------- /sources/help/img/upgrade-database-plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/upgrade-database-plugin.png -------------------------------------------------------------------------------- /sources/help/img/welcome-database-plugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/help/img/welcome-database-plugin.png -------------------------------------------------------------------------------- /sources/help_contexts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | You may select the Configure the plugin link below to get help about how to configure the database plugin. 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sources/img/10x10/bypassed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/bypassed.png -------------------------------------------------------------------------------- /sources/img/10x10/clock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/clock.png -------------------------------------------------------------------------------- /sources/img/10x10/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/error.png -------------------------------------------------------------------------------- /sources/img/10x10/lock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/lock.png -------------------------------------------------------------------------------- /sources/img/10x10/ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/ok.png -------------------------------------------------------------------------------- /sources/img/10x10/right_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/right_arrow.png -------------------------------------------------------------------------------- /sources/img/10x10/unlock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/unlock.png -------------------------------------------------------------------------------- /sources/img/10x10/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/10x10/warning.png -------------------------------------------------------------------------------- /sources/img/16x16/debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/16x16/debug.png -------------------------------------------------------------------------------- /sources/img/16x16/export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/16x16/export.png -------------------------------------------------------------------------------- /sources/img/16x16/history.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/16x16/history.png -------------------------------------------------------------------------------- /sources/img/16x16/import.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/16x16/import.png -------------------------------------------------------------------------------- /sources/img/16x16/replace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/16x16/replace.png -------------------------------------------------------------------------------- /sources/img/22x22/export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/22x22/export.png -------------------------------------------------------------------------------- /sources/img/22x22/import.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/22x22/import.png -------------------------------------------------------------------------------- /sources/img/28x28/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/28x28/help.png -------------------------------------------------------------------------------- /sources/img/grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/grey.png -------------------------------------------------------------------------------- /sources/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/img/logo.png -------------------------------------------------------------------------------- /sources/lib/json-simple-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/json-simple-1.1.1.jar -------------------------------------------------------------------------------- /sources/lib/lombok.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/lombok.jar -------------------------------------------------------------------------------- /sources/lib/mssql-jdbc-11.2.0.jre11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/mssql-jdbc-11.2.0.jre11.jar -------------------------------------------------------------------------------- /sources/lib/mysql-connector-j-8.0.31.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/mysql-connector-j-8.0.31.jar -------------------------------------------------------------------------------- /sources/lib/neo4j-jdbc-driver-4.0.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/neo4j-jdbc-driver-4.0.9.jar -------------------------------------------------------------------------------- /sources/lib/ojdbc11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/ojdbc11.jar -------------------------------------------------------------------------------- /sources/lib/orai18n-21.7.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/orai18n-21.7.0.0.jar -------------------------------------------------------------------------------- /sources/lib/postgresql-42.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/postgresql-42.5.0.jar -------------------------------------------------------------------------------- /sources/lib/reload4j-1.2.25.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/reload4j-1.2.25.jar -------------------------------------------------------------------------------- /sources/lib/sqlite-jdbc-3.39.3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/archi-contribs/database-plugin/09e7a62593674d8dc306de772f04d56a43a691bd/sources/lib/sqlite-jdbc-3.39.3.0.jar -------------------------------------------------------------------------------- /sources/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 11 | 12 | 13 | 15 | 19 | 20 | 21 | 23 | 27 | 28 | 29 | 31 | 34 | 35 | 36 | 38 | 42 | 46 | 47 | 51 | 52 | 53 | 57 | 58 | 62 | 63 | 67 | 68 | 72 | 73 | 77 | 78 | 82 | 83 | 84 | 86 | 90 | 91 | 95 | 96 | 100 | 101 | 105 | 106 | 107 | 109 | 113 | 114 | 118 | 119 | 120 | 122 | 125 | 126 | 127 | 129 | 132 | 133 | 134 | 136 | 138 | 144 | 145 | 151 | 152 | 153 | 154 | 156 | 161 | 162 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/DBColumnType.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database; 2 | 3 | /** 4 | * Database columns type 5 | * 6 | * @author Herve Jouin 7 | */ 8 | public enum DBColumnType { 9 | AUTO_INCREMENT, 10 | BOOLEAN, 11 | COLOR, 12 | DATETIME, 13 | FONT, 14 | IMAGE, 15 | INTEGER, 16 | OBJECTID, 17 | OBJ_NAME, 18 | STRENGTH, 19 | TEXT, 20 | TYPE, 21 | USERNAME; 22 | } 23 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/DBDatabaseDriver.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * Enumeration of all the database drivers managed by the database plugin. 7 | * 8 | * @author Herve Jouin 9 | */ 10 | public enum DBDatabaseDriver { 11 | MSSQL("ms-sql", "com.microsoft.sqlserver.jdbc.SQLServerDriver"), 12 | MYSQL("mysql", "com.mysql.cj.jdbc.Driver"), 13 | NEO4J("neo4j", "org.neo4j.jdbc.Driver"), 14 | ORACLE("oracle", "oracle.jdbc.driver.OracleDriver"), 15 | POSTGRESQL("postgresql", "org.postgresql.Driver"), 16 | SQLITE("sqlite", "org.sqlite.JDBC"); 17 | 18 | @Getter private String driverName = null; 19 | @Getter private String driverClass = null; 20 | 21 | /** 22 | * Sets the database driver name 23 | * @param dbName 24 | * @param dbClass 25 | */ 26 | private DBDatabaseDriver(String dbName, String dbClass) { 27 | this.driverName = dbName; 28 | this.driverClass = dbClass; 29 | } 30 | 31 | /** 32 | * Gets the DBDatabaseDriver by its name 33 | * @param dbName 34 | * @return the DBDatabaseDriver value 35 | */ 36 | public static DBDatabaseDriver fromName(String dbName) { 37 | switch (dbName.toLowerCase()) { 38 | case "ms-sql": return MSSQL; 39 | case "mysql": return MYSQL; 40 | case "neo4j": return NEO4J; 41 | case "oracle": return ORACLE; 42 | case "postgresql": return POSTGRESQL; 43 | case "sqlite": return SQLITE; 44 | default: // just in case 45 | } 46 | 47 | return null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/DBException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database; 8 | 9 | 10 | /** 11 | * The BDException class is an Exception class that is thrown each time there is an impossibility to import or export a component to the datatabase 12 | * 13 | * @author Herve Jouin 14 | */ 15 | public class DBException extends Exception { 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * Creates a new exception 20 | * @param message describes the error that is raised 21 | */ 22 | public DBException (String message) { 23 | super (message); 24 | } 25 | 26 | /** 27 | * Creates a new exception 28 | * @param cause describes the primary exception that causes this exception 29 | */ 30 | public DBException (Throwable cause) { 31 | super (cause); 32 | } 33 | 34 | /** 35 | * Creates a new exception 36 | * @param message describes the error that is raised 37 | * @param cause describes the primary exception that causes this exception 38 | */ 39 | public DBException (String message, Throwable cause) { 40 | super (message, cause); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/DBExporter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database; 8 | 9 | import java.io.IOException; 10 | 11 | import org.apache.log4j.Level; 12 | import org.archicontribs.database.gui.DBGuiExportModel; 13 | import org.archicontribs.database.gui.DBGuiUtils; 14 | import org.archicontribs.database.model.DBArchimateModel; 15 | import com.archimatetool.editor.model.IModelExporter; 16 | import com.archimatetool.model.IArchimateModel; 17 | 18 | /** 19 | * Database Model Exporter. This class exports the model components into a central repository (database). 20 | * 21 | * @author Herve Jouin 22 | */ 23 | public class DBExporter implements IModelExporter { 24 | private static final DBLogger logger = new DBLogger(DBExporter.class); 25 | 26 | /** 27 | * Exports the model into the database.
28 | * This method is called when the user clicks on the "Export / Export to database" menu entry of Archi 29 | */ 30 | @Override 31 | public void export(IArchimateModel archimateModel) throws IOException { 32 | logger.info("Exporting model "+archimateModel.getName()); 33 | 34 | try { 35 | DBGuiExportModel exportModel = new DBGuiExportModel((DBArchimateModel)archimateModel, "Export model"); 36 | exportModel.run(); 37 | } catch (Exception e) { 38 | DBGuiUtils.popup(Level.ERROR,"Cannot export model", e); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/DBImporter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database; 8 | 9 | import java.io.IOException; 10 | import java.lang.invoke.MethodHandles; 11 | 12 | import org.apache.log4j.Level; 13 | import org.archicontribs.database.gui.DBGuiImportModel; 14 | import org.archicontribs.database.gui.DBGuiUtils; 15 | 16 | import com.archimatetool.editor.model.IModelImporter; 17 | import com.archimatetool.editor.model.ISelectedModelImporter; 18 | import com.archimatetool.model.IArchimateModel; 19 | 20 | /** 21 | * Import from Database 22 | * 23 | * @author Herve Jouin 24 | */ 25 | public class DBImporter implements IModelImporter, ISelectedModelImporter { 26 | private static final DBLogger logger = new DBLogger(MethodHandles.lookup().lookupClass()); 27 | 28 | @Override 29 | public void doImport() throws IOException { 30 | doImport(null); 31 | } 32 | /** 33 | * Imports the model from the database.
34 | * This method is called when the user clicks on the "Import / Import from database" menu entry of Archi 35 | */ 36 | @Override 37 | public void doImport(IArchimateModel notUsed) throws IOException { 38 | logger.info("Importing model."); 39 | 40 | try { 41 | DBGuiImportModel importModel = new DBGuiImportModel("Import model"); 42 | importModel.run(); 43 | } catch (Exception e) { 44 | DBGuiUtils.popup(Level.ERROR,"Cannot import model", e); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/DBScript.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database; 2 | 3 | import java.io.IOException; 4 | import java.sql.SQLException; 5 | import java.util.List; 6 | 7 | import org.archicontribs.database.connection.DBDatabaseConnection; 8 | import org.archicontribs.database.connection.DBDatabaseImportConnection; 9 | import org.archicontribs.database.model.DBArchimateFactory; 10 | import org.archicontribs.database.model.DBArchimateModel; 11 | import org.archicontribs.database.model.DBMetadata; 12 | import org.eclipse.gef.commands.CommandStack; 13 | 14 | import com.archimatetool.editor.model.IArchiveManager; 15 | import com.archimatetool.editor.model.IEditorModelManager; 16 | import com.archimatetool.model.IArchimateModel; 17 | import com.archimatetool.model.IDiagramModel; 18 | 19 | /** 20 | * This class is an API for the script plugin 21 | * 22 | * @author Herve Jouin 23 | */ 24 | public class DBScript { 25 | private static final DBLogger logger = new DBLogger(DBDatabaseConnection.class); 26 | 27 | /** 28 | * Imports the latest version of a model 29 | * @param modelName name of the model top import 30 | * @param databaseName name of the database to import from, as stated in the list of databases on the plugin's preference page 31 | * @param force if true, allow to have another model with the same name, else, the model's name must be unique in Archi 32 | * @return the model 33 | * @throws DBException in case ofdatbase issue 34 | * @throws SQLException if the model cannot be imported 35 | * @throws IOException if the model cannot be closed (in case it cannot be imported) 36 | */ 37 | public static IArchimateModel importModel(String modelName, String databaseName, boolean force) throws DBException, SQLException, IOException { 38 | // we get the databases list from the preferences 39 | List databaseEntries = DBDatabaseEntry.getAllDatabasesFromPreferenceStore(); 40 | if ( (databaseEntries == null) || databaseEntries.isEmpty() ) 41 | throw new DBException("Cannot find any database."); 42 | 43 | // we get the database by its name 44 | DBDatabaseEntry databaseEntry = null; 45 | for ( DBDatabaseEntry entry: databaseEntries ) { 46 | if ( entry.getName().equals(databaseName) ) { 47 | databaseEntry = entry; 48 | break; 49 | } 50 | 51 | } 52 | 53 | // we check that the database exists 54 | if ( databaseEntry == null ) 55 | throw new DBException("Cannot find database \""+databaseName+"\""); 56 | 57 | // we connect to the database 58 | try ( DBDatabaseImportConnection connection = new DBDatabaseImportConnection(databaseEntry) ) { 59 | // we check if we are connected to the database 60 | if ( !connection.isConnected() ) 61 | throw new DBException("Cannot connect to the database \""+databaseName+"\""); 62 | 63 | // we check if the model exists in the database 64 | String modelId = connection.getModelId(modelName, false); 65 | 66 | if ( modelId == null ) 67 | throw new DBException("Cannot find model \""+ modelName +"\" in the database \""+databaseName+"\""); 68 | 69 | // we check that the model is not already in memory 70 | List allModels = IEditorModelManager.INSTANCE.getModels(); 71 | for ( IArchimateModel existingModel: allModels ) { 72 | if ( DBPlugin.areEqual(modelId, existingModel.getId()) ) 73 | throw new DBException("A model with ID \""+modelId+"\" is already opened."); 74 | if ( DBPlugin.areEqual(modelName, existingModel.getName()) && !force ) 75 | throw new DBException("A model with name \""+modelName+"\" is already opened."); 76 | } 77 | 78 | // we create the model 79 | DBArchimateModel modelToImport = (DBArchimateModel)DBArchimateFactory.eINSTANCE.createArchimateModel(); 80 | modelToImport.setId(modelId); 81 | modelToImport.setName(modelName); 82 | 83 | // awe create the model's archive manager 84 | modelToImport.setAdapter(IArchiveManager.class, IArchiveManager.FACTORY.createArchiveManager(modelToImport)); 85 | 86 | try { 87 | // at last, we import the model 88 | connection.importModel(modelToImport); 89 | 90 | if ( logger.isDebugEnabled() ) logger.debug("Importing the folders ..."); 91 | connection.prepareImportFolders(modelToImport); 92 | while ( connection.importFolders(modelToImport) ) { 93 | // each loop imports a folder 94 | } 95 | 96 | if ( logger.isDebugEnabled() ) logger.debug("Importing the elements ..."); 97 | connection.prepareImportElements(modelToImport); 98 | while ( connection.importElements(modelToImport) ) { 99 | // each loop imports an element 100 | } 101 | 102 | if ( logger.isDebugEnabled() ) logger.debug("Importing the relationships ..."); 103 | connection.prepareImportRelationships(modelToImport); 104 | while ( connection.importRelationships(modelToImport) ) { 105 | // each loop imports a relationship 106 | } 107 | 108 | modelToImport.resolveSourceAndTargetRelationships(); 109 | 110 | if ( logger.isDebugEnabled() ) logger.debug("Importing the views ..."); 111 | connection.prepareImportViews(modelToImport); 112 | while ( connection.importViews(modelToImport) ) { 113 | // each loop imports a view 114 | } 115 | 116 | if ( logger.isDebugEnabled() ) logger.debug("Importing the views objects ..."); 117 | for (IDiagramModel view: modelToImport.getAllViews().values()) { 118 | connection.prepareImportViewsObjects(view.getId(), DBMetadata.getDBMetadata(view).getInitialVersion().getVersion()); 119 | while ( connection.importViewsObjects(modelToImport, view) ) { 120 | // each loop imports a view object 121 | } 122 | } 123 | 124 | if ( logger.isDebugEnabled() ) logger.debug("Importing the views connections ..."); 125 | for (IDiagramModel view: modelToImport.getAllViews().values()) { 126 | connection.prepareImportViewsConnections(view.getId(), DBMetadata.getDBMetadata(view).getInitialVersion().getVersion()); 127 | while ( connection.importViewsConnections(modelToImport) ) { 128 | // each loop imports a view connection 129 | } 130 | } 131 | 132 | modelToImport.resolveSourceAndTargetConnections(); 133 | 134 | if ( logger.isDebugEnabled() ) logger.debug("Importing the images ..."); 135 | for (String path: connection.getAllImagePaths()) 136 | connection.importImage(modelToImport, path); 137 | } catch ( SQLException e) { 138 | // in case of an import error, we remove the newly created model, except if we are in force mode 139 | if ( !force ) { 140 | // we remove the 'dirty' flag (i.e. we consider the model as saved) because we do not want the closeModel() method ask to save it 141 | CommandStack stack = (CommandStack)modelToImport.getAdapter(CommandStack.class); 142 | if ( stack != null ) stack.markSaveLocation(); 143 | 144 | IEditorModelManager.INSTANCE.closeModel(modelToImport); 145 | } 146 | throw e; 147 | } 148 | // we add the new model in the manager 149 | IEditorModelManager.INSTANCE.registerModel(modelToImport); 150 | 151 | return modelToImport; 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/DBTable.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database; 2 | 3 | import java.util.List; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NonNull; 8 | import lombok.Setter; 9 | 10 | /** 11 | * 12 | * @author Herve Jouin 13 | * 14 | */ 15 | @AllArgsConstructor() 16 | @Getter 17 | @Setter 18 | public class DBTable { 19 | String schema; 20 | @NonNull String name; 21 | @NonNull List columns; 22 | List primaryKeys; 23 | 24 | /** 25 | * @return 26 | */ 27 | public String getFullName() { 28 | StringBuilder fullName = new StringBuilder(); 29 | if ( !DBPlugin.isEmpty(this.schema) ) { 30 | fullName.append(this.schema); 31 | fullName.append("."); 32 | } 33 | fullName.append(this.name); 34 | 35 | return fullName.toString(); 36 | } 37 | 38 | /** 39 | * @return 40 | */ 41 | public String generateCreateStatement() { 42 | StringBuilder tbls = new StringBuilder(); 43 | StringBuilder pkey = new StringBuilder(); 44 | 45 | for ( int i = 0 ; i < this.columns.size() ; ++i ) { 46 | if ( tbls.length() != 0 ) 47 | tbls.append(", "); 48 | DBColumn col = this.columns.get(i); 49 | tbls.append(col.getName()); 50 | tbls.append(" "); 51 | tbls.append(col.getFullType()); 52 | } 53 | 54 | if ( this.primaryKeys != null ) { 55 | for ( int i = 0 ; i < this.primaryKeys.size() ; ++i ) { 56 | if ( pkey.length() == 0 ) 57 | pkey.append(", PRIMARY KEY ("); 58 | else 59 | pkey.append(", "); 60 | String colPK = this.primaryKeys.get(i); 61 | pkey.append(colPK); 62 | } 63 | if ( pkey.length() != 0 ) 64 | pkey.append(")"); 65 | } 66 | 67 | StringBuilder createRequest = new StringBuilder("CREATE TABLE "); 68 | createRequest.append(getFullName()); 69 | createRequest.append(" ("); 70 | createRequest.append(tbls); 71 | createRequest.append(pkey); 72 | createRequest.append(")"); 73 | 74 | return createRequest.toString(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/commandline/DBExportModelProvider.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.commandline; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | import org.apache.commons.cli.Options; 8 | import org.archicontribs.database.DBPlugin; 9 | import org.archicontribs.database.gui.DBGuiExportModel; 10 | import org.archicontribs.database.model.DBArchimateModel; 11 | import com.archimatetool.commandline.AbstractCommandLineProvider; 12 | import com.archimatetool.commandline.CommandLineState; 13 | 14 | /** 15 | * Command Line interface to export a model to a database 16 | * 17 | * Typical usage: 18 | * Archi [-consoleLog] -application com.archimatetool.commandline.app --export.database "database name" [--export.releasenote "release note"] 19 | * 20 | * @author Herve Jouin 21 | */ 22 | public class DBExportModelProvider extends AbstractCommandLineProvider { 23 | static final String OPTION_EXPORT_DATABASE = "export.database"; 24 | static final String OPTION_EXPORT_RELEASENOTE = "export.releasenote"; 25 | 26 | /** 27 | * 28 | */ 29 | public DBExportModelProvider() { 30 | // nothing to do 31 | } 32 | 33 | @Override 34 | public void run(CommandLine commandLine) throws Exception { 35 | 36 | if( !commandLine.hasOption(OPTION_EXPORT_DATABASE) ) { 37 | // if the option is not present on the CommandLine, we do not have anything to do 38 | return; 39 | } 40 | 41 | // We check there is an active model 42 | DBArchimateModel modelToExport = DBArchimateModel.getDBArchimateModel(CommandLineState.getModel()); 43 | 44 | if(modelToExport == null) 45 | throw new IOException(getLogPrefix()+": There is no active model. You must load a model before trying to export it in a database."); 46 | 47 | String modelName = modelToExport.getName(); 48 | String databaseName = commandLine.getOptionValue(OPTION_EXPORT_DATABASE); 49 | String releaseNote = commandLine.getOptionValue(OPTION_EXPORT_RELEASENOTE); 50 | 51 | // we deactivate the database comparison at GUI startup 52 | DBPlugin.INSTANCE.getPreferenceStore().setValue("compareBeforeExport", false); 53 | 54 | // We activate the export GUI that is mandatory to export a model 55 | DBGuiExportModel guiExportModel = new DBGuiExportModel(modelToExport, "Export model"); 56 | 57 | // We set the database 58 | guiExportModel.getDatabases(true, null, databaseName); 59 | 60 | // we check if the database has been declared in Archi 61 | if ( (guiExportModel.getComboDatabases().getItemCount() == 0) || !(databaseName.equals(guiExportModel.getComboDatabases().getItem(guiExportModel.getComboDatabases().getSelectionIndex()))) ) 62 | throw new IOException(getLogPrefix()+": Database \""+databaseName+"\" is unknown. You must declare it in the plugin preferences before using the commandline interface."); 63 | 64 | // we count the model's components 65 | guiExportModel.getExportedModel().countAllObjects(); 66 | 67 | // we set the release note if provided 68 | if ( releaseNote != null ) 69 | guiExportModel.getTxtReleaseNote().setText(releaseNote); 70 | 71 | // we export the model 72 | switch ( guiExportModel.export() ) { 73 | case 1 : logMessage(getLogPrefix()+": The model \""+modelName+"\" has been exported to the \""+databaseName+"\" database."); break; 74 | case 0 : logMessage(getLogPrefix()+": The model \""+modelName+"\" does not need to be exported to the \""+databaseName+"\" database."); break; 75 | default : logError(getLogPrefix()+": Failed to export the model \""+modelName+"\" to the \""+databaseName+"\" database."); 76 | } 77 | } 78 | 79 | @Override 80 | public Options getOptions() { 81 | Options options = new Options(); 82 | 83 | Option option = Option.builder() 84 | .longOpt(OPTION_EXPORT_DATABASE) 85 | .hasArg().argName("exportDatabase") 86 | .desc("Name of the database (should already be configured in Archi through the database plugin preferences page)") 87 | .build(); 88 | options.addOption(option); 89 | 90 | option = Option.builder() 91 | .longOpt(OPTION_EXPORT_RELEASENOTE) 92 | .hasArg().argName("exportReleaseNote") 93 | .desc("Specifies the release note of the exported model") 94 | .build(); 95 | options.addOption(option); 96 | 97 | return options; 98 | } 99 | 100 | @Override 101 | public int getPriority() { 102 | return PRIORITY_REPORT_OR_EXPORT; 103 | } 104 | 105 | @Override 106 | protected String getLogPrefix() { 107 | return "DBPlugin Export CommandLine"; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/commandline/DBImportModelProvider.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.commandline; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.commons.cli.CommandLine; 6 | import org.apache.commons.cli.Option; 7 | import org.apache.commons.cli.Options; 8 | import org.archicontribs.database.DBPlugin; 9 | import org.archicontribs.database.gui.DBGuiImportModel; 10 | import org.eclipse.swt.SWT; 11 | import org.eclipse.swt.widgets.Event; 12 | import org.eclipse.swt.widgets.Table; 13 | import org.eclipse.swt.widgets.TableItem; 14 | 15 | import com.archimatetool.commandline.AbstractCommandLineProvider; 16 | import com.archimatetool.commandline.CommandLineState; 17 | 18 | /** 19 | * Command Line interface to import a model from a database 20 | * 21 | * Typical usage: 22 | * Archi [-consoleLog] -application com.archimatetool.commandline.app --import.database "database name" --import.model.name "model name" [--import.model.version "model version"] 23 | * 24 | * @author Herve Jouin 25 | */ 26 | public class DBImportModelProvider extends AbstractCommandLineProvider { 27 | static final String OPTION_IMPORT_DATABASE = "import.database"; 28 | static final String OPTION_IMPORT_MODEL = "import.model"; 29 | static final String OPTION_IMPORT_VERSION = "import.version"; 30 | 31 | /** 32 | * 33 | */ 34 | public DBImportModelProvider() { 35 | // nothing to do 36 | } 37 | 38 | @Override 39 | public void run(CommandLine commandLine) throws Exception { 40 | if( !commandLine.hasOption(OPTION_IMPORT_DATABASE) ) { 41 | // if the option is not present on the CommandLine, we do not have anything to do 42 | return; 43 | } 44 | 45 | String databaseName = commandLine.getOptionValue(OPTION_IMPORT_DATABASE); 46 | String modelName = commandLine.getOptionValue(OPTION_IMPORT_MODEL); 47 | int modelVersion = 0; 48 | 49 | // We check the options provided on the CommandLine 50 | if ( commandLine.hasOption(OPTION_IMPORT_VERSION) ) { 51 | try { 52 | modelVersion = Integer.valueOf(commandLine.getOptionValue(OPTION_IMPORT_VERSION)); 53 | } catch (NumberFormatException ign) { 54 | logError(getLogPrefix()+": parameter "+OPTION_IMPORT_MODEL+" should be a number"); 55 | if ( commandLine.hasOption("abortOnException") ) 56 | logError(getLogPrefix()+": parameter "+OPTION_IMPORT_MODEL+" defaulting to zero"); 57 | else 58 | throw ign; 59 | } 60 | } 61 | 62 | // We activate the import GUI that is mandatory to import a model 63 | // and set the database 64 | DBGuiImportModel guiImportModel = new DBGuiImportModel("Import model", databaseName); 65 | 66 | // we check if the database has been found in Archi preferences 67 | if ( (guiImportModel.getComboDatabases().getItemCount() == 0) || !(databaseName.equals(guiImportModel.getComboDatabases().getItem(guiImportModel.getComboDatabases().getSelectionIndex()))) ) 68 | throw new IOException(getLogPrefix()+": Database \""+databaseName+"\" is unknown. You must declare it in the plugin preferences before using the commandline interface."); 69 | 70 | // we check if the model exists in the database 71 | boolean modelFound = false; 72 | Table tblModels = guiImportModel.getTblModels(); 73 | for (int i = 0; i < tblModels.getItemCount(); ++i) { 74 | TableItem item = tblModels.getItem(i); 75 | if ( DBPlugin.areEqual(item.getText(0), modelName)) { 76 | // we select the model 77 | tblModels.select(i); 78 | // we get the model versions from the database 79 | tblModels.notifyListeners(SWT.Selection, new Event()); 80 | modelFound = true; 81 | break; 82 | } 83 | } 84 | if ( !modelFound ) 85 | throw new IOException(getLogPrefix()+": Model \""+modelName+"\" not found in the database \""+databaseName+"\""); 86 | 87 | // we check if the model version exists in the database 88 | boolean versionFound = false; 89 | if ( modelVersion == 0 ) { 90 | // if the model does exist, there is a latest version 91 | versionFound = true; 92 | } else { 93 | String modelVersionStr = String.valueOf(modelVersion); 94 | 95 | Table tblVersions = guiImportModel.getTblModelVersions(); 96 | for (int i = 0; i < tblVersions.getItemCount(); ++i) { 97 | TableItem item = tblVersions.getItem(i); 98 | if ( DBPlugin.areEqual(item.getText(0), modelVersionStr)) { 99 | // we select the version 100 | tblVersions.select(i); 101 | versionFound = true; 102 | break; 103 | } 104 | } 105 | } 106 | 107 | if ( !versionFound ) 108 | throw new IOException(getLogPrefix()+": Version \""+modelVersion+"\" of model \""+modelName+"\" not found in the database \""+databaseName+"\""); 109 | 110 | // we import the model 111 | guiImportModel.doImport(); 112 | 113 | // we set the imported model as the active model 114 | CommandLineState.setModel(guiImportModel.getModelToImport()); 115 | 116 | if ( modelVersion == 0 ) 117 | logMessage(getLogPrefix()+": Latest version of the model \""+modelName+"\" has been imported from the \""+databaseName+"\" database."); 118 | else 119 | logMessage(getLogPrefix()+": Version "+modelVersion+" the model \""+modelName+"\" has been imported from the \""+databaseName+"\" database."); 120 | } 121 | 122 | @Override 123 | public Options getOptions() { 124 | Options options = new Options(); 125 | 126 | Option option = Option.builder() 127 | .longOpt(OPTION_IMPORT_DATABASE) 128 | .hasArg().argName("importDatabase") 129 | .desc("Name of the database (should already be configured in Archi through the database plugin preferences page)") 130 | .build(); 131 | options.addOption(option); 132 | 133 | option = Option.builder() 134 | .longOpt(OPTION_IMPORT_MODEL) 135 | .hasArg().argName("importModel") 136 | .desc("Specifies the name of the model to import") 137 | .build(); 138 | options.addOption(option); 139 | 140 | option = Option.builder() 141 | .longOpt(OPTION_IMPORT_VERSION) 142 | .hasArg().argName("importVersion") 143 | .desc("Specifies the version of the model to import (if not specified, the latest version of the model will be imported)") 144 | .build(); 145 | options.addOption(option); 146 | 147 | return options; 148 | } 149 | 150 | @Override 151 | public int getPriority() { 152 | return PRIORITY_IMPORT; 153 | } 154 | 155 | @Override 156 | protected String getLogPrefix() { 157 | return "DBPlugin Import CommandLine"; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/connection/DBRequest.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.connection; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | //import org.archicontribs.database.DBLogger; 6 | 7 | import lombok.Getter; 8 | 9 | /** 10 | * Helper class that allows to execute a request upon a database 11 | * 12 | * @author Herve Jouin 13 | */ 14 | public class DBRequest extends DBStatement { 15 | //private static final DBLogger logger = new DBLogger(DBRequest.class); 16 | 17 | @Getter private int rowCount = 0; 18 | 19 | /** 20 | * wrapper to execute an INSERT or UPDATE request in the database
21 | * One may use '?' in the request and provide the corresponding values as parameters (strings, integers, booleans and byte[] are accepted) 22 | * @return the number of lines impacted by the request 23 | * @param 24 | * @param theDriverName 25 | * @param theConnection 26 | * @param theRequest 27 | * @param theParameters 28 | * @throws SQLException 29 | */ 30 | @SafeVarargs 31 | public DBRequest(String theDriverName, Connection theConnection, String theRequest, T... theParameters) throws SQLException { 32 | super(theDriverName, theConnection, theRequest, theParameters); 33 | 34 | this.rowCount = executeUpdate(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/connection/DBSelect.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.connection; 2 | 3 | import java.sql.Connection; 4 | import java.sql.Date; 5 | import java.sql.ResultSet; 6 | import java.sql.SQLException; 7 | import java.sql.Timestamp; 8 | 9 | import org.archicontribs.database.DBLogger; 10 | 11 | import lombok.Getter; 12 | 13 | /** 14 | * Helper class that allows to execute a SQL select request upon a database 15 | * 16 | * @author Herve Jouin 17 | */ 18 | public class DBSelect extends DBStatement { 19 | private static final DBLogger logger = new DBLogger(DBSelect.class); 20 | 21 | @Getter ResultSet result = null; 22 | 23 | /** 24 | * Wrapper to generate and execute a SELECT request in the database
25 | * One may use '?' in the request and provide the corresponding values as parameters (at the moment, only strings are accepted)
26 | * The connection to the database should already exist 27 | * @param theDriverName 28 | * @param theConnection 29 | * @param theRequest 30 | * @param theParameters 31 | * @param 32 | * @return the ResultSet with the data read from the database 33 | * @throws SQLException 34 | */ 35 | @SafeVarargs 36 | public DBSelect(String theDriverName, Connection theConnection, String theRequest, T... theParameters) throws SQLException { 37 | super(theDriverName, theConnection, theRequest, theParameters); 38 | 39 | try { 40 | this.result = executeQuery(); 41 | } catch (Exception err) { 42 | // in case of an SQLException, we log the raw request to ease the debug process 43 | if ( logger.isTraceEnabled() ) logger.trace("SQL Exception for database request: "+theRequest); 44 | throw err; 45 | } 46 | } 47 | 48 | /** 49 | * May be called after a DBselect call 50 | * @return the next value 51 | * @throws SQLException 52 | */ 53 | public boolean next() throws SQLException { 54 | return this.result.next(); 55 | } 56 | 57 | public int getInt(String columnLabel) throws SQLException { 58 | return this.result.getInt(columnLabel); 59 | } 60 | 61 | public String getString(String columnLabel) throws SQLException { 62 | return this.result.getString(columnLabel); 63 | } 64 | 65 | public Timestamp getTimestamp(String columnLabel) throws SQLException { 66 | return this.result.getTimestamp(columnLabel); 67 | } 68 | 69 | public byte[] getBytes(String columnLabel) throws SQLException { 70 | return this.result.getBytes(columnLabel); 71 | } 72 | 73 | public Date getDate(String columnLabel) throws SQLException { 74 | return this.result.getDate(columnLabel); 75 | } 76 | 77 | public Object getObject(String columnLabel) throws SQLException { 78 | return this.result.getObject(columnLabel); 79 | } 80 | 81 | @Override public void close() { 82 | try { 83 | if ( this.result != null && !this.result.isClosed() ) 84 | this.result.close(); 85 | } catch (SQLException err) { 86 | logger.error("Cannot close the ResultSet", err); 87 | } 88 | 89 | super.close(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/connection/DBStatement.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.connection; 2 | 3 | 4 | import java.io.ByteArrayInputStream; 5 | import java.sql.Connection; 6 | import java.sql.PreparedStatement; 7 | import java.sql.ResultSet; 8 | import java.sql.SQLException; 9 | import java.sql.Savepoint; 10 | import java.sql.Statement; 11 | import java.sql.Timestamp; 12 | import java.util.ArrayList; 13 | import java.util.Base64; 14 | 15 | import org.archicontribs.database.DBLogger; 16 | import org.archicontribs.database.DBPlugin; 17 | import org.archicontribs.database.data.DBDatabase; 18 | 19 | /** 20 | * Helper class that allows to construct a preparedStatement 21 | */ 22 | public class DBStatement implements AutoCloseable { 23 | private static final DBLogger logger = new DBLogger(DBStatement.class); 24 | 25 | String driverName = null; 26 | Connection connection = null; 27 | Statement statement = null; 28 | PreparedStatement preparedStatement = null; 29 | String request = null; 30 | 31 | /** 32 | * HelperMethod to construct the PreparedStatement from the specified request and all its parameters 33 | * @param 34 | * @param theDriverName 35 | * @param theConnection 36 | * @param theRequest 37 | * @param theParameters 38 | * @throws SQLException 39 | */ 40 | @SafeVarargs 41 | public DBStatement(String theDriverName, Connection theConnection, String theRequest, T... theParameters) throws SQLException { 42 | this.driverName = theDriverName; 43 | this.connection = theConnection; 44 | this.request = theRequest; 45 | try { 46 | if ( theParameters.length == 0 ) 47 | this.statement = theConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 48 | else { 49 | this.preparedStatement = theConnection.prepareStatement(theRequest, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); 50 | constructStatement(theParameters); 51 | } 52 | } catch (SQLException err) { 53 | // in case of an SQLException, we log the raw request to ease the debug process 54 | if ( logger.isTraceEnabled() ) logger.trace("SQL Exception for database request: "+theRequest); 55 | throw err; 56 | } 57 | 58 | } 59 | 60 | /** 61 | * Executes the preparedStatement where no answer is awaited 62 | * @return 63 | * @throws SQLException 64 | */ 65 | public ResultSet executeQuery() throws SQLException { 66 | if ( this.statement != null && ! this.statement.isClosed() ) 67 | return this.statement.executeQuery(this.request); 68 | 69 | if ( this.preparedStatement != null && ! this.preparedStatement.isClosed() ) 70 | return this.preparedStatement.executeQuery(); 71 | 72 | return null; 73 | } 74 | 75 | /** 76 | * executes the preparedStement when it is related to an UPDATE request 77 | * @return the number or updated rows 78 | * @throws SQLException 79 | */ 80 | public int executeUpdate() throws SQLException { 81 | Savepoint savepoint = null; 82 | int rowCount = 0; 83 | 84 | if ( logger.isTraceEnabled() && !this.request.toLowerCase().startsWith("match") && !this.request.toLowerCase().startsWith("create") && !this.request.toLowerCase().startsWith("insert") && !this.request.toLowerCase().startsWith("update")) { 85 | // MATCH, CREATE, INSERT and UPDATE request are going through constructStatement that has got its own trace 86 | logger.trace(" --> "+this.request); 87 | } 88 | 89 | try { 90 | // on PostGreSQL databases, we can only send new requests if we rollback the transaction that caused the exception 91 | if ( DBPlugin.areEqual(this.driverName, DBDatabase.POSTGRESQL.getDriverName()) ) 92 | savepoint = this.connection.setSavepoint(); 93 | 94 | if ( this.statement != null && !this.statement.isClosed() ) 95 | rowCount = this.statement.executeUpdate(this.request); 96 | else 97 | if ( this.preparedStatement != null && !this.preparedStatement.isClosed() ) 98 | rowCount = this.preparedStatement.executeUpdate(); 99 | } catch (SQLException err) { 100 | if ( savepoint != null ) { 101 | try { 102 | rollback(savepoint); 103 | if ( logger.isTraceEnabled() ) logger.trace("Rolled back to savepoint"); 104 | } catch (SQLException e2) { logger.error("Failed to rollback to savepoint", e2); } 105 | } 106 | throw err; 107 | } finally { 108 | if ( savepoint != null ) 109 | this.connection.releaseSavepoint(savepoint); 110 | } 111 | 112 | return rowCount; 113 | } 114 | 115 | /** 116 | * Rollbacks the current database transactions from a specified savePoint 117 | * @param savepoint 118 | * @throws SQLException 119 | */ 120 | public void rollback(Savepoint savepoint) throws SQLException { 121 | if ( this.connection.getAutoCommit() ) { 122 | if ( logger.isDebugEnabled() ) logger.debug("Do not rollback as database is in auto commit mode."); 123 | } else { 124 | if ( logger.isDebugEnabled() ) logger.debug("Rollbacking database transaction."); 125 | if ( savepoint == null ) 126 | this.connection.rollback(); 127 | else 128 | this.connection.rollback(savepoint); 129 | } 130 | } 131 | 132 | /** 133 | * Rollbacks the current database transactions 134 | * @throws SQLException 135 | */ 136 | public void rollback() throws SQLException { 137 | rollback(null); 138 | } 139 | 140 | @SuppressWarnings("unchecked") 141 | void constructStatement(T... parameters) throws SQLException { 142 | StringBuilder debugRequest = new StringBuilder(); 143 | String[] splittedRequest = this.request.split("\\?"); 144 | 145 | int requestRank = 0; 146 | int parameterRank = 0; 147 | while (parameterRank < parameters.length) { 148 | if ( logger.isTraceEnabled() ) debugRequest.append(splittedRequest[requestRank]); 149 | 150 | if ( parameters[parameterRank] == null ) { 151 | if ( logger.isTraceEnabled() ) debugRequest.append("null"); 152 | this.preparedStatement.setString(++requestRank, null); 153 | } else if ( parameters[parameterRank] instanceof String ) { 154 | if ( logger.isTraceEnabled() ) debugRequest.append("'"+parameters[parameterRank]+"'"); 155 | this.preparedStatement.setString(++requestRank, (String)parameters[parameterRank]); 156 | 157 | } else if ( parameters[parameterRank] instanceof Integer ) { 158 | if ( logger.isTraceEnabled() ) debugRequest.append(parameters[parameterRank]); 159 | this.preparedStatement.setInt(++requestRank, (int)parameters[parameterRank]); 160 | 161 | } else if ( parameters[parameterRank] instanceof Timestamp ) { 162 | if ( logger.isTraceEnabled() ) debugRequest.append(String.valueOf(parameters[parameterRank])); 163 | this.preparedStatement.setTimestamp(++requestRank, (Timestamp)parameters[parameterRank]); 164 | 165 | } else if ( parameters[parameterRank] instanceof Boolean ) { 166 | if ( logger.isTraceEnabled() ) debugRequest.append(String.valueOf((boolean)parameters[parameterRank])); 167 | this.preparedStatement.setBoolean(++requestRank, (Boolean)parameters[parameterRank]); 168 | 169 | } else if ( parameters[parameterRank] instanceof ArrayList ){ 170 | for(int i = 0; i < ((ArrayList)parameters[parameterRank]).size(); ++i) { 171 | if ( logger.isTraceEnabled() ) { 172 | if ( i != 0 ) 173 | debugRequest.append(","); 174 | debugRequest.append("'"+((ArrayList)parameters[parameterRank]).get(i)+"'"); 175 | } 176 | this.preparedStatement.setString(++requestRank, ((ArrayList)parameters[parameterRank]).get(i)); 177 | } 178 | } else if ( parameters[parameterRank] instanceof byte[] ) { 179 | try { 180 | this.preparedStatement.setBinaryStream(++requestRank, new ByteArrayInputStream((byte[])parameters[parameterRank]), ((byte[])parameters[parameterRank]).length); 181 | if ( logger.isTraceEnabled() ) debugRequest.append("[image as stream ("+((byte[])parameters[parameterRank]).length+" bytes)]"); 182 | } catch (@SuppressWarnings("unused") Exception err) { 183 | this.preparedStatement.setString(++requestRank, Base64.getEncoder().encodeToString((byte[])parameters[parameterRank])); 184 | if ( logger.isTraceEnabled() ) debugRequest.append("[image as base64 string ("+((byte[])parameters[parameterRank]).length+" bytes)]"); 185 | } 186 | 187 | } else { 188 | if ( logger.isTraceEnabled() ) logger.trace(" "+this.request); 189 | throw new SQLException("Unknown "+parameters[parameterRank].getClass().getSimpleName()+" parameter in SQL select."); 190 | } 191 | ++parameterRank; 192 | } 193 | if ( logger.isTraceSQLEnabled() ) { 194 | if ( requestRank < splittedRequest.length ) 195 | debugRequest.append(splittedRequest[requestRank]); 196 | logger.trace(" --> "+debugRequest.toString()); 197 | } 198 | } 199 | 200 | @Override public void close() { 201 | try { 202 | if ( this.statement != null && !this.statement.isClosed() ) { 203 | this.statement.close(); 204 | this.statement = null; 205 | } 206 | } catch (SQLException err) { 207 | logger.error("Cannot close the Statement", err); 208 | } 209 | 210 | try { 211 | if ( this.preparedStatement != null && !this.preparedStatement.isClosed() ) { 212 | this.preparedStatement.close(); 213 | this.preparedStatement = null; 214 | } 215 | } catch (SQLException err) { 216 | logger.error("Cannot close the PreparedStatement", err); 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBBendpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.data; 7 | 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | 11 | /** 12 | * Simple class to store a bendpoint 13 | * 14 | * @author Herve Jouin 15 | */ 16 | public class DBBendpoint 17 | { 18 | @Getter @Setter private int startX; 19 | @Getter @Setter private int startY; 20 | @Getter @Setter private int endX; 21 | @Getter @Setter private int endY; 22 | 23 | /** 24 | * Initialize the bendpoint 25 | * @param theStartX 26 | * @param theStartY 27 | * @param theEndX 28 | * @param theEndY 29 | */ 30 | public DBBendpoint(int theStartX, int theStartY, int theEndX, int theEndY) { 31 | this.startX = theStartX; 32 | this.endX = theEndX; 33 | this.startY = theStartY; 34 | this.endY = theEndY; 35 | } 36 | } -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBCompoundCommand.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.data; 2 | 3 | import org.archicontribs.database.DBException; 4 | import org.archicontribs.database.model.commands.IDBCommand; 5 | import org.eclipse.gef.commands.Command; 6 | import org.eclipse.gef.commands.CompoundCommand; 7 | 8 | /** 9 | * Command that can be executed 10 | * 11 | * @author Herve Jouin 12 | */ 13 | public class DBCompoundCommand extends CompoundCommand { 14 | /** 15 | * Constructs an empty CompoundCommand 16 | */ 17 | public DBCompoundCommand() { 18 | super(); 19 | } 20 | 21 | /** 22 | * Constructs an empty CompoundCommand with the specified label. 23 | * 24 | * @param label the label for the Command 25 | */ 26 | public DBCompoundCommand(String label) { 27 | super(label); 28 | } 29 | 30 | /** 31 | * Adds the specified command if it is not null. 32 | * 33 | * @param command null or a IDBCommand 34 | * @throws DBException if any exception is raised during the initialization of the command 35 | */ 36 | public void checkAndAdd(IDBCommand command) throws DBException { 37 | if (command != null) { 38 | DBException exception = command.getException(); 39 | if ( exception != null ) 40 | throw exception; 41 | 42 | super.add((Command)command); 43 | } 44 | } 45 | 46 | /** 47 | * Execute the specified command and adds it if it is not null. 48 | * 49 | * @param command null or a IDBCommand 50 | * @throws Exception if any exception is raised during the initialization of the command 51 | */ 52 | public void checkAndExecute(IDBCommand command) throws DBException { 53 | if (command != null) { 54 | DBException exception = command.getException(); 55 | if ( exception != null ) 56 | throw exception; 57 | 58 | command.execute(); 59 | exception = command.getException(); 60 | if ( exception != null) 61 | throw exception; 62 | 63 | super.add((Command)command); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBDatabase.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.data; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | import org.archicontribs.database.DBPlugin; 8 | 9 | import lombok.Getter; 10 | 11 | /** 12 | * This enum stores the information required to connect to a database 13 | * @author Herve Jouin 14 | */ 15 | public enum DBDatabase { 16 | /** Microsoft SQL */ MSSQL(0, "ms-sql", 1433, "com.microsoft.sqlserver.jdbc.SQLServerDriver", true), 17 | /** MySQL */ MYSQL(1, "mysql", 3306, "com.mysql.cj.jdbc.Driver", false), 18 | /** Neo4J */ NEO4J(2, "neo4j", 7687, "org.neo4j.jdbc.Driver", false), 19 | /** Oracle */ ORACLE(3, "oracle", 1521, "oracle.jdbc.driver.OracleDriver", true), 20 | /** PostGreSQL */ POSTGRESQL(4, "postgresql", 5432, "org.postgresql.Driver", true), 21 | /** SQLite */ SQLITE(5, "sqlite", 0, "org.sqlite.JDBC", false); 22 | 23 | /** Microsoft SQL */ public static final int MSSQL_VALUE = 0; 24 | /** MySQL */ public static final int MYSQL_VALUE = 1; 25 | /** Neo4J */ public static final int NEO4J_VALUE = 2; 26 | /** Oracle */ public static final int ORACLE_VALUE = 3; 27 | /** PostGreSQL */ public static final int POSTGRESQL_VALUE = 4; 28 | /** SQLite */ public static final int SQLITE_VALUE = 5; 29 | 30 | private static final DBDatabase[] VALUES_ARRAY = new DBDatabase[] {MSSQL, MYSQL, NEO4J, ORACLE, POSTGRESQL, SQLITE}; 31 | 32 | /** Numerical values affected to database drivers */ 33 | public static final List VALUES_LIST = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY)); 34 | 35 | /** List of database drivers */ 36 | public static final String[] DRIVER_NAMES = new String[] {MSSQL.getDriverName(), MYSQL.getDriverName(), NEO4J.getDriverName(), ORACLE.getDriverName(), POSTGRESQL.getDriverName(), SQLITE.getDriverName()}; 37 | 38 | /** Numeric value of the entry */ 39 | @Getter private final int value; 40 | 41 | /** driver name of the database */ 42 | @Getter private final String driverName; 43 | 44 | /** default port that can be used to connect to the database */ 45 | @Getter private final int defaultPort; 46 | 47 | /** driver class of the database */ 48 | @Getter private final String driverClass; 49 | 50 | /** indicates if the database handles schemas or not */ 51 | private final boolean hasSchema; 52 | 53 | /** 54 | * @return true is the database handles schemas, false if not. 55 | */ 56 | public boolean hasSchema() { 57 | return this.hasSchema; 58 | } 59 | 60 | private DBDatabase(int val, String name, int port, String clazz, boolean schema) { 61 | this.value = val; 62 | this.driverName = name.toLowerCase(); 63 | this.defaultPort = port; 64 | this.driverClass = clazz; 65 | this.hasSchema = schema; 66 | } 67 | 68 | /** 69 | * Gets the database properties from its driver-name 70 | * @param driverName 71 | * @return the database properties 72 | */ 73 | public static DBDatabase get(String driverName) { 74 | for ( DBDatabase database: VALUES_ARRAY ) 75 | if ( DBPlugin.areEqual(database.getDriverName(), driverName) ) return database; 76 | return null; 77 | } 78 | 79 | /** 80 | * Gets the database properties from its numeric value 81 | * @param value numeric value 82 | * @return the database properties 83 | */ 84 | public static DBDatabase get(int value) { 85 | switch (value) { 86 | case NEO4J_VALUE: return NEO4J; 87 | case MSSQL_VALUE: return MSSQL; 88 | case MYSQL_VALUE: return MYSQL; 89 | case ORACLE_VALUE: return ORACLE; 90 | case POSTGRESQL_VALUE: return POSTGRESQL; 91 | case SQLITE_VALUE: return SQLITE; 92 | default: 93 | break; 94 | } 95 | return null; 96 | } 97 | 98 | /** 99 | * Gets the database driver name 100 | * @return the driver name 101 | */ 102 | @Override 103 | public String toString() { 104 | return this.driverName; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBImportMode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.data; 7 | 8 | import java.util.List; 9 | 10 | import org.archicontribs.database.DBLogger; 11 | import org.archicontribs.database.DBPlugin; 12 | 13 | import lombok.Getter; 14 | 15 | /** 16 | * This enum specifies how individual components may be imported. 17 | *
    18 | *
  • templateMode: the components are imported in copy mode, except the concept that have the "template" property's value set to "shared" which will be imported in shared mode.
  • 19 | *
  • forceSharedMode: the components are imported in shared mode (i.e. modifications done will be seen by other models).
  • 20 | *
  • forceCopyMode: the components are imported in copy mode (i.e. modifications done are local to the model and are not seen by other models).
  • 21 | *
22 | * @author Herve Jouin 23 | */ 24 | public enum DBImportMode { 25 | /** 26 | * In templateMode, the components are imported in copy mode, except the concept that have the "template" property's value set to "shared" which will be imported in shared mode. 27 | */ 28 | TEMPLATE_MODE(DBImportMode.TEMPLATE_MODE_VALUE, "template mode"), 29 | /** 30 | * In forceSharedMode, the components are imported in shared mode (i.e. modifications done will be seen by other models). 31 | */ 32 | FORCE_SHARED_MODE(DBImportMode.FORCE_SHARED_MODE_VALUE, "force shared mode"), 33 | /** 34 | * In forceCopyMode, the components are imported in copy mode (i.e. modifications done are local to the model and are not seen by other models). 35 | */ 36 | FORCE_COPY_MODE(DBImportMode.FORCE_COPY_MODE_VALUE, "force copy mode"); 37 | 38 | protected static final DBLogger logger = new DBLogger(DBImportMode.class); 39 | 40 | @Getter private int value; 41 | @Getter private String label; 42 | 43 | public static final int TEMPLATE_MODE_VALUE = 1; 44 | public static final int FORCE_SHARED_MODE_VALUE = 2; 45 | public static final int FORCE_COPY_MODE_VALUE = 3; 46 | 47 | private DBImportMode(int v, String l) { 48 | this.value = v; 49 | this.label = l; 50 | } 51 | 52 | public static String getLabel(int value) { 53 | switch ( value ) { 54 | case DBImportMode.TEMPLATE_MODE_VALUE: return TEMPLATE_MODE.getLabel(); 55 | case DBImportMode.FORCE_SHARED_MODE_VALUE: return FORCE_SHARED_MODE.getLabel(); 56 | case DBImportMode.FORCE_COPY_MODE_VALUE: return FORCE_COPY_MODE.getLabel(); 57 | default: return null; 58 | } 59 | } 60 | 61 | public static DBImportMode get(int value) { 62 | switch ( value ) { 63 | case DBImportMode.TEMPLATE_MODE_VALUE: return TEMPLATE_MODE; 64 | case DBImportMode.FORCE_SHARED_MODE_VALUE: return FORCE_SHARED_MODE; 65 | case DBImportMode.FORCE_COPY_MODE_VALUE: return FORCE_COPY_MODE; 66 | default: return null; 67 | } 68 | } 69 | 70 | /** 71 | * @param properties Array with Archimate component properties 72 | * @return true if import should be done in copy mode, false if import should be done in share mode 73 | */ 74 | public boolean shouldCreateCopy(List properties) { 75 | switch ( this.value ) { 76 | case DBImportMode.FORCE_SHARED_MODE_VALUE: 77 | logger.debug(" Import in forced shared mode."); 78 | return false; 79 | 80 | case DBImportMode.FORCE_COPY_MODE_VALUE: 81 | logger.debug(" Import in forced copy mode."); 82 | return true; 83 | 84 | case DBImportMode.TEMPLATE_MODE_VALUE: 85 | if ( properties != null ) { 86 | for ( DBProperty prop: properties) { 87 | if ( DBPlugin.areEqual(prop.getKey(), "template") && DBPlugin.areEqual(prop.getValue(), "copy") ) { 88 | logger.debug(" Import in copy mode (as specified by the \"template\" property)"); 89 | return true; 90 | } 91 | } 92 | } 93 | logger.debug(" Import in shared mode (no \"template\" property or value different from \"copy\")"); 94 | return false; 95 | 96 | default: 97 | logger.debug(" Unknown import mode: defaulting to shared mode."); 98 | return false; 99 | } 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBProfile.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.data; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.Setter; 11 | 12 | /** 13 | * Simple class to store a Profile 14 | * 15 | * @author Herve Jouin 16 | */ 17 | @AllArgsConstructor 18 | public class DBProfile implements java.lang.Comparable 19 | { 20 | @Getter @Setter private String name; 21 | @Getter @Setter private String conceptType; 22 | @Getter @Setter private boolean specialization; 23 | @Getter @Setter private String imagePath; 24 | 25 | 26 | @Override 27 | public int compareTo(DBProfile o) { 28 | int result = this.name.compareTo(o.getName()); 29 | if ( result == 0 ) result = this.conceptType.compareTo(o.getConceptType()); 30 | if ( result == 0 ) result = ((Boolean)this.specialization).compareTo(o.isSpecialization()); 31 | if ( result == 0 ) result = this.imagePath.compareTo(o.getImagePath()); 32 | return result; 33 | } 34 | 35 | @Override 36 | public boolean equals(Object o) { 37 | if ( o instanceof DBProfile) 38 | return this.conceptType.equals(((DBProfile)o).getConceptType()) 39 | && this.specialization == (((DBProfile)o).isSpecialization()) 40 | && this.imagePath.equals(((DBProfile)o).getImagePath()); 41 | return false; 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return super.hashCode(); 47 | } 48 | } -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBProperty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.data; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Getter; 10 | import lombok.Setter; 11 | 12 | /** 13 | * Simple class to store a pair of key/value 14 | * 15 | * @author Herve Jouin 16 | */ 17 | @AllArgsConstructor 18 | public class DBProperty implements java.lang.Comparable 19 | { 20 | @Getter @Setter private String key; 21 | @Getter @Setter private String value; 22 | 23 | @Override 24 | public int compareTo(DBProperty o) { 25 | int result = this.key.compareTo(o.getKey()); 26 | if ( result == 0 ) result = this.value.compareTo(o.getValue()); 27 | return result; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object o) { 32 | if ( o instanceof DBProperty ) 33 | return this.key.equals(((DBProperty)o).key) && this.value.equals(((DBProperty)o).value); 34 | return false; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return super.hashCode(); 40 | } 41 | } -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBScreenshot.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.data; 7 | 8 | import org.eclipse.draw2d.geometry.Rectangle; 9 | 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | /** 14 | * Simple class to store a view screenshot 15 | * 16 | * @author Herve Jouin 17 | */ 18 | public class DBScreenshot { 19 | @Setter private Integer scaleFactor; 20 | @Setter private Integer borderWidth; 21 | @Setter private Rectangle bounds; 22 | @Setter private byte[] screenshotBytes; 23 | 24 | @Getter @Setter private boolean screenshotActive = true; 25 | 26 | public DBScreenshot() { 27 | this.screenshotBytes = null; 28 | this.scaleFactor = null; 29 | this.borderWidth = null; 30 | this.bounds = null; 31 | this.screenshotActive = false; 32 | } 33 | 34 | public DBScreenshot(byte[] screenshot, int scale, int margin) { 35 | this.screenshotBytes = screenshot; 36 | this.scaleFactor = scale; 37 | this.borderWidth = margin; 38 | this.bounds = null; 39 | this.screenshotActive = true; 40 | } 41 | 42 | public byte[] getBytes() { 43 | return this.screenshotActive ? this.screenshotBytes : null; 44 | } 45 | 46 | public Integer getScaleFactor() { 47 | return this.screenshotActive ? this.scaleFactor : null; 48 | } 49 | 50 | public Integer getX() { 51 | return this.screenshotActive ? this.bounds.x : null; 52 | } 53 | public Integer getY() { 54 | return this.screenshotActive ? this.bounds.y : null; 55 | } 56 | 57 | public Integer getWidth() { 58 | return this.screenshotActive ? this.bounds.width : null; 59 | } 60 | 61 | public Integer getHeight() { 62 | return this.screenshotActive ? this.bounds.height : null; 63 | } 64 | 65 | public Integer getBodrderWidth() { 66 | return this.screenshotActive ? this.borderWidth : null; 67 | } 68 | 69 | public void dispose() { 70 | this.screenshotBytes = null; 71 | this.scaleFactor = null; 72 | this.borderWidth = null; 73 | this.bounds = null; 74 | this.screenshotActive = false; 75 | } 76 | } -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/data/DBVersion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.data; 8 | 9 | import java.sql.Timestamp; 10 | import java.time.Instant; 11 | 12 | import lombok.Getter; 13 | 14 | /** 15 | * This class holds a version, a checksum and a timestamp 16 | * 17 | * @author Herve Jouin 18 | */ 19 | @SuppressWarnings("hiding") 20 | public class DBVersion { 21 | /** 22 | * value used to represent the "NEVER" concept 23 | */ 24 | public static final Timestamp NEVER = Timestamp.from(Instant.EPOCH); 25 | 26 | @Getter private int version; 27 | 28 | /** 29 | * Initialize the {@link DBVersion} with another DBVersion that will be copied 30 | * @param versionToCopy 31 | */ 32 | public DBVersion(DBVersion versionToCopy) { 33 | set(versionToCopy); 34 | } 35 | 36 | /** 37 | * Initialize the {@link DBVersion} with another DBVersion that will be copied 38 | * @param versionToCopy 39 | */ 40 | public DBVersion(int version, String containerChecksum, String checksum, Timestamp timestamp, String username) { 41 | set(version, containerChecksum, checksum, timestamp, username); 42 | } 43 | 44 | public DBVersion(int version, String checksum, Timestamp timestamp, String username) { 45 | set(version, null, checksum, timestamp, username); 46 | } 47 | 48 | public DBVersion() { 49 | this(0, null, null, null, null); 50 | } 51 | 52 | public DBVersion(Timestamp timestamp) { 53 | this(0, null, null, timestamp, null); 54 | } 55 | 56 | public DBVersion(int version) { 57 | this(version, null, null, null, null); 58 | } 59 | 60 | public void reset() { 61 | setVersion(0); 62 | setContainerChecksum(null); 63 | setChecksum(null); 64 | setTimestamp(null); 65 | setUsername(null); 66 | } 67 | 68 | public void set(DBVersion version) { 69 | if (version == null ) { 70 | setVersion(0); 71 | setContainerChecksum(null); 72 | setChecksum(null); 73 | setTimestamp(null); 74 | setUsername(null); 75 | } else { 76 | setVersion(version.getVersion()); 77 | setContainerChecksum(version.getContainerChecksum()); 78 | setChecksum(version.getChecksum()); 79 | setTimestamp(version.getTimestamp()); 80 | setUsername(version.getUsername()); 81 | } 82 | } 83 | 84 | public void set(int version, String checksum, Timestamp timestamp, String username) { 85 | setVersion(version); 86 | setContainerChecksum(null); 87 | setChecksum(checksum); 88 | setTimestamp(timestamp); 89 | setUsername(username); 90 | } 91 | 92 | public void set(int version, String containerChecksum, String checksum, Timestamp timestamp, String username) { 93 | setVersion(version); 94 | setContainerChecksum(containerChecksum); 95 | setChecksum(checksum); 96 | setTimestamp(timestamp); 97 | setUsername(username); 98 | } 99 | 100 | public void setVersion(int version) { 101 | this.version = (version<0 ? 0 : version); 102 | } 103 | 104 | /** 105 | * For containers, the checksum calculation must take the content in account 106 | */ 107 | @Getter private String checksum; 108 | /** 109 | * For containers, the checksum calculation must take the content in account 110 | */ 111 | public void setChecksum(String checksum) { 112 | this.checksum = (checksum==null ? "" : checksum); 113 | } 114 | 115 | /** 116 | * For containers, the checksum calculation must not take the content in account 117 | */ 118 | @Getter private String containerChecksum; 119 | /** 120 | * For containers, the checksum calculation must not take the content in account 121 | */ 122 | public void setContainerChecksum(String checksum) { 123 | this.containerChecksum = (checksum==null ? "" : checksum); 124 | } 125 | 126 | @Getter private Timestamp timestamp; 127 | public void setTimestamp(Timestamp timestamp) { 128 | this.timestamp = (timestamp==null ? NEVER : timestamp); 129 | } 130 | 131 | private String username; 132 | public String getUsername() { 133 | if (this.username == null) 134 | return System.getProperty("user.name"); 135 | return this.username; 136 | } 137 | 138 | public void setUsername(String name) { 139 | this.username = name; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/gui/DBGuiImportImage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.gui; 7 | 8 | import org.apache.log4j.Level; 9 | import org.archicontribs.database.DBLogger; 10 | import org.archicontribs.database.DBPlugin; 11 | import org.archicontribs.database.connection.DBDatabaseImportConnection; 12 | import org.archicontribs.database.model.DBArchimateModel; 13 | import org.eclipse.nebula.widgets.gallery.DefaultGalleryItemRenderer; 14 | import org.eclipse.nebula.widgets.gallery.Gallery; 15 | import org.eclipse.nebula.widgets.gallery.GalleryItem; 16 | import org.eclipse.nebula.widgets.gallery.NoGroupRenderer; 17 | import org.eclipse.swt.SWT; 18 | import org.eclipse.swt.events.DisposeEvent; 19 | import org.eclipse.swt.events.DisposeListener; 20 | import org.eclipse.swt.events.SelectionAdapter; 21 | import org.eclipse.swt.events.SelectionEvent; 22 | import org.eclipse.swt.events.SelectionListener; 23 | import org.eclipse.swt.graphics.Image; 24 | import org.eclipse.swt.graphics.Point; 25 | import org.eclipse.swt.layout.FormAttachment; 26 | import org.eclipse.swt.layout.FormData; 27 | import org.eclipse.swt.layout.GridData; 28 | import org.eclipse.swt.layout.GridLayout; 29 | import org.eclipse.swt.widgets.Composite; 30 | import org.eclipse.swt.widgets.Event; 31 | import org.eclipse.swt.widgets.Group; 32 | import org.eclipse.swt.widgets.Listener; 33 | import org.eclipse.swt.widgets.Scale; 34 | 35 | import com.archimatetool.editor.utils.PlatformUtils; 36 | 37 | /** 38 | * This class holds the methods requires to import an image from the database 39 | * 40 | * @author Herve Jouin 41 | */ 42 | public class DBGuiImportImage extends DBGui { 43 | @SuppressWarnings("hiding") 44 | private static final DBLogger logger = new DBLogger(DBGuiImportImage.class); 45 | 46 | private static final int DEFAULT_GALLERY_ITEM_SIZE = 128; 47 | private static final int MIN_GALLERY_ITEM_SIZE = 64; 48 | private static final int MAX_GALLERY_ITEM_SIZE = 256; 49 | 50 | String imagePath = null; 51 | Image image = null; 52 | 53 | DBDatabaseImportConnection importConnection; 54 | 55 | Gallery gallery; 56 | GalleryItem rootGalleryItem; 57 | Scale scale; 58 | 59 | public DBGuiImportImage(DBArchimateModel model, String title) { 60 | // We call the DBGui constructor that will create the underlying form and expose the compoRight, compoRightUp and compoRightBottom composites 61 | super(title); 62 | 63 | if ( logger.isDebugEnabled() ) logger.debug("Setting up GUI for importing an image \""+model.getName()+"\" (plugin version "+DBPlugin.PLUGIN_VERSION.toString()+")."); 64 | 65 | createGrpImages(); 66 | 67 | this.compoRightBottom.setVisible(true); 68 | this.compoRightBottom.layout(); 69 | 70 | createAction(ACTION.One, "1 - select image"); 71 | 72 | // we show an arrow in front of the first action 73 | setActiveAction(ACTION.One); 74 | 75 | // if the user select the "Import" button --> import the image, set the importedImagePath variable and close the window 76 | setBtnAction("Import image", new SelectionListener() { 77 | @Override public void widgetSelected(SelectionEvent e) { 78 | GalleryItem[] selectedItems = DBGuiImportImage.this.gallery.getSelection(); 79 | if ( selectedItems != null && selectedItems.length != 0 ) { 80 | Image selectedImage = selectedItems[0].getImage(); 81 | if ( selectedImage != null ) { 82 | DBGuiImportImage.this.imagePath = (String)selectedItems[0].getData("imagePath"); 83 | DBGuiImportImage.this.image = new Image(display, selectedImage, SWT.IMAGE_COPY); 84 | close(); 85 | } 86 | } 87 | } 88 | @Override public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } 89 | }); 90 | 91 | // We rename the "close" button to "Cancel" 92 | this.btnClose.setText("Cancel"); 93 | 94 | // We activate the Eclipse Help framework 95 | setHelpHref("importImage.html"); 96 | } 97 | 98 | @Override 99 | public void run() { 100 | super.run(); 101 | try { 102 | getDatabases(false); 103 | } catch (Exception err) { 104 | DBGuiUtils.popup(Level.ERROR, "Failed to get the databases.", err); 105 | } 106 | } 107 | 108 | /** 109 | * Creates a group displaying the images from the database 110 | */ 111 | private void createGrpImages() { 112 | Group grpImages = new Group(this.compoRightBottom, SWT.NONE); 113 | grpImages.setBackground(GROUP_BACKGROUND_COLOR); 114 | grpImages.setText("Images in the database: "); 115 | grpImages.setFont(GROUP_TITLE_FONT); 116 | FormData fd = new FormData(); 117 | fd.top = new FormAttachment(0); 118 | fd.left = new FormAttachment(0); 119 | fd.right = new FormAttachment(100); 120 | fd.bottom = new FormAttachment(100); 121 | grpImages.setLayoutData(fd); 122 | grpImages.setLayout(new GridLayout(2, false)); 123 | 124 | Composite galleryComposite = new Composite(grpImages, SWT.FILL); 125 | galleryComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); 126 | GridLayout layout = new GridLayout(); 127 | layout.marginWidth = 0; 128 | layout.marginHeight = 0; 129 | galleryComposite.setLayout(layout); 130 | 131 | this.gallery = new Gallery(galleryComposite, SWT.V_SCROLL | SWT.BORDER | SWT.FILL); 132 | this.gallery.setLayoutData(new GridData(GridData.FILL_BOTH)); 133 | 134 | // Renderers 135 | final NoGroupRenderer groupRenderer = new NoGroupRenderer(); 136 | groupRenderer.setItemSize(DEFAULT_GALLERY_ITEM_SIZE, DEFAULT_GALLERY_ITEM_SIZE); 137 | groupRenderer.setAutoMargin(true); 138 | groupRenderer.setMinMargin(10); 139 | this.gallery.setGroupRenderer(groupRenderer); 140 | 141 | final DefaultGalleryItemRenderer itemRenderer = new DefaultGalleryItemRenderer(); 142 | itemRenderer.setDropShadows(true); 143 | itemRenderer.setDropShadowsSize(7); 144 | itemRenderer.setShowRoundedSelectionCorners(false); 145 | this.gallery.setItemRenderer(itemRenderer); 146 | 147 | // Root Group 148 | this.rootGalleryItem = new GalleryItem(this.gallery, SWT.NONE); 149 | 150 | // Slider 151 | this.scale = new Scale(galleryComposite, SWT.HORIZONTAL); 152 | GridData gd = new GridData(SWT.END, SWT.NONE, false, false); 153 | gd.widthHint = 120; 154 | if(PlatformUtils.isMac()) { // Mac clips height of slider 155 | gd.heightHint = 18; 156 | } 157 | this.scale.setLayoutData(gd); 158 | this.scale.setMinimum(MIN_GALLERY_ITEM_SIZE); 159 | this.scale.setMaximum(MAX_GALLERY_ITEM_SIZE); 160 | this.scale.setIncrement(8); 161 | this.scale.setPageIncrement(32); 162 | this.scale.setSelection(DEFAULT_GALLERY_ITEM_SIZE); 163 | this.scale.addSelectionListener(new SelectionAdapter() { 164 | @Override public void widgetSelected(SelectionEvent e) { 165 | int inc = DBGuiImportImage.this.scale.getSelection(); 166 | itemRenderer.setDropShadows(inc >= 96); 167 | groupRenderer.setItemSize(inc, inc); 168 | } 169 | }); 170 | 171 | // Gallery selections 172 | this.gallery.addSelectionListener(new SelectionAdapter() { 173 | @Override public void widgetSelected(SelectionEvent e) { 174 | DBGuiImportImage.this.btnDoAction.setEnabled(e.item instanceof GalleryItem); 175 | } 176 | }); 177 | 178 | // Double-clicks 179 | this.gallery.addListener(SWT.MouseDoubleClick, new Listener() { 180 | @Override public void handleEvent(Event event) { 181 | Image selectedImage = DBGuiImportImage.this.gallery.getItem(new Point(event.x, event.y)).getImage(); 182 | if ( selectedImage != null ) { 183 | DBGuiImportImage.this.imagePath = (String)DBGuiImportImage.this.gallery.getItem(new Point(event.x, event.y)).getData("imagePath"); 184 | DBGuiImportImage.this.image = new Image(display, selectedImage, SWT.IMAGE_COPY); 185 | close(); 186 | } 187 | } 188 | }); 189 | 190 | // Dispose of the images here not in the main dispose() method because if the help system is showing then 191 | // the TrayDialog is resized and this control is asked to relayout. 192 | this.gallery.addDisposeListener(new DisposeListener() { 193 | @Override 194 | public void widgetDisposed(DisposeEvent e) { 195 | notConnectedToDatabase(); // we dispose the images 196 | } 197 | }); 198 | } 199 | 200 | /** 201 | * This method is called each time a database is selected and a connection has been established to it.
202 | */ 203 | @Override 204 | protected void connectedToDatabase(boolean forceCheckDatabase) { 205 | notConnectedToDatabase(); // we dispose the images 206 | 207 | this.importConnection = new DBDatabaseImportConnection(getDatabaseConnection()); 208 | 209 | try { 210 | for ( String path: this.importConnection.getImageListFromDatabase() ) { 211 | GalleryItem item = new GalleryItem(this.rootGalleryItem, SWT.NONE); 212 | item.setImage(this.importConnection.getImageFromDatabase(path)); 213 | item.setData("imagePath", path); 214 | } 215 | } catch (Exception err) { 216 | DBGuiUtils.popup(Level.ERROR, "Failed to get images from the database", err); 217 | } 218 | } 219 | 220 | /** 221 | * 222 | */ 223 | 224 | /** 225 | * This method is called each time a connection to the database fails.
226 | */ 227 | @Override 228 | protected void notConnectedToDatabase() { 229 | if( this.rootGalleryItem != null && !this.rootGalleryItem.isDisposed()) { 230 | while(this.rootGalleryItem.getItemCount() > 0) { 231 | GalleryItem item = this.rootGalleryItem.getItem(0); 232 | this.rootGalleryItem.remove(item); 233 | } 234 | } 235 | } 236 | 237 | public String getImagePath() { 238 | return this.imagePath; 239 | } 240 | 241 | public Image getImage() { 242 | return this.image; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/gui/DBGuiPasswordDialog.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.gui; 8 | 9 | import org.eclipse.jface.dialogs.Dialog; 10 | import org.eclipse.swt.SWT; 11 | import org.eclipse.swt.events.SelectionEvent; 12 | import org.eclipse.swt.events.SelectionListener; 13 | import org.eclipse.swt.graphics.Point; 14 | import org.eclipse.swt.layout.FormAttachment; 15 | import org.eclipse.swt.layout.FormData; 16 | import org.eclipse.swt.layout.FormLayout; 17 | import org.eclipse.swt.widgets.Button; 18 | import org.eclipse.swt.widgets.Composite; 19 | import org.eclipse.swt.widgets.Control; 20 | import org.eclipse.swt.widgets.Label; 21 | import org.eclipse.swt.widgets.Shell; 22 | import org.eclipse.swt.widgets.Text; 23 | 24 | /** 25 | * This class opens up an input dialog and asks for a password 26 | * 27 | * @author Herve Jouin 28 | */ 29 | public class DBGuiPasswordDialog extends Dialog { 30 | private Text txtPassword; 31 | Button btnShowPassword; 32 | private String password = ""; 33 | 34 | 35 | /** 36 | * Creates the dialog 37 | * @param parentShell 38 | */ 39 | public DBGuiPasswordDialog(Shell parentShell) { 40 | super(parentShell); 41 | } 42 | 43 | @Override 44 | protected Control createDialogArea(Composite parent) { 45 | Composite composite = (Composite) super.createDialogArea(parent); 46 | FormLayout layout = new FormLayout(); 47 | composite.setLayout(layout); 48 | 49 | Label lblPassword = new Label(composite, SWT.NONE); 50 | lblPassword.setText("Password:"); 51 | FormData fd = new FormData(); 52 | fd.top = new FormAttachment(0, 20); 53 | fd.left = new FormAttachment(0, 10); 54 | lblPassword.setLayoutData(fd); 55 | 56 | this.btnShowPassword = new Button(composite, SWT.TOGGLE); 57 | this.btnShowPassword.setImage(DBGui.LOCK_ICON); 58 | this.btnShowPassword.setSelection(true); 59 | fd = new FormData(); 60 | fd.top = new FormAttachment(lblPassword, 0, SWT.CENTER); 61 | fd.right = new FormAttachment(100, -20); 62 | this.btnShowPassword.setLayoutData(fd); 63 | this.btnShowPassword.addSelectionListener(new SelectionListener() { 64 | @Override 65 | public void widgetSelected(SelectionEvent e) { showOrHidePasswordCallback(); } 66 | @Override 67 | public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } 68 | }); 69 | 70 | this.txtPassword = new Text(composite, SWT.BORDER| SWT.PASSWORD); 71 | this.txtPassword.setText(this.password); 72 | fd = new FormData(); 73 | fd.top = new FormAttachment(lblPassword, 0, SWT.CENTER); 74 | fd.left = new FormAttachment(lblPassword, 10); 75 | fd.right = new FormAttachment(this.btnShowPassword, -10); 76 | this.txtPassword.setLayoutData(fd); 77 | 78 | 79 | 80 | return composite; 81 | } 82 | 83 | /** 84 | * Called when the "showPassword" button is pressed 85 | */ 86 | public void showOrHidePasswordCallback() { 87 | this.txtPassword.setEchoChar(this.btnShowPassword.getSelection() ? 0x25cf : '\0' ); 88 | this.btnShowPassword.setImage(this.btnShowPassword.getSelection() ? DBGui.LOCK_ICON : DBGui.UNLOCK_ICON); 89 | } 90 | 91 | @Override 92 | protected Point getInitialSize() { 93 | return new Point(450, 300); 94 | } 95 | 96 | @Override 97 | protected void okPressed() { 98 | this.password = this.txtPassword.getText(); 99 | super.okPressed(); 100 | } 101 | 102 | /** 103 | * Get password 104 | * @return the password 105 | */ 106 | public String getPassword() { 107 | return this.password; 108 | } 109 | 110 | /** 111 | * Set password 112 | * @param passwrd 113 | */ 114 | public void setPassword(String passwrd) { 115 | this.password = passwrd; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/gui/DBGuiReplaceElement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.gui; 8 | 9 | import org.apache.log4j.Level; 10 | import org.archicontribs.database.DBException; 11 | import org.archicontribs.database.DBLogger; 12 | import org.archicontribs.database.model.DBArchimateModel; 13 | import org.archicontribs.database.model.DBMetadata; 14 | import org.eclipse.swt.events.SelectionEvent; 15 | import org.eclipse.swt.events.SelectionListener; 16 | 17 | import com.archimatetool.model.IArchimateElement; 18 | 19 | /** 20 | * This class manages the GUI that allows to replace a component by another one 21 | * 22 | * @author Herve Jouin 23 | */ 24 | public class DBGuiReplaceElement extends DBGuiImportComponents { 25 | @SuppressWarnings("hiding") 26 | protected static final DBLogger logger = new DBLogger(DBGuiReplaceElement.class); 27 | 28 | IArchimateElement selectedElement; 29 | 30 | public DBGuiReplaceElement(DBArchimateModel model, IArchimateElement element, String title) throws DBException { 31 | super(model, null, null, title); 32 | 33 | this.selectedElement = element; 34 | 35 | // we ensure that the element tab is selected and the only one shown 36 | 37 | 38 | // we replace the "import" button by a "replace" button 39 | setBtnAction("Replace", new SelectionListener() { 40 | @Override 41 | public void widgetSelected(SelectionEvent event) { 42 | DBGuiReplaceElement.this.btnDoAction.setEnabled(false); 43 | try { 44 | doReplace(); 45 | } catch (Exception err) { 46 | DBGuiUtils.popup(Level.ERROR, "An exception has been raised during import.", err); 47 | } 48 | } 49 | @Override 50 | public void widgetDefaultSelected(SelectionEvent event) { widgetSelected(event); } 51 | }); 52 | } 53 | 54 | void doReplace() { 55 | logger.info("Replacing "+DBMetadata.getDBMetadata(this.selectedElement).getDebugName()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/help/ApplicationActionBarAdvisor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.help; 8 | 9 | import org.eclipse.ui.IWorkbenchWindow; 10 | import org.eclipse.ui.actions.ActionFactory; 11 | import org.eclipse.ui.application.ActionBarAdvisor; 12 | import org.eclipse.ui.application.IActionBarConfigurer; 13 | 14 | public class ApplicationActionBarAdvisor extends ActionBarAdvisor { 15 | 16 | @Override 17 | protected void makeActions(IWorkbenchWindow window) { 18 | register(ActionFactory.HELP_SEARCH.create(window)); 19 | register(ActionFactory.DYNAMIC_HELP.create(window)); 20 | } 21 | 22 | public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { 23 | super(configurer); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/menu/DBMenuComponentHistoryHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.menu; 8 | 9 | import org.apache.log4j.Level; 10 | import org.archicontribs.database.model.DBMetadata; 11 | import org.archicontribs.database.DBLogger; 12 | import org.archicontribs.database.DBPlugin; 13 | import org.archicontribs.database.gui.DBGuiComponentHistory; 14 | import org.archicontribs.database.gui.DBGuiUtils; 15 | import org.eclipse.core.commands.AbstractHandler; 16 | import org.eclipse.core.commands.ExecutionEvent; 17 | import org.eclipse.core.commands.ExecutionException; 18 | import org.eclipse.gef.editparts.AbstractEditPart; 19 | import org.eclipse.jface.viewers.IStructuredSelection; 20 | import org.eclipse.ui.handlers.HandlerUtil; 21 | 22 | import com.archimatetool.model.IArchimateModelObject; 23 | import com.archimatetool.model.IDiagramModelArchimateComponent; 24 | 25 | /** 26 | * Class that is called when the user selects the "Component history" contexte menu. 27 | * 28 | * @author Herve Jouin 29 | */ 30 | public class DBMenuComponentHistoryHandler extends AbstractHandler { 31 | private static final DBLogger logger = new DBLogger(DBMenu.class); 32 | 33 | @Override 34 | public Object execute(ExecutionEvent event) throws ExecutionException { 35 | Object selection = ((IStructuredSelection)HandlerUtil.getCurrentSelection(event)).getFirstElement(); 36 | Object selectedObject; 37 | 38 | if ( selection instanceof AbstractEditPart ) { 39 | selectedObject = ((AbstractEditPart)selection).getModel(); 40 | 41 | if ( DBPlugin.areEqual(event.getParameter("mustConsiderConcept"), "yes") && (selectedObject instanceof IDiagramModelArchimateComponent) ) 42 | selectedObject = ((IDiagramModelArchimateComponent)selectedObject).getArchimateConcept(); 43 | } else 44 | selectedObject = selection; 45 | 46 | if ( selectedObject instanceof IArchimateModelObject ) { 47 | IArchimateModelObject selectedComponent = (IArchimateModelObject) selectedObject; 48 | if ( logger.isDebugEnabled() ) logger.debug("Showing database history of component " + DBMetadata.getDBMetadata(selectedComponent).getDebugName()); 49 | 50 | try { 51 | DBGuiComponentHistory componentHistory = new DBGuiComponentHistory(selectedComponent); 52 | componentHistory.run(); 53 | } catch (Exception e) { 54 | DBGuiUtils.popup(Level.ERROR,"Cannot get history from database.", e); 55 | } 56 | } 57 | else { 58 | // in all other cases, we do not know how to get its history from the database 59 | DBGuiUtils.popup(Level.ERROR, "Cannot get history of a "+selectedObject.getClass().getSimpleName()); 60 | return null; 61 | } 62 | 63 | 64 | return null; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/menu/DBMenuComponentImportHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.menu; 8 | 9 | import org.apache.log4j.Level; 10 | import org.archicontribs.database.DBLogger; 11 | import org.archicontribs.database.gui.DBGuiImportComponents; 12 | import org.archicontribs.database.gui.DBGuiUtils; 13 | import org.archicontribs.database.model.DBArchimateModel; 14 | import org.eclipse.core.commands.AbstractHandler; 15 | import org.eclipse.core.commands.ExecutionEvent; 16 | import org.eclipse.core.commands.ExecutionException; 17 | import org.eclipse.jface.viewers.IStructuredSelection; 18 | import org.eclipse.ui.handlers.HandlerUtil; 19 | 20 | import com.archimatetool.editor.diagram.editparts.ArchimateDiagramPart; 21 | import com.archimatetool.editor.diagram.editparts.ArchimateElementEditPart; 22 | import com.archimatetool.model.IArchimateConcept; 23 | import com.archimatetool.model.IArchimateDiagramModel; 24 | import com.archimatetool.model.IFolder; 25 | /** 26 | * Class that is called when the user selects the "Import component from database" context menu. 27 | * 28 | * @author Herve Jouin 29 | */ 30 | public class DBMenuComponentImportHandler extends AbstractHandler { 31 | private static final DBLogger logger = new DBLogger(DBMenu.class); 32 | 33 | @Override 34 | public Object execute(ExecutionEvent event) throws ExecutionException { 35 | Object selection = ((IStructuredSelection)HandlerUtil.getCurrentSelection(event)).getFirstElement(); 36 | DBArchimateModel model; 37 | IArchimateDiagramModel view = null; 38 | IFolder folder = null; 39 | 40 | if ( selection instanceof IFolder ) { // if the user clicked on a folder in the tree 41 | model = (DBArchimateModel) ((IFolder)selection).getArchimateModel(); 42 | folder = (IFolder)selection; 43 | 44 | } else if ( selection instanceof IArchimateConcept ) { // if the user clicked on an element or a relationship in the tree 45 | model = (DBArchimateModel) ((IArchimateConcept)selection).getArchimateModel(); 46 | folder = (IFolder) ((IArchimateConcept)selection).eContainer(); 47 | 48 | } else if ( selection instanceof ArchimateElementEditPart ) { // if the user clicked on a component in a view 49 | model = (DBArchimateModel) ((ArchimateElementEditPart)selection).getModel().getDiagramModel().getArchimateModel(); 50 | view = (IArchimateDiagramModel) ((ArchimateElementEditPart)selection).getModel().getDiagramModel(); 51 | 52 | } else if ( selection instanceof IArchimateDiagramModel ) { // if the user clicked on a view in the tree 53 | model = (DBArchimateModel) ((IArchimateDiagramModel)selection).getArchimateModel(); 54 | view = ((IArchimateDiagramModel)selection); 55 | folder = (IFolder)view.eContainer(); 56 | 57 | } else if ( selection instanceof ArchimateDiagramPart ) { // if the user clicked on a view background 58 | model = (DBArchimateModel) ((ArchimateDiagramPart)selection).getModel().getArchimateModel(); 59 | view = ((ArchimateDiagramPart)selection).getModel(); 60 | 61 | } else if ( selection instanceof DBArchimateModel ) { // if the user clicked on the model 62 | model = (DBArchimateModel) selection; 63 | 64 | } else { 65 | logger.error("We do not know what the user selected ("+selection.getClass().getSimpleName()+")"); 66 | return null; // we do not know what the user selected 67 | } 68 | 69 | if ( logger.isDebugEnabled() ) logger.debug("Importing component in model "+model.getName()); 70 | 71 | try { 72 | DBGuiImportComponents importComponent = new DBGuiImportComponents(model, view, folder, "Import a component"); 73 | importComponent.run(); 74 | } catch (Exception e) { 75 | DBGuiUtils.popup(Level.ERROR,"Cannot import model", e); 76 | } 77 | return null; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/menu/DBMenuElementReplaceHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.menu; 8 | 9 | import org.apache.log4j.Level; 10 | import org.archicontribs.database.DBLogger; 11 | import org.archicontribs.database.gui.DBGuiReplaceElement; 12 | import org.archicontribs.database.gui.DBGuiUtils; 13 | import org.archicontribs.database.model.DBArchimateModel; 14 | import org.archicontribs.database.model.DBMetadata; 15 | import org.eclipse.core.commands.AbstractHandler; 16 | import org.eclipse.core.commands.ExecutionEvent; 17 | import org.eclipse.core.commands.ExecutionException; 18 | import org.eclipse.jface.viewers.IStructuredSelection; 19 | import org.eclipse.ui.handlers.HandlerUtil; 20 | 21 | import com.archimatetool.editor.diagram.editparts.ArchimateElementEditPart; 22 | import com.archimatetool.model.IArchimateElement; 23 | 24 | /** 25 | * Class that is called when the user selects the "Replace Element" in the context menu 26 | * 27 | * @author Herve Jouin 28 | */ 29 | public class DBMenuElementReplaceHandler extends AbstractHandler { 30 | private static final DBLogger logger = new DBLogger(DBMenu.class); 31 | 32 | @Override 33 | public Object execute(ExecutionEvent event) throws ExecutionException { 34 | Object selection = ((IStructuredSelection)HandlerUtil.getCurrentSelection(event)).getFirstElement(); 35 | IArchimateElement element; 36 | 37 | if ( selection instanceof IArchimateElement ) { // if the user clicked on an element 38 | element = (IArchimateElement)selection; 39 | 40 | } else if ( selection instanceof ArchimateElementEditPart ) { // if the user clicked on an element in a view 41 | element = ((ArchimateElementEditPart)selection).getModel().getArchimateElement(); 42 | 43 | } else { 44 | logger.error("We do not know how to replace a ("+selection.getClass().getSimpleName()+")"); 45 | return null; // we can only replace elements here 46 | } 47 | 48 | if ( logger.isDebugEnabled() ) logger.debug("Replacing element "+DBMetadata.getDBMetadata(element).getDebugName()); 49 | 50 | try { 51 | DBGuiReplaceElement replaceElement = new DBGuiReplaceElement((DBArchimateModel)element.getArchimateModel(), element, "Replace element"); 52 | replaceElement.run(); 53 | } catch (Exception e) { 54 | DBGuiUtils.popup(Level.ERROR,"Cannot import model", e); 55 | } 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/menu/DBMenuModelExportHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.menu; 8 | 9 | import org.apache.log4j.Level; 10 | import org.archicontribs.database.DBLogger; 11 | import org.archicontribs.database.gui.DBGuiExportModel; 12 | import org.archicontribs.database.gui.DBGuiUtils; 13 | import org.archicontribs.database.model.DBArchimateModel; 14 | import org.eclipse.core.commands.AbstractHandler; 15 | import org.eclipse.core.commands.ExecutionEvent; 16 | import org.eclipse.core.commands.ExecutionException; 17 | import org.eclipse.gef.editparts.AbstractEditPart; 18 | import org.eclipse.jface.viewers.IStructuredSelection; 19 | import org.eclipse.ui.handlers.HandlerUtil; 20 | 21 | import com.archimatetool.model.IArchimateModelObject; 22 | import com.archimatetool.model.IDiagramModelArchimateComponent; 23 | 24 | /** 25 | * Class that is called when the user selects the "export model to database" in the context menu 26 | * 27 | * @author Herve Jouin 28 | */ 29 | public class DBMenuModelExportHandler extends AbstractHandler { 30 | private static final DBLogger logger = new DBLogger(DBMenu.class); 31 | 32 | @Override 33 | public Object execute(ExecutionEvent event) throws ExecutionException { 34 | Object selection = ((IStructuredSelection)HandlerUtil.getCurrentSelection(event)).getFirstElement(); 35 | DBArchimateModel exportedModel = null; 36 | 37 | // we check if a model is selected 38 | if ( selection instanceof DBArchimateModel ) 39 | exportedModel = (DBArchimateModel)selection; 40 | else if ( selection instanceof AbstractEditPart ) { 41 | Object selectedObject = ((AbstractEditPart)selection).getModel(); 42 | if ( selectedObject instanceof IDiagramModelArchimateComponent ) 43 | exportedModel = (DBArchimateModel) ((IDiagramModelArchimateComponent)selectedObject).getArchimateConcept().getArchimateModel(); 44 | } else if ( selection instanceof IArchimateModelObject ) 45 | exportedModel = (DBArchimateModel) ((IArchimateModelObject) selection).getArchimateModel(); 46 | 47 | if ( exportedModel != null ) { 48 | if ( logger.isDebugEnabled() ) 49 | logger.debug("Exporting model "+exportedModel.getName()); 50 | 51 | try { 52 | DBGuiExportModel exportModel = new DBGuiExportModel(exportedModel, "Export model"); 53 | exportModel.run(); 54 | } catch (Exception e) { 55 | DBGuiUtils.popup(Level.ERROR,"Cannot export model", e); 56 | } 57 | } 58 | 59 | return null; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/menu/DBMenuModelImportHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.menu; 8 | 9 | import org.apache.log4j.Level; 10 | import org.archicontribs.database.DBLogger; 11 | import org.archicontribs.database.gui.DBGuiImportModel; 12 | import org.archicontribs.database.gui.DBGuiUtils; 13 | import org.eclipse.core.commands.AbstractHandler; 14 | import org.eclipse.core.commands.ExecutionEvent; 15 | import org.eclipse.core.commands.ExecutionException; 16 | 17 | /** 18 | * Class that is called when the user selects the "import model from database" in the context menu 19 | * 20 | * @author Herve Jouin 21 | */ 22 | public class DBMenuModelImportHandler extends AbstractHandler { 23 | private static final DBLogger logger = new DBLogger(DBMenu.class); 24 | 25 | @Override 26 | public Object execute(ExecutionEvent event) throws ExecutionException { 27 | if ( logger.isDebugEnabled() ) 28 | logger.debug("Launching Import model window"); 29 | 30 | try { 31 | DBGuiImportModel importModel = new DBGuiImportModel("Import model"); 32 | importModel.run(); 33 | } catch (Exception e) { 34 | DBGuiUtils.popup(Level.ERROR,"Cannot import model", e); 35 | } 36 | 37 | return null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/menu/DBMenuShowDebugHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.menu; 8 | 9 | import org.apache.log4j.Level; 10 | import org.archicontribs.database.DBLogger; 11 | import org.archicontribs.database.gui.DBGuiShowDebug; 12 | import org.archicontribs.database.gui.DBGuiUtils; 13 | import org.archicontribs.database.model.DBMetadata; 14 | import org.eclipse.core.commands.AbstractHandler; 15 | import org.eclipse.core.commands.ExecutionEvent; 16 | import org.eclipse.core.commands.ExecutionException; 17 | import org.eclipse.emf.ecore.EObject; 18 | import org.eclipse.gef.EditPart; 19 | import org.eclipse.jface.viewers.IStructuredSelection; 20 | import org.eclipse.ui.handlers.HandlerUtil; 21 | 22 | import com.archimatetool.canvas.model.ICanvasModel; 23 | import com.archimatetool.model.IArchimateConcept; 24 | import com.archimatetool.model.IArchimateDiagramModel; 25 | import com.archimatetool.model.IArchimateModelObject; 26 | import com.archimatetool.model.IFolder; 27 | import com.archimatetool.model.ISketchModel; 28 | 29 | /** 30 | * Class that is called when the iser selects the "show debugging information" in the context menu 31 | * 32 | * @author Herve Jouin 33 | */ 34 | public class DBMenuShowDebugHandler extends AbstractHandler { 35 | private static final DBLogger logger = new DBLogger(DBMenuShowDebugHandler.class); 36 | 37 | @Override 38 | public Object execute(ExecutionEvent event) throws ExecutionException { 39 | Object selection = ((IStructuredSelection)HandlerUtil.getCurrentSelection(event)).getFirstElement(); 40 | EObject component; 41 | 42 | if ( selection instanceof IArchimateConcept 43 | || selection instanceof IArchimateDiagramModel 44 | || selection instanceof ICanvasModel 45 | || selection instanceof ISketchModel 46 | || selection instanceof IFolder) { 47 | // if the user click on a component in the model tree 48 | component = (IArchimateModelObject)selection; 49 | } else if ( selection instanceof EditPart ) { 50 | // if the user clicked on a graphical object in a view 51 | component = (EObject) ((EditPart)selection).getModel(); 52 | } else { 53 | DBGuiUtils.popup(Level.ERROR, "Do not know which component you selected."); 54 | return null; 55 | } 56 | 57 | DBMetadata dbMetadata = DBMetadata.getDBMetadata(component); 58 | if ( dbMetadata != null ) { 59 | if ( logger.isDebugEnabled() ) { 60 | logger.debug("Showing debbuging information for "+dbMetadata.getDebugName()); 61 | } 62 | 63 | try { 64 | DBGuiShowDebug showDebug = new DBGuiShowDebug(component, "Debugging information"); 65 | showDebug.run(); 66 | } catch (Exception e) { 67 | DBGuiUtils.popup(Level.ERROR,"Failed to show debugging information.", e); 68 | } 69 | } 70 | 71 | return dbMetadata; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/DBArchimateFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.model; 8 | 9 | import org.archicontribs.database.DBLogger; 10 | import com.archimatetool.model.IArchimateModel; 11 | import com.archimatetool.model.impl.ArchimateFactory; 12 | 13 | /** 14 | * The DBArchimateFactory class overrides the com.archimatetool.model.impl.ArchimateFactory class
15 | * It allows to create DBArchimateModel instances instead of standard ArchimaeModel instances. 16 | * 17 | * @author Herve JOUIN 18 | * @see com.archimatetool.model.impl.ArchimateFactory 19 | * @see org.archicontribs.database.model.IDBMetadata 20 | */ 21 | public class DBArchimateFactory extends ArchimateFactory { 22 | static DBLogger logger = new DBLogger(DBArchimateFactory.class); 23 | static boolean ignoreNext = false; 24 | 25 | /** 26 | * Instance of the DBArchimateFactory class 27 | */ 28 | @SuppressWarnings("hiding") 29 | public static final DBArchimateFactory eINSTANCE = init(); 30 | 31 | public static DBArchimateFactory init() { 32 | if ( logger.isDebugEnabled() ) 33 | logger.debug("Initializing DBArchimateFactory"); 34 | 35 | if ( eINSTANCE==null ) 36 | return new DBArchimateFactory(); 37 | return eINSTANCE; 38 | } 39 | 40 | /** 41 | * Override of the original ArchimateFactory
42 | * Creates a DBxxxx instead of a xxxx objects that include DBMetadata properties 43 | */ 44 | public DBArchimateFactory() { 45 | super(); 46 | } 47 | 48 | 49 | /** 50 | * Override of the original createArchimateModel
51 | * Creates a DBArchimateModel instead of a ArchimateModel 52 | */ 53 | @Override 54 | public IArchimateModel createArchimateModel() { 55 | return new org.archicontribs.database.model.DBArchimateModel(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/DBDeleteDiagramConnectionCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.model.commands; 8 | 9 | import org.archicontribs.database.DBException; 10 | import org.archicontribs.database.model.DBArchimateModel; 11 | import org.eclipse.gef.commands.Command; 12 | 13 | import com.archimatetool.model.IDiagramModel; 14 | import com.archimatetool.model.IDiagramModelConnection; 15 | 16 | /** 17 | * Delete Diagram Connection Command
18 | *
19 | * This class is based on {@link com.archimatetool.editor.diagram.commands.DeleteDiagramConnectionCommand} written by Phillip Beauvoir 20 | * 21 | * @author Herve Jouin 22 | */ 23 | public class DBDeleteDiagramConnectionCommand extends Command implements IDBCommand { 24 | private IDiagramModelConnection fConnection; 25 | private DBArchimateModel fModel; 26 | DBException exception = null; 27 | 28 | /** 29 | * Create a command that will disconnect a connection from its endpoints. 30 | * @param model 31 | * @param connection the connection instance to disconnect (non-null) 32 | */ 33 | public DBDeleteDiagramConnectionCommand(DBArchimateModel model, IDiagramModelConnection connection) { 34 | this.fConnection = connection; 35 | this.fModel = model; 36 | } 37 | 38 | @Override 39 | public void execute() { 40 | try { 41 | IDiagramModel diagramModel = this.fConnection.getDiagramModel(); 42 | if ( diagramModel != null ) 43 | this.fModel.getDBMetadata(diagramModel).setChecksumValid(false); 44 | this.fModel.getAllViewConnections().remove(this.fConnection.getId()); 45 | this.fConnection.disconnect(); 46 | } catch ( Exception e ) { 47 | this.exception = new DBException("Failed to delete diagram connection"); 48 | this.exception.initCause(e); 49 | } 50 | } 51 | 52 | @Override 53 | public void undo() { 54 | try { 55 | this.fConnection.reconnect(); 56 | this.fModel.getAllViewConnections().put(this.fConnection.getId(), this.fConnection); 57 | } catch (Exception e) { 58 | this.exception = new DBException("Failed to restore deleted diagram connection"); 59 | this.exception.initCause(e); 60 | } 61 | } 62 | 63 | 64 | @Override 65 | public void dispose() { 66 | this.fConnection = null; 67 | } 68 | 69 | @Override 70 | public DBException getException() { 71 | return this.exception; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/DBDeleteDiagramObjectCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.model.commands; 8 | 9 | import java.util.ArrayList; 10 | 11 | import org.archicontribs.database.DBException; 12 | import org.archicontribs.database.model.DBArchimateModel; 13 | import org.eclipse.gef.commands.Command; 14 | 15 | import com.archimatetool.model.IDiagramModelComponent; 16 | import com.archimatetool.model.IDiagramModelContainer; 17 | import com.archimatetool.model.IDiagramModelObject; 18 | 19 | /** 20 | * Command for deleting an Object from its parent container.
21 | * It puts it back at the index position from where it was removed.
22 | *
23 | * This class is inspired from {@link com.archimatetool.editor.diagram.commands.DeleteDiagramObjectCommand} written by Phillip Beauvoir, but is not recursive (deleting a view object does not delete its children) 24 | * 25 | * @author Herve Jouin 26 | */ 27 | public class DBDeleteDiagramObjectCommand extends Command implements IDBCommand { 28 | private IDiagramModelContainer viewObjectParent; 29 | private IDiagramModelObject viewObject; 30 | private DBArchimateModel model; 31 | private int viewObjectIndex; 32 | private ArrayList viewObjectChildren; 33 | private DBException exception = null; 34 | 35 | /** 36 | * @param archimateModel 37 | * @param object 38 | */ 39 | public DBDeleteDiagramObjectCommand(DBArchimateModel archimateModel, IDiagramModelObject object) { 40 | this.viewObjectParent = (IDiagramModelContainer)object.eContainer(); 41 | this.viewObject = object; 42 | this.viewObjectChildren = new ArrayList<>(); 43 | this.model = archimateModel; 44 | } 45 | 46 | @Override 47 | public boolean canExecute() { 48 | /* 49 | * Parent can be null when objects are selected (with marquee tool) and transferred from one container 50 | * to another and the Diagram Editor updates the enablement state of Actions. 51 | * Can also be null if already deleted as part of a Compound Command. 52 | */ 53 | return this.viewObjectParent != null && this.viewObjectParent.getChildren().contains(this.viewObject); 54 | } 55 | 56 | @Override 57 | public void execute() { 58 | // Ensure viewObjectIndex is stored just before execute because if this is part of a composite delete action, then the index positions will have changed 59 | try { 60 | this.viewObjectIndex = this.viewObjectParent.getChildren().indexOf(this.viewObject); 61 | if ( this.viewObjectIndex != -1 ) { // might have already been deleted by another process 62 | // we move the viewObject children to the viewObjectParent 63 | if ( this.viewObject instanceof IDiagramModelContainer ) { 64 | for ( IDiagramModelObject child: ((IDiagramModelContainer)this.viewObject).getChildren() ) 65 | this.viewObjectChildren.add(child); 66 | 67 | for ( IDiagramModelObject child: this.viewObjectChildren ) 68 | this.viewObjectParent.getChildren().add(child); 69 | } 70 | this.model.getDBMetadata(((IDiagramModelComponent)this.viewObject).getDiagramModel()).setChecksumValid(false); 71 | this.model.getAllViewObjects().remove(this.viewObject.getId()); 72 | this.viewObjectParent.getChildren().remove(this.viewObject); 73 | } 74 | } catch (Exception e) { 75 | this.exception = new DBException("Failed to delete diagram object"); 76 | this.exception.initCause(e); 77 | } 78 | } 79 | 80 | @Override 81 | public void undo() { 82 | // Add the Child at old index position 83 | try { 84 | if ( this.viewObjectIndex != -1 ) { // might have already been deleted by another process 85 | this.viewObjectParent.getChildren().add(this.viewObjectIndex, this.viewObject); 86 | 87 | // we restore the children to the viewObject 88 | for ( IDiagramModelObject child: this.viewObjectChildren ) { 89 | this.viewObjectParent.getChildren().remove(child); 90 | ((IDiagramModelContainer)this.viewObject).getChildren().add(child); 91 | } 92 | this.model.getAllViewObjects().put(this.viewObject.getId(), this.viewObject); 93 | } 94 | } catch (Exception e) { 95 | this.exception = new DBException("Failed to restore deleted diagram object"); 96 | this.exception.initCause(e); 97 | } 98 | } 99 | 100 | @Override 101 | public void dispose() { 102 | this.viewObjectParent = null; 103 | this.viewObject = null; 104 | this.viewObjectChildren = null; 105 | } 106 | 107 | @Override 108 | public DBException getException() { 109 | return this.exception; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/DBDeleteProfileCommand.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.model.commands; 2 | 3 | import java.util.List; 4 | 5 | import org.archicontribs.database.model.DBArchimateModel; 6 | import org.eclipse.gef.commands.CompoundCommand; 7 | 8 | import com.archimatetool.editor.model.commands.RemoveListMemberCommand; 9 | import com.archimatetool.model.IProfile; 10 | import com.archimatetool.model.IProfiles; 11 | 12 | /** 13 | * This class is base upon Archi class deleteProfileCommand. It calls Archi's RemoveListMemberCommand to delete a profile (ie specialization) in the model.
14 | *
15 | * It is necessary as Archi declares its own class as private so we cannot instantiate it :( 16 | */ 17 | public class DBDeleteProfileCommand extends CompoundCommand { 18 | /** 19 | * Deletes a profile in a model, including all the profile usages 20 | * @param model 21 | * @param profile 22 | */ 23 | public DBDeleteProfileCommand(DBArchimateModel model, IProfile profile) { 24 | 25 | // Delete profile from Model 26 | add(new RemoveListMemberCommand(profile.getArchimateModel().getProfiles(), profile)); 27 | 28 | // Delete profile usages 29 | List usages = model.getAllProfilesUsages().get(profile); 30 | if(usages != null) { 31 | for(IProfiles owner: usages) { 32 | add(new RemoveListMemberCommand(owner.getProfiles(), profile)); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/DBImportProfileFromIdCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.model.commands; 8 | 9 | import java.sql.Timestamp; 10 | import java.util.Calendar; 11 | import java.util.HashMap; 12 | 13 | import org.archicontribs.database.DBException; 14 | import org.archicontribs.database.DBLogger; 15 | import org.archicontribs.database.DBPlugin; 16 | import org.archicontribs.database.connection.DBDatabaseImportConnection; 17 | import org.archicontribs.database.data.DBImportMode; 18 | import org.archicontribs.database.data.DBVersion; 19 | import org.archicontribs.database.model.DBArchimateModel; 20 | import org.archicontribs.database.model.DBMetadata; 21 | import org.eclipse.gef.commands.Command; 22 | import com.archimatetool.model.IArchimateFactory; 23 | import com.archimatetool.model.IProfile; 24 | import com.archimatetool.model.util.Logger; 25 | import com.archimatetool.model.util.UUIDFactory; 26 | 27 | /** 28 | * Command for importing a profile from it's ID. 29 | * 30 | * @author Herve Jouin 31 | */ 32 | public class DBImportProfileFromIdCommand extends Command implements IDBImportCommand { 33 | private static final DBLogger logger = new DBLogger(DBImportProfileFromIdCommand.class); 34 | 35 | private IProfile importedProfile= null; 36 | 37 | private boolean commandHasBeenExecuted = false; // to avoid being executed several times 38 | private DBException exception = null; 39 | 40 | private DBArchimateModel model = null; 41 | 42 | private String id; 43 | private boolean mustCreateCopy; 44 | private boolean isNew; 45 | 46 | // new values that are retrieved from the database 47 | private HashMap newValues = null; 48 | 49 | // old values that need to be retain to allow undo 50 | private DBVersion oldInitialVersion; 51 | private DBVersion oldCurrentVersion; 52 | private DBVersion oldDatabaseVersion; 53 | private DBVersion oldLatestDatabaseVersion; 54 | private String oldName = null; 55 | private String oldConceptType = null; 56 | 57 | /** 58 | * Imports a profile into the model
59 | * @param importConnection connection to the database 60 | * @param archimateModel model into which the profile will be imported 61 | * @param idToImport id of the profile to import 62 | * @param versionToImport version of the profile to import (0 if the latest version must be imported) 63 | * @param importMode specifies if the profile must be copied or shared 64 | */ 65 | public DBImportProfileFromIdCommand(DBDatabaseImportConnection importConnection, DBArchimateModel archimateModel, String idToImport, int versionToImport, DBImportMode importMode) { 66 | this.model = archimateModel; 67 | this.id = idToImport; 68 | 69 | if ( logger.isDebugEnabled() ) 70 | logger.debug(" Importing profile id " + idToImport + " version " + versionToImport + " in " + importMode.getLabel()+"."); 71 | 72 | try { 73 | // we get the new values from the database to allow execute and redo 74 | this.newValues = importConnection.getObjectFromDatabase(idToImport, "IProfile", versionToImport); 75 | 76 | this.mustCreateCopy = importMode.shouldCreateCopy(null); 77 | 78 | if ( this.mustCreateCopy ) { 79 | this.newValues.put("id", UUIDFactory.createID(null)); 80 | this.newValues.put("name", (String)this.newValues.get("name") + DBPlugin.INSTANCE.getPreferenceStore().getString("copySuffix")); 81 | } 82 | 83 | if ( DBPlugin.isEmpty((String)this.newValues.get("name")) ) { 84 | setLabel("import profile"); 85 | } else { 86 | if ( ((String)this.newValues.get("name")).length() > 20 ) 87 | setLabel("import \""+((String)this.newValues.get("name")).substring(0,16)+"...\""); 88 | else 89 | setLabel("import \""+(String)this.newValues.get("name")+"\""); 90 | } 91 | } catch (Exception err) { 92 | Logger.logError("Got Exception "+err.getMessage()); 93 | this.importedProfile = null; 94 | this.exception = new DBException("Failed to import profile from its ID"); 95 | this.exception.initCause(err); 96 | } 97 | } 98 | 99 | @Override 100 | public void execute() { 101 | if ( this.commandHasBeenExecuted ) 102 | return; // we do not execute it twice 103 | 104 | this.commandHasBeenExecuted = true; 105 | 106 | try { 107 | this.importedProfile = this.model.getAllProfiles().get(this.id); 108 | 109 | if ( this.importedProfile == null ) { 110 | this.importedProfile = IArchimateFactory.eINSTANCE.createProfile(); 111 | this.model.getProfiles().add(this.importedProfile); 112 | 113 | this.isNew = true; 114 | } else { 115 | // we must save the old values to allow undo 116 | DBMetadata dbMetadata = this.model.getDBMetadata(this.importedProfile); 117 | 118 | this.oldInitialVersion = dbMetadata.getInitialVersion(); 119 | this.oldCurrentVersion = dbMetadata.getCurrentVersion(); 120 | this.oldDatabaseVersion = dbMetadata.getDatabaseVersion(); 121 | this.oldLatestDatabaseVersion = dbMetadata.getLatestDatabaseVersion(); 122 | 123 | this.oldName = dbMetadata.getName(); 124 | this.oldConceptType = dbMetadata.getConceptType(); 125 | 126 | this.isNew = false; 127 | } 128 | 129 | DBMetadata dbMetadata = this.model.getDBMetadata(this.importedProfile); 130 | 131 | if ( this.mustCreateCopy ) 132 | dbMetadata.getInitialVersion().set(0, null, new Timestamp(Calendar.getInstance().getTime().getTime()), null); 133 | else 134 | dbMetadata.getInitialVersion().set((int)this.newValues.get("version"), (String)this.newValues.get("checksum"), (Timestamp)this.newValues.get("created_on"), (String)this.newValues.get("created_by")); 135 | 136 | dbMetadata.setId((String)this.newValues.get("id")); 137 | dbMetadata.setName((String)this.newValues.get("name")); 138 | dbMetadata.setConceptType((String)this.newValues.get("conceptType")); 139 | 140 | dbMetadata.getCurrentVersion().set(dbMetadata.getInitialVersion()); 141 | dbMetadata.getDatabaseVersion().set(dbMetadata.getInitialVersion()); 142 | dbMetadata.getLatestDatabaseVersion().set(dbMetadata.getInitialVersion()); 143 | 144 | if ( this.isNew ) 145 | this.model.countObject(this.importedProfile, false); 146 | 147 | } catch (Exception err) { 148 | Logger.logError("Got Exception "+err.getMessage()); 149 | this.exception = new DBException("Failed to import profile from its ID"); 150 | this.exception.initCause(err); 151 | } 152 | } 153 | 154 | @Override 155 | public void undo() { 156 | if ( !this.commandHasBeenExecuted ) 157 | return; 158 | 159 | if ( this.importedProfile != null ) { 160 | if ( this.isNew ) { 161 | // if the profile has been created by the execute() method, we just delete it 162 | this.model.getProfiles().remove(this.importedProfile); 163 | 164 | this.model.getAllProfiles().remove(this.importedProfile.getId()); 165 | } else { 166 | // else, we need to restore the old properties 167 | DBMetadata dbMetadata = this.model.getDBMetadata(this.importedProfile); 168 | 169 | dbMetadata.getInitialVersion().set(this.oldInitialVersion); 170 | dbMetadata.getCurrentVersion().set(this.oldCurrentVersion); 171 | dbMetadata.getDatabaseVersion().set(this.oldDatabaseVersion); 172 | dbMetadata.getLatestDatabaseVersion().set(this.oldLatestDatabaseVersion); 173 | 174 | dbMetadata.setName(this.oldName); 175 | dbMetadata.setConceptType(this.oldConceptType); 176 | } 177 | } 178 | 179 | // we allow the command to be executed again 180 | this.commandHasBeenExecuted = false; 181 | } 182 | 183 | /** 184 | * @return the element that has been imported by the command (of course, the command must have been executed before)
185 | * if the value is null, the exception that has been raised can be get using {@link getException} 186 | */ 187 | @Override 188 | public IProfile getImported() { 189 | return this.importedProfile; 190 | } 191 | 192 | /** 193 | * @return the exception that has been raised during the import process, if any. 194 | */ 195 | @Override 196 | public DBException getException() { 197 | return this.exception; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/DBResolveConnectionsCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.model.commands; 7 | 8 | import org.archicontribs.database.DBException; 9 | import org.archicontribs.database.model.DBArchimateModel; 10 | import org.eclipse.gef.commands.Command; 11 | 12 | /** 13 | * Command for resolving source and target for connections 14 | * 15 | * @author Herve Jouin 16 | */ 17 | public class DBResolveConnectionsCommand extends Command implements IDBCommand { 18 | private DBArchimateModel model = null; 19 | 20 | private DBException exception = null; 21 | private boolean commandHasBeenExecuted = false; 22 | 23 | public DBResolveConnectionsCommand(DBArchimateModel archimateModel) { 24 | this.model = archimateModel; 25 | } 26 | 27 | @Override 28 | public boolean canExecute() { 29 | return this.model != null; 30 | } 31 | 32 | @Override 33 | public void execute() { 34 | if ( ! this.commandHasBeenExecuted ) { 35 | this.commandHasBeenExecuted = true; 36 | try { 37 | this.model.resolveSourceAndTargetConnections(); 38 | } catch (Exception e) { 39 | this.exception = new DBException("Failed to resolve connections"); 40 | this.exception.initCause(e); 41 | } 42 | } 43 | } 44 | 45 | @Override 46 | public void undo() { 47 | this.commandHasBeenExecuted = false; 48 | } 49 | 50 | @Override 51 | public DBException getException() { 52 | return this.exception; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/DBResolveRelationshipsCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.model.commands; 7 | 8 | import org.archicontribs.database.DBException; 9 | import org.archicontribs.database.model.DBArchimateModel; 10 | import org.eclipse.gef.commands.Command; 11 | 12 | /** 13 | * Command for resolving source and target for relationships 14 | * 15 | * @author Herve Jouin 16 | */ 17 | public class DBResolveRelationshipsCommand extends Command implements IDBCommand { 18 | private DBArchimateModel model = null; 19 | 20 | private DBException exception = null; 21 | private boolean commandHasBeenExecuted = false; 22 | 23 | public DBResolveRelationshipsCommand(DBArchimateModel archimateModel) { 24 | this.model = archimateModel; 25 | } 26 | 27 | @Override 28 | public boolean canExecute() { 29 | return this.model != null; 30 | } 31 | 32 | @Override 33 | public void execute() { 34 | if ( ! this.commandHasBeenExecuted ) { 35 | this.commandHasBeenExecuted = true; 36 | try { 37 | this.model.resolveSourceAndTargetRelationships(); 38 | } catch (Exception e) { 39 | this.exception = new DBException("Failed to resolve relationships"); 40 | this.exception.initCause(e); 41 | } 42 | } 43 | } 44 | @Override 45 | public void undo() { 46 | this.commandHasBeenExecuted = false; 47 | } 48 | 49 | @Override 50 | public DBException getException() { 51 | return this.exception; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/DBSetFolderToLastKnownCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | package org.archicontribs.database.model.commands; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | import org.archicontribs.database.DBException; 12 | import org.archicontribs.database.connection.DBDatabaseImportConnection; 13 | import org.archicontribs.database.connection.DBSelect; 14 | import org.archicontribs.database.model.DBArchimateModel; 15 | import org.archicontribs.database.model.DBMetadata; 16 | import org.eclipse.gef.commands.Command; 17 | import org.eclipse.emf.ecore.EObject; 18 | 19 | import com.archimatetool.model.IArchimateElement; 20 | import com.archimatetool.model.IArchimateRelationship; 21 | import com.archimatetool.model.IDiagramModel; 22 | import com.archimatetool.model.IFolder; 23 | import com.archimatetool.model.util.Logger; 24 | 25 | /** 26 | * Check all the components in the database that have been move to a new folder and set them in the new folder
27 | *
28 | * This methods does nothing if the model is the latest in the database 29 | */ 30 | public class DBSetFolderToLastKnownCommand extends Command implements IDBCommand { 31 | private DBException exception = null; 32 | 33 | private Map oldObjectsFolders = new HashMap<>(); 34 | private Map newObjectsFolders = new HashMap<>(); 35 | 36 | private DBArchimateModel dbModel; 37 | 38 | /** 39 | * @param model 40 | * @param importConnection 41 | */ 42 | public DBSetFolderToLastKnownCommand(DBArchimateModel model, DBDatabaseImportConnection importConnection) { 43 | this.dbModel = model; 44 | 45 | try { 46 | try ( DBSelect result = new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT m2.element_id AS element_id, m2.parent_folder_id AS parent_folder_id" 47 | + " FROM "+importConnection.getSchemaPrefix()+"elements_in_model m1" 48 | + " JOIN "+importConnection.getSchemaPrefix()+"elements_in_model m2 ON m1.element_id = m2.element_id AND m1.model_id = m2.model_id" 49 | + " WHERE m1.model_id = ? AND m1.model_version = ? AND m2.model_version = ? AND m1.parent_folder_id <> m2.parent_folder_id" 50 | , model.getId() 51 | , model.getInitialVersion().getVersion() 52 | , model.getDatabaseVersion().getVersion() 53 | ) ) { 54 | while (result.next() ) { 55 | IArchimateElement element = model.getAllElements().get(result.getString("element_id")); 56 | DBMetadata elementDbMetadata = model.getDBMetadata(element); 57 | if ( element != null ) { 58 | IFolder parentFolder = model.getAllFolders().get(result.getString("parent_folder_id")); 59 | if ( (parentFolder != null) && (parentFolder != elementDbMetadata.getParentFolder()) ) { 60 | this.oldObjectsFolders.put(element, elementDbMetadata.getParentFolder()); 61 | this.newObjectsFolders.put(element, parentFolder); 62 | } 63 | } 64 | } 65 | } 66 | 67 | // relationships 68 | try ( DBSelect result = new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT m2.relationship_id AS relationship_id, m2.parent_folder_id AS parent_folder_id" 69 | + " FROM "+importConnection.getSchemaPrefix()+"relationships_in_model m1" 70 | + " JOIN "+importConnection.getSchemaPrefix()+"relationships_in_model m2 ON m1.relationship_id = m2.relationship_id AND m1.model_id = m2.model_id" 71 | + " WHERE m1.model_id = ? AND m1.model_version = ? AND m2.model_version = ? AND m1.parent_folder_id <> m2.parent_folder_id" 72 | , model.getId() 73 | , model.getInitialVersion().getVersion() 74 | , model.getDatabaseVersion().getVersion() 75 | ) ) { 76 | while (result.next() ) { 77 | IArchimateRelationship relationship = model.getAllRelationships().get(result.getString("relationship_id")); 78 | DBMetadata relationshipDbMetadata = model.getDBMetadata(relationship); 79 | if ( relationship != null ) { 80 | IFolder parentFolder = model.getAllFolders().get(result.getString("parent_folder_id")); 81 | if ( (parentFolder != null) && (parentFolder != relationshipDbMetadata.getParentFolder()) ) { 82 | this.oldObjectsFolders.put(relationship, relationshipDbMetadata.getParentFolder()); 83 | this.newObjectsFolders.put(relationship, parentFolder); 84 | } 85 | } 86 | } 87 | } 88 | 89 | // folders 90 | try ( DBSelect result = new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT m2.folder_id AS folder_id, m2.parent_folder_id AS parent_folder_id" 91 | + " FROM "+importConnection.getSchemaPrefix()+"folders_in_model m1" 92 | + " JOIN "+importConnection.getSchemaPrefix()+"folders_in_model m2 ON m1.folder_id = m2.folder_id AND m1.model_id = m2.model_id" 93 | + " WHERE m1.model_id = ? AND m1.model_version = ? AND m2.model_version = ? AND m1.parent_folder_id <> m2.parent_folder_id" 94 | , model.getId() 95 | , model.getInitialVersion().getVersion() 96 | , model.getDatabaseVersion().getVersion() 97 | ) ) { 98 | while (result.next() ) { 99 | IFolder folder = model.getAllFolders().get(result.getString("view_id")); 100 | if ( (folder != null) ) { 101 | IFolder parentFolder = model.getAllFolders().get(result.getString("parent_folder_id")); 102 | DBMetadata folderDbMetadata = model.getDBMetadata(folder); 103 | if ( parentFolder != null && (parentFolder != folderDbMetadata.getParentFolder()) ) { 104 | this.oldObjectsFolders.put(folder, folderDbMetadata.getParentFolder()); 105 | this.newObjectsFolders.put(folder, parentFolder); 106 | } 107 | } 108 | } 109 | } 110 | 111 | // views 112 | try ( DBSelect result = new DBSelect(importConnection.getDatabaseEntry().getName(), importConnection.getConnection(), "SELECT m2.view_id AS view_id, m2.parent_folder_id AS parent_folder_id" 113 | + " FROM "+importConnection.getSchemaPrefix()+"views_in_model m1" 114 | + " JOIN "+importConnection.getSchemaPrefix()+"views_in_model m2 ON m1.view_id = m2.view_id AND m1.model_id = m2.model_id" 115 | + " WHERE m1.model_id = ? AND m1.model_version = ? AND m2.model_version = ? AND m1.parent_folder_id <> m2.parent_folder_id" 116 | , model.getId() 117 | , model.getInitialVersion().getVersion() 118 | , model.getDatabaseVersion().getVersion() 119 | ) ) { 120 | while (result.next() ) { 121 | IDiagramModel view = model.getAllViews().get(result.getString("view_id")); 122 | if ( (view != null) ) { 123 | IFolder parentFolder = model.getAllFolders().get(result.getString("parent_folder_id")); 124 | DBMetadata viewDbMetadata = model.getDBMetadata(view); 125 | if ( parentFolder != null && (parentFolder != viewDbMetadata.getParentFolder()) ) { 126 | this.oldObjectsFolders.put(view, viewDbMetadata.getParentFolder()); 127 | this.newObjectsFolders.put(view, parentFolder); 128 | } 129 | } 130 | } 131 | } 132 | } catch (Exception e) { 133 | Logger.logError("Got Exception "+e.getMessage()); 134 | this.exception = new DBException("Failed to set folder to last known"); 135 | this.exception.initCause(e); 136 | } 137 | } 138 | 139 | @Override 140 | public void execute() { 141 | for (Map.Entry newObjectEntry : this.newObjectsFolders.entrySet()) { 142 | this.dbModel.getDBMetadata(newObjectEntry.getKey()).setParentFolder(newObjectEntry.getValue()); 143 | } 144 | } 145 | 146 | @Override 147 | public void undo() { 148 | for (Map.Entry oldObjectEntry : this.oldObjectsFolders.entrySet()) { 149 | this.dbModel.getDBMetadata(oldObjectEntry.getKey()).setParentFolder(oldObjectEntry.getValue()); 150 | } 151 | } 152 | 153 | public boolean needsToBeExecuted() { 154 | return (this.newObjectsFolders.size() != 0) || (this.oldObjectsFolders.size() != 0); 155 | } 156 | 157 | @Override 158 | public DBException getException() { 159 | return this.exception; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/IDBCommand.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.model.commands; 2 | 3 | import org.archicontribs.database.DBException; 4 | 5 | public interface IDBCommand { 6 | public boolean canExecute(); 7 | public void execute(); 8 | 9 | public boolean canUndo(); 10 | public void undo(); 11 | 12 | public boolean canRedo(); 13 | public void redo(); 14 | 15 | public DBException getException(); 16 | 17 | public void dispose(); 18 | } 19 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/commands/IDBImportCommand.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.model.commands; 2 | 3 | import org.eclipse.emf.ecore.EObject; 4 | 5 | public interface IDBImportCommand extends IDBCommand { 6 | public EObject getImported(); 7 | } 8 | -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/propertysections/IObjectFilter.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.model.propertysections; 2 | 3 | /** 4 | * This program and the accompanying materials 5 | * are made available under the terms of the License 6 | * which accompanies this distribution in the file LICENSE.txt 7 | */ 8 | import org.eclipse.emf.ecore.EAttribute; 9 | import org.eclipse.emf.ecore.EObject; 10 | 11 | /** 12 | * Interface for Object Filter 13 | * 14 | * @author Phillip Beauvoir 15 | */ 16 | public interface IObjectFilter { 17 | 18 | /** 19 | * Get the required object for this Property Section from the given object 20 | * For example, object might be an EditPart but we want the underlying model element. 21 | * @param object 22 | * @return The required object or null 23 | */ 24 | Object adaptObject(Object object); 25 | 26 | /** 27 | * @param eObject 28 | * @param feature 29 | * @return True if the feature should be exposed on the object 30 | */ 31 | boolean shouldExposeFeature(EObject eObject, EAttribute feature); 32 | 33 | /** 34 | * @param object 35 | * @return true if object is the required type for this property section 36 | */ 37 | boolean isRequiredType(Object object); 38 | 39 | /** 40 | * @return The underlying adaptable type for this property section 41 | * For example, the underlying type for a fill color in an EditPart is a IDiagramModelObject 42 | */ 43 | Class getAdaptableType(); 44 | } -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/model/propertysections/ObjectFilter.java: -------------------------------------------------------------------------------- 1 | package org.archicontribs.database.model.propertysections; 2 | 3 | import org.eclipse.core.runtime.IAdaptable; 4 | import org.eclipse.emf.ecore.EAttribute; 5 | import org.eclipse.emf.ecore.EObject; 6 | import org.eclipse.jface.viewers.IFilter; 7 | 8 | import com.archimatetool.editor.ui.factory.IObjectUIProvider; 9 | import com.archimatetool.editor.ui.factory.ObjectUIFactory; 10 | 11 | /** 12 | * Object Filter class to show or reject this section depending on input value 13 | */ 14 | public abstract class ObjectFilter implements IFilter, IObjectFilter { 15 | 16 | @Override 17 | public boolean select(Object object) { 18 | return adaptObject(object) != null; 19 | } 20 | 21 | @Override 22 | public Object adaptObject(Object object) { 23 | if(isRequiredType(object)) { 24 | return object; 25 | } 26 | 27 | if(object instanceof IAdaptable) { 28 | Object obj = ((IAdaptable)object).getAdapter(getAdaptableType()); 29 | return isRequiredType(obj) ? obj : null; 30 | } 31 | 32 | return null; 33 | } 34 | 35 | @SuppressWarnings("deprecation") 36 | @Override 37 | public boolean shouldExposeFeature(EObject eObject, EAttribute feature) { 38 | IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(eObject); 39 | 40 | if(provider != null) { 41 | return provider.shouldExposeFeature(feature); 42 | } 43 | 44 | return true; 45 | } 46 | } -------------------------------------------------------------------------------- /sources/src/org/archicontribs/database/preferences/DBFileFieldEditor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This program and the accompanying materials 3 | * are made available under the terms of the License 4 | * which accompanies this distribution in the file LICENSE.txt 5 | */ 6 | 7 | package org.archicontribs.database.preferences; 8 | 9 | import org.archicontribs.database.DBLogger; 10 | import org.eclipse.jface.dialogs.DialogPage; 11 | import org.eclipse.jface.preference.FileFieldEditor; 12 | import org.eclipse.swt.SWT; 13 | import org.eclipse.swt.events.PaintEvent; 14 | import org.eclipse.swt.events.PaintListener; 15 | import org.eclipse.swt.graphics.Color; 16 | import org.eclipse.swt.graphics.GC; 17 | import org.eclipse.swt.graphics.Rectangle; 18 | import org.eclipse.swt.widgets.Composite; 19 | import org.eclipse.swt.widgets.Control; 20 | import org.eclipse.swt.widgets.Text; 21 | 22 | /** 23 | * This class extends the FileFieldEditor. It allows invalid filenames. 24 | * 25 | * @author Herve Jouin 26 | * 27 | */ 28 | public class DBFileFieldEditor extends FileFieldEditor { 29 | protected static final DBLogger logger = new DBLogger(DBFileFieldEditor.class); 30 | 31 | protected static final Color RED_COLOR = new Color(null, 255, 0 ,0); 32 | protected static final Color GREEN_COLOR = new Color(null, 0, 255 ,0); 33 | 34 | Color borderColor = null; 35 | 36 | /** 37 | * 38 | */ 39 | public DBFileFieldEditor() { 40 | super(); 41 | setFileExtensions(new String[] {"*.log", "*.txt", "*.*"}); 42 | addColoredBorder(getTextControl()); 43 | } 44 | 45 | /** 46 | * Creates a new file field editor 47 | * @param name 48 | * @param labelText 49 | * @param parent 50 | */ 51 | public DBFileFieldEditor(String name, String labelText, Composite parent) { 52 | super(name, labelText, false, parent); 53 | setFileExtensions(new String[] {"*.log", "*.txt", "*.*"}); 54 | addColoredBorder(getTextControl()); 55 | } 56 | 57 | /** 58 | * Creates a new file field editor 59 | * @param name 60 | * @param labelText 61 | * @param enforceAbsolute 62 | * @param parent 63 | */ 64 | public DBFileFieldEditor(String name, String labelText, boolean enforceAbsolute, Composite parent) { 65 | super(name, labelText, enforceAbsolute, VALIDATE_ON_KEY_STROKE, parent); 66 | setFileExtensions(new String[] {"*.log", "*.txt", "*.*"}); 67 | addColoredBorder(getTextControl()); 68 | } 69 | 70 | /** 71 | * Creates a new file field editor 72 | * @param name 73 | * @param labelText 74 | * @param enforceAbsolute 75 | * @param validationStrategy 76 | * @param parent 77 | */ 78 | public DBFileFieldEditor(String name, String labelText, boolean enforceAbsolute, int validationStrategy, Composite parent) { 79 | super(name, labelText, enforceAbsolute, validationStrategy, parent); 80 | setFileExtensions(new String[] {"*.log", "*.txt", "*.*"}); 81 | addColoredBorder(getTextControl()); 82 | } 83 | 84 | @Override protected boolean checkState() { 85 | boolean state = super.checkState(); 86 | DialogPage page = getPage(); 87 | Text text = getTextControl(); 88 | String path = text.getText(); 89 | 90 | 91 | if ( state ) { 92 | logger.debug("\""+path + "\" is a valid filename"); 93 | this.borderColor = GREEN_COLOR; 94 | text.setToolTipText(null); 95 | } else { 96 | logger.debug("\""+path + "\" is an invalid filename"); 97 | this.borderColor = RED_COLOR; 98 | if ( page != null ) 99 | text.setToolTipText(page.getErrorMessage()); 100 | } 101 | 102 | // we force the redraw of the text control's parent to refresh the border color 103 | getTextControl().getParent().redraw(); 104 | getTextControl().getParent().update(); 105 | 106 | // we always return true, else it may generate errors in Archi preferences 107 | return true; 108 | } 109 | 110 | protected void addColoredBorder(Control cont){ 111 | final Control control = cont; 112 | cont.getParent().addPaintListener(new PaintListener(){ 113 | @Override public void paintControl(PaintEvent e){ 114 | if ( DBFileFieldEditor.this.borderColor != null ) { 115 | GC gc = e.gc; 116 | gc.setBackground(DBFileFieldEditor.this.borderColor); 117 | Rectangle rect = control.getBounds(); 118 | Rectangle rect1 = new Rectangle(rect.x - 2, rect.y - 2, rect.width + 4, rect.height + 4); 119 | gc.setLineStyle(SWT.LINE_SOLID); 120 | gc.fillRectangle(rect1); 121 | } 122 | } 123 | }); 124 | } 125 | } 126 | --------------------------------------------------------------------------------