commit e458d248bcc5dda9cc75e5bdb61c869fbca9e9c9 Author: VogelT Date: Tue Dec 12 12:48:58 2023 +0100 Eclipse Plugin diff --git a/GeisPlugin/.classpath b/GeisPlugin/.classpath new file mode 100644 index 0000000..51e971f --- /dev/null +++ b/GeisPlugin/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/GeisPlugin/.project b/GeisPlugin/.project new file mode 100644 index 0000000..f90b728 --- /dev/null +++ b/GeisPlugin/.project @@ -0,0 +1,28 @@ + + + GeisPlugin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/GeisPlugin/.settings/org.eclipse.jdt.core.prefs b/GeisPlugin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0fee6a9 --- /dev/null +++ b/GeisPlugin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,15 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/GeisPlugin/.settings/org.eclipse.ltk.core.refactoring.prefs b/GeisPlugin/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 0000000..b196c64 --- /dev/null +++ b/GeisPlugin/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/GeisPlugin/META-INF/MANIFEST.MF b/GeisPlugin/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6b67eb1 --- /dev/null +++ b/GeisPlugin/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Geis Plugin +Bundle-SymbolicName: GeisPlugin;singleton:=true +Bundle-Version: 5.0.1 +Bundle-Activator: geisplugin.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.jdt.core;bundle-version="3.9.1" +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: libs/jxl.jar, + libs/cfr-0.152.jar, + . +Bundle-Vendor: Geis GmbH diff --git a/GeisPlugin/bin/geisplugin/Activator.class b/GeisPlugin/bin/geisplugin/Activator.class new file mode 100644 index 0000000..0f67f4b Binary files /dev/null and b/GeisPlugin/bin/geisplugin/Activator.class differ diff --git a/GeisPlugin/bin/geisplugin/Tools$DriverShim.class b/GeisPlugin/bin/geisplugin/Tools$DriverShim.class new file mode 100644 index 0000000..06c726c Binary files /dev/null and b/GeisPlugin/bin/geisplugin/Tools$DriverShim.class differ diff --git a/GeisPlugin/bin/geisplugin/Tools.class b/GeisPlugin/bin/geisplugin/Tools.class new file mode 100644 index 0000000..3542ff0 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/Tools.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/AddHeaderAction.class b/GeisPlugin/bin/geisplugin/popup/actions/AddHeaderAction.class new file mode 100644 index 0000000..6d23662 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/AddHeaderAction.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/CCJspGenerator.class b/GeisPlugin/bin/geisplugin/popup/actions/CCJspGenerator.class new file mode 100644 index 0000000..df6a011 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/CCJspGenerator.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/ChecksumLFS.class b/GeisPlugin/bin/geisplugin/popup/actions/ChecksumLFS.class new file mode 100644 index 0000000..80878b5 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/ChecksumLFS.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/ChecksumSingleFigure.class b/GeisPlugin/bin/geisplugin/popup/actions/ChecksumSingleFigure.class new file mode 100644 index 0000000..ae70ef2 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/ChecksumSingleFigure.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/ConvertToUTF8.class b/GeisPlugin/bin/geisplugin/popup/actions/ConvertToUTF8.class new file mode 100644 index 0000000..24939e1 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/ConvertToUTF8.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/DatabaseTableObjekt.class b/GeisPlugin/bin/geisplugin/popup/actions/DatabaseTableObjekt.class new file mode 100644 index 0000000..c9cbe89 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/DatabaseTableObjekt.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/Decompile.class b/GeisPlugin/bin/geisplugin/popup/actions/Decompile.class new file mode 100644 index 0000000..46d9d93 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/Decompile.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$1.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$1.class new file mode 100644 index 0000000..578f241 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$1.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$10.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$10.class new file mode 100644 index 0000000..3ae0b31 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$10.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$2.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$2.class new file mode 100644 index 0000000..0dbf78f Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$2.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$3.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$3.class new file mode 100644 index 0000000..244c0f9 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$3.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$4.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$4.class new file mode 100644 index 0000000..65c62c3 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$4.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$5.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$5.class new file mode 100644 index 0000000..512fd43 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$5.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$6.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$6.class new file mode 100644 index 0000000..593b71d Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$6.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$7.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$7.class new file mode 100644 index 0000000..ffc0c13 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$7.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$8.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$8.class new file mode 100644 index 0000000..023212e Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$8.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$9.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$9.class new file mode 100644 index 0000000..f5c930c Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$9.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel$1.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel$1.class new file mode 100644 index 0000000..3a706a9 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel$1.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel$Filter.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel$Filter.class new file mode 100644 index 0000000..2e8a4f0 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel$Filter.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel.class new file mode 100644 index 0000000..d96ddbc Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$FilteredListModel.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$MyListCellThing.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$MyListCellThing.class new file mode 100644 index 0000000..4f0a2b7 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$MyListCellThing.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$RequestFocusListener.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$RequestFocusListener.class new file mode 100644 index 0000000..486336b Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping$RequestFocusListener.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping.class new file mode 100644 index 0000000..0e28698 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateHibernateMapping.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateMapping.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateMapping.class new file mode 100644 index 0000000..8936cf5 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateMapping.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GenerateReflectionGetSet.class b/GeisPlugin/bin/geisplugin/popup/actions/GenerateReflectionGetSet.class new file mode 100644 index 0000000..1b7fa50 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GenerateReflectionGetSet.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GetMetaData.class b/GeisPlugin/bin/geisplugin/popup/actions/GetMetaData.class new file mode 100644 index 0000000..6f7b545 Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GetMetaData.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GetMetaDataTable.class b/GeisPlugin/bin/geisplugin/popup/actions/GetMetaDataTable.class new file mode 100644 index 0000000..dcc220a Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GetMetaDataTable.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/GetTableMetaData.class b/GeisPlugin/bin/geisplugin/popup/actions/GetTableMetaData.class new file mode 100644 index 0000000..b7d308a Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/GetTableMetaData.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/LinkClassWithManagedbeans.class b/GeisPlugin/bin/geisplugin/popup/actions/LinkClassWithManagedbeans.class new file mode 100644 index 0000000..ec7c03e Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/LinkClassWithManagedbeans.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/NESAS107.class b/GeisPlugin/bin/geisplugin/popup/actions/NESAS107.class new file mode 100644 index 0000000..d4e11ae Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/NESAS107.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/RemoveGenerateReflectionGetSet.class b/GeisPlugin/bin/geisplugin/popup/actions/RemoveGenerateReflectionGetSet.class new file mode 100644 index 0000000..853103a Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/RemoveGenerateReflectionGetSet.class differ diff --git a/GeisPlugin/bin/geisplugin/popup/actions/WhiteSpaceAction.class b/GeisPlugin/bin/geisplugin/popup/actions/WhiteSpaceAction.class new file mode 100644 index 0000000..475b91d Binary files /dev/null and b/GeisPlugin/bin/geisplugin/popup/actions/WhiteSpaceAction.class differ diff --git a/GeisPlugin/bin/icons/db.gif b/GeisPlugin/bin/icons/db.gif new file mode 100644 index 0000000..caa5aa3 Binary files /dev/null and b/GeisPlugin/bin/icons/db.gif differ diff --git a/GeisPlugin/bin/icons/geis.gif b/GeisPlugin/bin/icons/geis.gif new file mode 100644 index 0000000..f6f63bf Binary files /dev/null and b/GeisPlugin/bin/icons/geis.gif differ diff --git a/GeisPlugin/bin/icons/java.gif b/GeisPlugin/bin/icons/java.gif new file mode 100644 index 0000000..1461357 Binary files /dev/null and b/GeisPlugin/bin/icons/java.gif differ diff --git a/GeisPlugin/build.properties b/GeisPlugin/build.properties new file mode 100644 index 0000000..903b5ec --- /dev/null +++ b/GeisPlugin/build.properties @@ -0,0 +1,14 @@ + +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + libs/,\ + libs/cfr-0.152.jar + +jars.compile.order = . + +jre.compilation.profile = JavaSE-1.8 + +output.. = bin/ + +source.. = src/ diff --git a/GeisPlugin/libs/cfr-0.152.jar b/GeisPlugin/libs/cfr-0.152.jar new file mode 100644 index 0000000..7f6ddc4 Binary files /dev/null and b/GeisPlugin/libs/cfr-0.152.jar differ diff --git a/GeisPlugin/libs/jxl.jar b/GeisPlugin/libs/jxl.jar new file mode 100644 index 0000000..4a1fc64 Binary files /dev/null and b/GeisPlugin/libs/jxl.jar differ diff --git a/GeisPlugin/plugin.xml b/GeisPlugin/plugin.xml new file mode 100644 index 0000000..b27da85 --- /dev/null +++ b/GeisPlugin/plugin.xml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GeisPlugin/src/geisplugin/Activator.java b/GeisPlugin/src/geisplugin/Activator.java new file mode 100644 index 0000000..f881ef6 --- /dev/null +++ b/GeisPlugin/src/geisplugin/Activator.java @@ -0,0 +1,81 @@ +package geisplugin; + +//import java.io.File; +//import java.io.FileNotFoundException; +//import java.io.FileOutputStream; +//import java.io.PrintStream; +//import java.util.Date; + +import javax.swing.JFrame; +import javax.swing.UIManager; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author Huellmante + * @version 1.0 + * + */ + + +public class Activator extends AbstractUIPlugin { + +//Logging zum Testen +// static { +// try { +// System.setOut(new PrintStream(new FileOutputStream("C:/output.txt"), true)); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } +// try { +// System.setErr(new PrintStream(new FileOutputStream("C:/err.txt"), true)); +// } catch (FileNotFoundException e) { +// e.printStackTrace(); +// } +// } + + public static final String PLUGIN_ID = "hbmToPoJoPlugIn"; + + public final static JFrame frame = createPluginFrame(); + + private static JFrame createPluginFrame() { + try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch (Exception e){} + JFrame.setDefaultLookAndFeelDecorated(true); + JFrame frame = new JFrame("Geis Tools"); + frame.setLocationRelativeTo(null); + frame.pack(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + return frame; + } + + @Override + public void start(final BundleContext context) throws Exception { + super.start(context); + //JOptionPane.showMessageDialog(null, "start"); + } + + @Override + public void stop(final BundleContext context) throws Exception { + //JOptionPane.showMessageDialog(null, "stop"); + frame.dispose(); + super.stop(context); + } + + @SuppressWarnings("deprecation") + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/GeisPlugin/src/geisplugin/Tools.java b/GeisPlugin/src/geisplugin/Tools.java new file mode 100644 index 0000000..419c79b --- /dev/null +++ b/GeisPlugin/src/geisplugin/Tools.java @@ -0,0 +1,409 @@ +package geisplugin; + +import java.awt.Desktop; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.URL; +import java.net.URLClassLoader; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.DriverManager; +import java.sql.DriverPropertyInfo; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.logging.Logger; + +import javax.swing.JOptionPane; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.internal.core.PackageFragmentRoot; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.PlatformUI; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +//Cp1252 -> Default Eclipse Sourceencoding + +@SuppressWarnings("restriction") +public abstract class Tools { + + public static final String[] getDBs() { + Connection jdbc = null; + Statement stmt = null; + ResultSet rs = null; + try { + jdbc = getConnection(); + stmt = jdbc.createStatement(); + rs = stmt.executeQuery("SELECT TABLE_SCHEM||' - '||IFNULL(SCHEMA_TEXT, '') FROM SYSIBM.SQLSCHEMAS WHERE TABLE_CAT='GEISAS01'"); + final ArrayList localDBList = new ArrayList(512); + while (rs.next()) { + localDBList.add(rs.getString(1)); + } + return localDBList.toArray(new String[0]); + } catch (final Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + rs = null; + } + if (stmt != null) { + try { + stmt.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + stmt = null; + } + } + return new String[0]; + } + + public final static String[] getTables(final String db) { + Connection jdbc = null; + Statement stmt = null; + ResultSet rs = null; + try { + jdbc = Tools.getConnection(); + stmt = jdbc.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + rs = stmt.executeQuery("SELECT DISTINCT RTRIM(a.table_name)||' - '||b.TABLE_TEXT as a FROM sysibm.SQLColumns a INNER JOIN qsys2.systables b ON a.table_name = b.table_name AND a.table_schem = b.table_schema WHERE b.type != 'A' AND a.table_schem='" + db + "' AND b.table_schema='" + db + "' ORDER BY a"); + final ArrayList localTableList = new ArrayList(512); + while (rs.next()) { + localTableList.add(rs.getString(1)); + } + return localTableList.toArray(new String[0]); + } catch (final Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + rs = null; + } + if (stmt != null) { + try { + stmt.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + stmt = null; + } + } + return new String[0]; + } + + private static class DriverShim implements Driver { + private Driver driver; + private DriverShim(final Driver d) { + this.driver = d; + } + @Override + public boolean acceptsURL(final String u) throws SQLException { + return this.driver.acceptsURL(u); + } + @Override + public Connection connect(final String u, final Properties p) throws SQLException { + return this.driver.connect(u, p); + } + @Override + public int getMajorVersion() { + return this.driver.getMajorVersion(); + } + @Override + public int getMinorVersion() { + return this.driver.getMinorVersion(); + } + @Override + public DriverPropertyInfo[] getPropertyInfo(final String u, final Properties p) throws SQLException { + return this.driver.getPropertyInfo(u, p); + } + @Override + public boolean jdbcCompliant() { + return this.driver.jdbcCompliant(); + } + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return null; + } + } + + private static String getjt400Url() throws Exception { + final List pathList = new ArrayList(17); + pathList.add("C:/EnterpriseClient/tools/embeddedserver/webapps/editor/WEB-INF/lib/jt400.jar"); + pathList.add("C:/EnterpriseClient/server/tomcattools/webapps/editor/WEB-INF/lib/jt400.jar"); + pathList.add("C:/Program Files (x86)/Eclipse/jt400.jar"); + pathList.add("C:/Program Files/Eclipse/jt400.jar"); + pathList.add("C:/Program Files (x86)/Eclipse/plugins/jt400.jar"); + pathList.add("C:/Program Files/Eclipse/plugins/jt400.jar"); + pathList.add("C:/Users/"+ System.getProperty("user.name") + "/.razorsql/jtopen/jt400.jar"); + pathList.add("C:/Program Files (x86)/Argus/embeddedserver/webapps/argus_page/WEB-INF/lib/jt400.jar"); + pathList.add("C:/Program Files (x86)/ArgusTest/embeddedserver/webapps/argus_page/WEB-INF/lib/jt400.jar"); + pathList.add("C:/Program Files/Argus/embeddedserver/webapps/argus_page/WEB-INF/lib/jt400.jar"); + pathList.add("C:/Program Files/ArgusTest/embeddedserver/webapps/argus_page/WEB-INF/lib/jt400.jar"); + pathList.add("C:/Program Files/Argus/embeddedserver/webapps/argus_page/WEB-INF/lib/jt400.jar"); + + if (Platform.isRunning()) { + pathList.add((Platform.getInstallLocation().getURL().toString()+"jt400.jar").substring(6)); + pathList.add((Platform.getInstallLocation().getURL().toString()+"plugins/jt400.jar").substring(6)); + } + + pathList.add("C:/projects/argus_page_entw/webcontent/WEB-INF/lib/jt400.jar"); + pathList.add("C:/Program Files (x86)/IBM/Client Access/jt400/lib/jt400.jar"); + pathList.add("C:/Program Files/IBM/Client Access/jt400/lib/jt400.jar"); + + int i = 0; + for(; i != pathList.size(); ++i) { + if(new File(pathList.get(i)).exists()) { + return "file:/" + pathList.get(i); + } + } + + throw new Exception("Can't find the jt400.jar driver"); + } + + static private final String user = "SVCJOBI";//argus GCC2TST + static private final String password = "pw_8e0#164";//argus369 GCC2369 + + static private boolean driverLoaded = false; + + public static Connection con = null; + + public static Connection getConnection() throws Exception { + if(!driverLoaded) { + DriverManager.registerDriver((new DriverShim( ((Driver)Class.forName("com.ibm.as400.access.AS400JDBCDriver", true, new URLClassLoader(new URL[] { new URL(getjt400Url()) })).newInstance())))); + driverLoaded = true; + } + if (con == null || con.isClosed()) { + con = DriverManager.getConnection("jdbc:as400://as400/GEISDB01;metadata source=0;translate binary=true;naming=system", user, password); + con.setReadOnly(true); + con.setAutoCommit(false); + } + return con; + } + + public static String read(final String filename) throws IOException { + final StringBuilder text = new StringBuilder(); + final char[] buffer = new char[0xFFFF]; + + InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(filename)), "Cp1252"); + try { + int len = 0; + while ((len = reader.read(buffer)) != -1) { + text.append(buffer, 0, len); + } + } finally { + reader.close(); + } + return text.toString(); + } + + public static void write(final String filename, final String text) throws IOException { + if(filename==null || filename.equals("nullnull")) + return; + + String folderName = filename; + + if(folderName.endsWith(".xml") || folderName.endsWith(".java")) { + folderName = folderName.substring(0, filename.lastIndexOf('\\')); + } + File f = new File(filename); + try { + new File(folderName).mkdirs(); + } + catch(Exception e) {} + f.createNewFile(); + OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), "Cp1252"); + try { + writer.write(text); + writer.flush(); + } finally { + writer.close(); + } + } + + public static String readUTF8(final String filename) throws IOException { + final StringBuilder text = new StringBuilder(); + final char[] buffer = new char[0xFFFF]; + + InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(filename)), "UTF-8"); + try { + int len = 0; + while ((len = reader.read(buffer)) != -1) { + text.append(buffer, 0, len); + } + } finally { + reader.close(); + } + return text.toString(); + } + + public static void writeUTF8withFolderCreation(final String filename, final String text) throws IOException { + if(filename==null || filename.equals("nullnull")) + return; + + String folderName = filename; + + if(folderName.endsWith(".xml") || folderName.endsWith(".java")) { + folderName = folderName.substring(0, filename.lastIndexOf('\\')); + } + File f = new File(filename); + try { + new File(folderName).mkdirs(); + } + catch(Exception e) {} + f.createNewFile(); + OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), "UTF-8"); + try { + writer.write(text); + writer.flush(); + } finally { + writer.close(); + } + } + + public static void writeUTF8(final String filename, final String text) throws IOException { + if(filename==null || filename.equals("nullnull")) + return; + File f = new File(filename); + f.createNewFile(); + OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), "UTF-8"); + try { + writer.write(text); + writer.flush(); + } finally { + writer.close(); + } + } + + public static void writeNoPathCreation(final String filename, final String text) throws IOException { + File f = new File(filename); + f.createNewFile(); + OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(f), "Cp1252"); + try { + writer.write(text); + writer.flush(); + } finally { + writer.close(); + } + } + + public static IProject getCurrentSelectedProject() throws Exception { + + IProject project = null; + + if (Platform.isRunning()) { + ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); + + if(selection instanceof IStructuredSelection) { + Object element = ((IStructuredSelection)selection).getFirstElement(); + + if (element instanceof IResource) { + project= ((IResource)element).getProject(); + } else if (element instanceof PackageFragmentRoot) { + IJavaProject jProject = ((PackageFragmentRoot)element).getJavaProject(); + project = jProject.getProject(); + } else if (element instanceof IJavaElement) { + IJavaProject jProject= ((IJavaElement)element).getJavaProject(); + project = jProject.getProject(); + } + } + } + return project; + } + + public static String trimEnd(final String source) { + int pos = source.length() - 1; + while ((pos >= 0) && Character.isWhitespace((int) source.charAt(pos))) { + pos--; + } + pos++; + return (pos < source.length()) ? source.substring(0, pos) : source; + } + + + //UPDATE GEISDTA.GXPADAT SET PAKEY1 = '2.9', PATXT = '\\nesfs001\install$\Java\Eclipse Plugin\GeisPlugin_2.9.0.jar', PALAED = 09082017, PALAET = 1052 WHERE PAID = 25834; + public static boolean isNotUpToDate() { + boolean result = false; + Connection con = null; + try { + con = getConnection(); + } catch (Exception e1) { + e1.printStackTrace(); + return true; + } + try ( + Statement ps = con.createStatement(); + ResultSet rs = ps.executeQuery("SELECT PAKEY1 from GEISDTA.GXPADAT WHERE PAID=25834 AND PAWERT='GEISPLUGIN'") + ) { + if (rs.next()) { + //System.out.println(new Double(rs.getString(1))); + result = (new Double(rs.getString(1)) > 5.0); + } + + } catch (final Exception e) { + e.printStackTrace(); + } + + if (result) { + if (JOptionPane.showConfirmDialog(Activator.frame, "A Plugin-Update is available, do you want to continue [Yes] or to update [No] ?", "Update", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + result = false; + } else { + try { + Desktop.getDesktop().open(new File("\\\\nesfs001\\install$\\Java\\Eclipse Plugin")); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + return result; + } + + public static void transform(File source, String srcEncoding, File target, String tgtEncoding) throws IOException { + try ( + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(source), srcEncoding)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(target), tgtEncoding)); ) { + char[] buffer = new char[16384]; + int read; + while ((read = br.read(buffer)) != -1) + bw.write(buffer, 0, read); + } + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/AddHeaderAction.java b/GeisPlugin/src/geisplugin/popup/actions/AddHeaderAction.java new file mode 100644 index 0000000..852f231 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/AddHeaderAction.java @@ -0,0 +1,233 @@ +package geisplugin.popup.actions; + + +import geisplugin.Tools; + +import java.sql.SQLException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + + +public class AddHeaderAction extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + Shell shell = HandlerUtil.getActiveShell(event); + for (final Object firstElement : ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).toList()) { + try { + if (firstElement instanceof ICompilationUnit) { + createOutput(shell, firstElement); + } else { + MessageDialog.openInformation(shell, "Info", "Please select Java source file"); + } + } catch (Exception e) { + MessageDialog.openError(shell, "Fehler", "Fehler " + e.getMessage()); + } + } + return null; + } + + private void createOutput(final Shell shell, final Object firstElement) { + ICompilationUnit cu = (ICompilationUnit) firstElement; + String file = cu.getResource().getRawLocation().toString(); + + try { + + String fileAsString = Tools.read(file); + + if (fileAsString.contains("* Program changes\n")) { + MessageDialog.openError(shell, "Error", "Already existing!"); + return; + } + + int index = 0; + + int b = fileAsString.indexOf("public class"); + if (b != -1) { + index = b; + } + + b = fileAsString.indexOf("public final class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("public final static class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("public static final class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private final class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private final static class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private static final class"); + if (b != -1 && b < index) { + index = b; + } + + + b = fileAsString.indexOf("public abstract class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private abstract class"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("public interface"); + if (b != -1) { + index = b; + } + + b = fileAsString.indexOf("public final interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("public final static interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("public static final interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private final interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private final static interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private static final interface"); + if (b != -1 && b < index) { + index = b; + } + + + b = fileAsString.indexOf("public abstract interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private abstract interface"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("public enum"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private enum"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("public final enum"); + if (b != -1 && b < index) { + index = b; + } + + b = fileAsString.indexOf("private final enum"); + if (b != -1 && b < index) { + index = b; + } + + String a = fileAsString.substring(0, index).trim(); + String header = "\n\n/**\n * DE: \n *\n * EN: \n * \n * \n * Program changes\n * **************************************************************************************\n * Date\t\t\t* Ticket\t* KonzFirm\t* Responsible\t* programmer *\n * Change\t\t\t\t\t\t\t\t\t\t*\n * **************************************************************************************\n *\n * @author "+System.getProperty("user.name")+"\n * @version 1.0\n *\n */"; + + if (!a.isEmpty()) { + int y = a.lastIndexOf("import"); + if(y > -1) { + a = a.substring(y).trim(); + } + y = a.indexOf('\n'); + if(y > -1) { + a = a.substring(0, a.indexOf('\n')).trim(); + } + fileAsString = fileAsString.replace(a,a + header); + } else { + //MessageDialog.openInformation(shell, "Info","Imports/Package are missing."); + fileAsString = header.trim() + "\n\n" + fileAsString; + } + Tools.writeNoPathCreation(file, fileAsString); + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (final Exception e) { + MessageDialog.openError(shell, "Fehler", "Fehler!\n"+e.getMessage()); + } + } +} \ No newline at end of file diff --git a/GeisPlugin/src/geisplugin/popup/actions/CCJspGenerator.java b/GeisPlugin/src/geisplugin/popup/actions/CCJspGenerator.java new file mode 100644 index 0000000..4d40884 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/CCJspGenerator.java @@ -0,0 +1,110 @@ +package geisplugin.popup.actions; + +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import geisplugin.Tools; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class CCJspGenerator extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + Shell shell = HandlerUtil.getActiveShell(event); + + String path = ""; + try { + path = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile().getCanonicalPath()+Tools.getCurrentSelectedProject().getFullPath().toString().replace('/', '\\')+"\\"; + } catch (Exception e) {} + + //MessageDialog.openInformation(shell, "path", path); + + File webcontent = new File(path+"webcontent/"); + + if (path == null || path.isEmpty() || !webcontent.exists() || !webcontent.isDirectory()) { + MessageDialog.openError(shell, "Info", "Error, can't find a valid webcontent path."); + return null; + } + + path += "webcontent\\"; + + InputDialog dia = new InputDialog(shell, "Set your .jsp path", "Set your .jsp path after "+path, "", null); + dia.open(); + + String jsp = dia.getValue(); + + if (jsp.isEmpty()) { + MessageDialog.openError(shell, "Error", "Empty path."); + return null; + } + + if (!jsp.toLowerCase().endsWith(".jsp")) { + jsp += ".jsp"; + } + + File newJspFile = new File(path+jsp); + newJspFile.getParentFile().mkdirs(); + + try { + Tools.writeNoPathCreation(newJspFile.getAbsolutePath(), "<%@page contentType=\"text/html\"%>\r\n<%@page pageEncoding=\"UTF-8\"%>\r\n\r\n<%@taglib prefix=\"f\" uri=\"http://java.sun.com/jsf/core\"%>\r\n<%@taglib prefix=\"h\" uri=\"http://java.sun.com/jsf/html\"%>\r\n\r\n@@taglibraries@@\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n"); + } catch (final IOException e) { + MessageDialog.openError(shell, "Error", e.getMessage()); + e.printStackTrace(); + return null; + } + + try { + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (final Exception e) { + MessageDialog.openError(shell, "Info", "Error, can't refresh your workplace automatically"); + } + + return null; + } + +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/ChecksumLFS.java b/GeisPlugin/src/geisplugin/popup/actions/ChecksumLFS.java new file mode 100644 index 0000000..fa22575 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/ChecksumLFS.java @@ -0,0 +1,105 @@ +package geisplugin.popup.actions; + + +import geisplugin.Activator; +import geisplugin.Tools; + +import java.sql.SQLException; + +import javax.swing.JOptionPane; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + + +public class ChecksumLFS extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + String originalLFSNumber = JOptionPane.showInputDialog(Activator.frame, "Calculate LFS checksum of:"); + if (originalLFSNumber != null && originalLFSNumber.trim().length() == 9) { + originalLFSNumber = originalLFSNumber.trim(); + JOptionPane.showMessageDialog(Activator.frame, Integer.toString(getCreateLFSPruefziffer(originalLFSNumber))); + } else { + JOptionPane.showMessageDialog(Activator.frame, "The number has to be 9 digits long!"); + } + return null; + + } + + private static int getCreateLFSPruefziffer(final String originalLFSNumber) { + /* + * Berechnung der 1-stelligen Prüfziffer für + * + * 1=Behälteretiketten + * 2=LE-Etiketten + * 3=Packstücketiketten + * 4=Lagerplatz + * + */ + + int zahlInt = 0; + String zahlString = null; + int summeInt = 0; + int tmpSummeInt = 0; + int gewichtung = 1; + + try { + if (originalLFSNumber.length() == 9) { + for (int i = 0; i < originalLFSNumber.length(); ++i) { + if (gewichtung == 3) { + gewichtung = 1; + } else if (gewichtung == 1) { + gewichtung = 3; + } + zahlString = originalLFSNumber.substring(i, i + 1); + zahlInt = Integer.parseInt(zahlString); + tmpSummeInt = gewichtung * zahlInt; + summeInt = summeInt + tmpSummeInt; + } + summeInt = 10 - (summeInt % 10); + } + } catch (final Exception e) { + e.printStackTrace(); + } + return (summeInt == 10) ? 0 : summeInt; + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/ChecksumSingleFigure.java b/GeisPlugin/src/geisplugin/popup/actions/ChecksumSingleFigure.java new file mode 100644 index 0000000..82aee96 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/ChecksumSingleFigure.java @@ -0,0 +1,79 @@ +package geisplugin.popup.actions; + + +import geisplugin.Activator; +import geisplugin.Tools; + +import java.math.BigInteger; +import java.sql.SQLException; + +import javax.swing.JOptionPane; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + + +public class ChecksumSingleFigure extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + String originalValue = JOptionPane.showInputDialog(Activator.frame, "Calculate single figure checksum of:"); + if (originalValue != null && !originalValue.trim().isEmpty()) { + originalValue = originalValue.trim(); + JOptionPane.showMessageDialog(Activator.frame, Integer.toString(berechnePZ1(originalValue))); + } + return null; + } + + private static int berechnePZ1(final String wert) { + int mp = 3; + int pz = 0; + BigInteger bi = null; + for (int pos = wert.length() - 1; pos >= 0; pos--) { + bi = new BigInteger(wert.substring(pos, pos + 1)); + pz = pz + (bi.intValue() * mp); + mp = (mp == 3) ? 1 : 3; + } + pz = 10 - (pz % 10); + if (pz == 10) { + pz = 0; + } + return pz; + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/ConvertToUTF8.java b/GeisPlugin/src/geisplugin/popup/actions/ConvertToUTF8.java new file mode 100644 index 0000000..f33a012 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/ConvertToUTF8.java @@ -0,0 +1,86 @@ +package geisplugin.popup.actions; + +import geisplugin.Tools; + +import java.sql.SQLException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class ConvertToUTF8 extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + Shell shell = HandlerUtil.getActiveShell(event); + for (Object firstElement : ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).toList()) { + try { + if (firstElement instanceof ICompilationUnit) { + createOutput(shell, firstElement); + } else { + MessageDialog.openInformation(shell, "Info", "Please select Java file, not a " + firstElement.getClass().getCanonicalName()); + } + } catch (Exception e) { + MessageDialog.openError(shell, "Fehler", "Fehler " + e.getMessage()); + } + } + return null; + } + + private void createOutput(final Shell shell, final Object firstElement) { + ICompilationUnit cu = (ICompilationUnit) firstElement; + String file = cu.getResource().getRawLocation().toString(); + try { + + String fileAsString = Tools.read(file); + + Tools.writeUTF8(file, fileAsString); + + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (final Exception e) { + MessageDialog.openError(shell, "Error", "Error!\n " + e.getMessage()); + } + + } +} \ No newline at end of file diff --git a/GeisPlugin/src/geisplugin/popup/actions/DatabaseTableObjekt.java b/GeisPlugin/src/geisplugin/popup/actions/DatabaseTableObjekt.java new file mode 100644 index 0000000..d4d1832 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/DatabaseTableObjekt.java @@ -0,0 +1,65 @@ +package geisplugin.popup.actions; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class DatabaseTableObjekt { + + private final boolean id; + private final String columnTypeString; + private final String columnLabelString; + private final int columnTypeInt, precision, scale; + private final boolean notnullable; + + public boolean isID() { + return id; + } + + public String getColumnTypeString() { + return columnTypeString; + } + + public String getColumnLabelString() { + return columnLabelString; + } + + public int getColumnTypeInt() { + return columnTypeInt; + } + + public int getPrecision() { + return precision; + } + + public int getScale() { + return scale; + } + + public boolean isNotnullable() { + return notnullable; + } + + public DatabaseTableObjekt(final String columnTypeString, final String columnLabelString, final int columnTypeInt, final int scale, final int precision, final boolean id, final boolean notnullable, final int columnDisplaySize) { + this.columnTypeString = columnTypeString; + this.columnLabelString = columnLabelString; + this.columnTypeInt = columnTypeInt; + this.scale = scale; + this.precision = columnTypeString.equals("NCHAR") ? columnDisplaySize : precision; + this.id = id; + this.notnullable = notnullable; + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/Decompile.java b/GeisPlugin/src/geisplugin/popup/actions/Decompile.java new file mode 100644 index 0000000..ab70b45 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/Decompile.java @@ -0,0 +1,102 @@ +package geisplugin.popup.actions; + + +import java.awt.Desktop; +import java.io.File; +import java.sql.SQLException; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileNameExtensionFilter; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; + +import geisplugin.Activator; +import geisplugin.Tools; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class Decompile extends AbstractHandler { + + public static void main(final String[] args) { + new Decompile().execute(null); + System.exit(0); + } + + public static String createStringStackTrace(final Throwable e) { + final StringBuilder stackTrace = new StringBuilder(); + stackTrace.append(e.getClass().getName()); + if (e.getMessage() != null && !e.getMessage().trim().isEmpty()) { + stackTrace.append(": "); + stackTrace.append(e.getMessage()); + } + for (final StackTraceElement element : e.getStackTrace()) { + stackTrace.append("\tat "); + stackTrace.append(element.toString()); + stackTrace.append('\n'); + } + return stackTrace.toString(); + } + + @Override + public Object execute(final ExecutionEvent event) { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + try { + JFileChooser chooser = new JFileChooser(); + FileNameExtensionFilter filter = new FileNameExtensionFilter("Java Files (*.jar, *.class)", "jar", "class"); + chooser.setFileFilter(filter); + chooser.setAcceptAllFileFilterUsed(false); + if (chooser.showOpenDialog(Activator.frame) == JFileChooser.APPROVE_OPTION) { + File inputFile = chooser.getSelectedFile(); + if (!inputFile.exists()) { + JOptionPane.showMessageDialog(Activator.frame, inputFile.getCanonicalPath() + " does not exist!"); + return null; + } + File outputFolder = new File(inputFile.getCanonicalPath() + "_sources\\"); + if (!outputFolder.isDirectory() && !outputFolder.mkdir()) { + JOptionPane.showMessageDialog(Activator.frame, outputFolder.getCanonicalPath() + " can't get created!"); + return null; + } + org.benf.cfr.reader.Main.main(new String[] { inputFile.getCanonicalPath(), "--outputdir", outputFolder.getCanonicalPath() + "\\" }); + Desktop.getDesktop().open(outputFolder); + } + } catch (final Throwable e) { + e.printStackTrace(); + JOptionPane.showMessageDialog(Activator.frame, createStringStackTrace(e)); + } + return null; + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/GenerateHibernateMapping.java b/GeisPlugin/src/geisplugin/popup/actions/GenerateHibernateMapping.java new file mode 100644 index 0000000..c10be9d --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/GenerateHibernateMapping.java @@ -0,0 +1,1536 @@ +package geisplugin.popup.actions; + +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Robot; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +import javax.swing.AbstractListModel; +import javax.swing.BorderFactory; +import javax.swing.DefaultListModel; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.ListCellRenderer; +import javax.swing.ListModel; +import javax.swing.ListSelectionModel; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.event.ListDataEvent; +import javax.swing.event.ListDataListener; +import javax.swing.filechooser.FileSystemView; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +import geisplugin.Activator; +import geisplugin.Tools; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class GenerateHibernateMapping { + + private final static Color alt = new Color(245, 245, 245); + private final static Color selectionBackgroundColor = new Color(51, 153, 255); + + public class MyListCellThing extends JLabel implements ListCellRenderer { + + private static final long serialVersionUID = 1L; + + public MyListCellThing() { + setOpaque(true); + } + + @Override + public Component getListCellRendererComponent(JList list, String value, int index, boolean isSelected, boolean cellHasFocus) { + setText(value.toString()); + if (isSelected) { + setBackground(selectionBackgroundColor); + setForeground(Color.white); + } else { + setForeground(Color.black); + if (index % 2 == 0) { + setBackground(Color.white); + } else { + setBackground(alt); + } + } + return this; + } + } + + private static Shell shell = null; + + public static class FilteredListModel extends AbstractListModel { + + private static final long serialVersionUID = 1L; + + public static interface Filter { + boolean accept(Object element); + } + + private final ListModel _source; + private Filter _filter; + private final ArrayList _indices = new ArrayList(); + + public FilteredListModel(ListModel source) { + if (source == null) + throw new IllegalArgumentException("Source is null"); + _source = source; + _source.addListDataListener(new ListDataListener() { + @Override + public void intervalRemoved(ListDataEvent e) { + doFilter(); + } + + @Override + public void intervalAdded(ListDataEvent e) { + doFilter(); + } + + @Override + public void contentsChanged(ListDataEvent e) { + doFilter(); + } + }); + } + + public void setFilter(Filter f) { + _filter = f; + doFilter(); + } + + private void doFilter() { + _indices.clear(); + + Filter f = _filter; + if (f != null) { + int count = _source.getSize(); + for (int i = 0; i < count; i++) { + Object element = _source.getElementAt(i); + if (f.accept(element)) { + _indices.add(i); + } + } + fireContentsChanged(this, 0, getSize() - 1); + } + } + + @Override + public int getSize() { + return (_filter != null) ? _indices.size() : _source.getSize(); + } + + @Override + public String getElementAt(int index) { + return (_filter != null) ? _source.getElementAt(_indices.get(index)) : _source.getElementAt(index); + } + } + + public static class RequestFocusListener implements AncestorListener + { + private boolean removeListener; + + /* + * Convenience constructor. The listener is only used once and then it is + * removed from the component. + */ + public RequestFocusListener() + { + this(true); + } + + /* + * Constructor that controls whether this listen can be used once or + * multiple times. + * + * @param removeListener when true this listener is only invoked once + * otherwise it can be invoked multiple times. + */ + public RequestFocusListener(boolean removeListener) + { + this.removeListener = removeListener; + } + + @Override + public void ancestorAdded(AncestorEvent e) + { + JComponent component = e.getComponent(); + component.requestFocusInWindow(); + + if (removeListener) + component.removeAncestorListener( this ); + } + + @Override + public void ancestorMoved(AncestorEvent e) {} + + @Override + public void ancestorRemoved(AncestorEvent e) {} + } + + public GenerateHibernateMapping(final Shell shell2, final String path) { + + try { + + shell = shell2; + + String[] dbs = null; + + try { + dbs = Tools.getDBs(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + + if (dbs == null || dbs.length == 0) { + MessageDialog.openError(shell, "Error 1", "Couldn't find any databases, go sure your AS400 driver does exist and read the plugin documentation!"); + return; + } + + String db = ""; + //(String) JOptionPane.showInputDialog(Activator.frame, "Which Database?", "Select a Database", JOptionPane.PLAIN_MESSAGE, null, dbs, "GEISDTT"); + + { + final DefaultListModel source = new DefaultListModel(); + Stream.of(dbs).forEach(source::addElement); + final FilteredListModel filteredListModel = new FilteredListModel(source); + final JList list = new JList(filteredListModel); + final JScrollPane panel = new JScrollPane(list); + final JTextField filter = new JTextField(); + filter.addAncestorListener(new RequestFocusListener()); + filteredListModel.setFilter(new FilteredListModel.Filter() { + @Override + public boolean accept(final Object element) { + return filter.getText().isEmpty() || element.toString().toUpperCase().startsWith(filter.getText().toUpperCase()); + } + }); + final JPanel pane = new JPanel(); + filter.addActionListener(e -> { + list.requestFocusInWindow(); + final Robot robot; + try { + robot = new Robot(); + robot.keyPress(KeyEvent.VK_ENTER); + } catch (AWTException e1) { + e1.printStackTrace(); + } + }); + filter.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + int lastSelectedIndex = list.getSelectedIndex(); + if (lastSelectedIndex != list.getModel().getSize()) { + list.setSelectedIndex(++lastSelectedIndex); + list.ensureIndexIsVisible(lastSelectedIndex); + } + } else if (e.getKeyCode() == KeyEvent.VK_UP) { + int lastSelectedIndex = list.getSelectedIndex(); + if (lastSelectedIndex != 0) { + list.setSelectedIndex(--lastSelectedIndex); + list.ensureIndexIsVisible(lastSelectedIndex); + } + } + } + }); + filter.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void removeUpdate(final DocumentEvent e) { + filteredListModel.doFilter(); + panel.getVerticalScrollBar().setValue(0); + list.setSelectedIndex(0); + } + + @Override + public void insertUpdate(final DocumentEvent e) { + filteredListModel.doFilter(); + panel.getVerticalScrollBar().setValue(0); + list.setSelectedIndex(0); + } + + @Override + public void changedUpdate(final DocumentEvent e) { + filteredListModel.doFilter(); + panel.getVerticalScrollBar().setValue(0); + list.setSelectedIndex(0); + } + }); + list.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent evt) { + @SuppressWarnings("unchecked") + final JList list = (JList) evt.getSource(); + if (evt.getClickCount() == 2) { + int index = list.locationToIndex(evt.getPoint()); + list.setSelectedIndex(index); + list.requestFocusInWindow(); + final Robot robot; + try { + robot = new Robot(); + robot.keyPress(KeyEvent.VK_ENTER); + } catch (final AWTException e1) { + e1.printStackTrace(); + } + } + } + }); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.setCellRenderer(new MyListCellThing()); + list.setBorder(BorderFactory.createEmptyBorder ( 5, 5, 5, 5 ) ); + list.addAncestorListener(new AncestorListener() { + + @Override + public void ancestorRemoved(final AncestorEvent event) { + } + + @Override + public void ancestorMoved(final AncestorEvent event) { + } + + @Override + public void ancestorAdded(final AncestorEvent event) { + list.requestFocusInWindow(); + list.setSelectedIndex(0); + } + }); + pane.setLayout(new BorderLayout()); + pane.add(panel, BorderLayout.CENTER); + + pane.add(filter, BorderLayout.PAGE_END); + if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(Activator.frame, pane, "Choose your Database from GEISDB01", JOptionPane.OK_CANCEL_OPTION)) { + return; + } + db = list.getModel().getElementAt(list.getSelectedIndex()); + } + + + dbs = null; + + if (db != null && !db.trim().isEmpty()) { + db = db.substring(0, db.indexOf(" - ")); + final String[] tables = Tools.getTables(db); + + if (tables == null || tables.length == 0) { + JOptionPane.showMessageDialog(Activator.frame, "Couldn't find any table!"); + return; + } + + final DefaultListModel source = new DefaultListModel(); + Stream.of(tables).forEach(source::addElement); + final FilteredListModel filteredListModel = new FilteredListModel(source); + final JList list = new JList(filteredListModel); + final JScrollPane panel = new JScrollPane(list); + final JTextField filter = new JTextField(); + filter.addAncestorListener(new RequestFocusListener()); + filteredListModel.setFilter(new FilteredListModel.Filter() { + @Override + public boolean accept(final Object element) { + return filter.getText().isEmpty() || element.toString().toUpperCase().startsWith(filter.getText().toUpperCase()); + } + }); + final JPanel pane = new JPanel(); + filter.addActionListener(e -> { + list.requestFocusInWindow(); + final Robot robot; + try { + robot = new Robot(); + robot.keyPress(KeyEvent.VK_ENTER); + } catch (final AWTException e1) { + e1.printStackTrace(); + } + }); + filter.getDocument().addDocumentListener(new DocumentListener() { + + @Override + public void removeUpdate(final DocumentEvent e) { + filteredListModel.doFilter(); + panel.getVerticalScrollBar().setValue(0); + list.setSelectedIndex(0); + } + + @Override + public void insertUpdate(final DocumentEvent e) { + filteredListModel.doFilter(); + panel.getVerticalScrollBar().setValue(0); + list.setSelectedIndex(0); + } + + @Override + public void changedUpdate(final DocumentEvent e) { + filteredListModel.doFilter(); + panel.getVerticalScrollBar().setValue(0); + list.setSelectedIndex(0); + } + }); + filter.addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(final KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DOWN) { + int lastSelectedIndex = list.getSelectedIndex(); + if (lastSelectedIndex != list.getModel().getSize()) { + list.setSelectedIndex(++lastSelectedIndex); + list.ensureIndexIsVisible(lastSelectedIndex); + } + } else if (e.getKeyCode() == KeyEvent.VK_UP) { + int lastSelectedIndex = list.getSelectedIndex(); + if (lastSelectedIndex != 0) { + list.setSelectedIndex(--lastSelectedIndex); + list.ensureIndexIsVisible(lastSelectedIndex); + } + } + } + }); + list.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent evt) { + @SuppressWarnings("unchecked") + final JList list = (JList) evt.getSource(); + if (evt.getClickCount() == 2) { + int index = list.locationToIndex(evt.getPoint()); + list.setSelectedIndex(index); + list.requestFocusInWindow(); + final Robot robot; + try { + robot = new Robot(); + robot.keyPress(KeyEvent.VK_ENTER); + } catch (AWTException e1) { + e1.printStackTrace(); + } + } + } + }); + list.setCellRenderer(new MyListCellThing()); + list.setBorder(BorderFactory.createEmptyBorder ( 5, 5, 5, 5 ) ); + list.addAncestorListener(new AncestorListener() { + + @Override + public void ancestorRemoved(final AncestorEvent event) { + } + + @Override + public void ancestorMoved(final AncestorEvent event) { + } + + @Override + public void ancestorAdded(final AncestorEvent event) { + list.requestFocusInWindow(); + list.setSelectedIndex(0); + } + }); + pane.setLayout(new BorderLayout()); + pane.add(panel, BorderLayout.CENTER); + + pane.add(filter, BorderLayout.PAGE_END); + + if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Activator.frame, pane, "Choose your table(s) from GEISDB01." + db, JOptionPane.YES_NO_OPTION)) { + return; + } + String currentTable = null; + + int[] selectedIndexes = list.getSelectedIndices(); + if (selectedIndexes == null || selectedIndexes.length == 0) { + return; + } + + int n; + if ((path.contains("\\geis_shared\\") || path.contains("\\geis_database\\") || path.contains("\\geis_database_entw\\") || path.contains("\\ServerSocked_MC9090\\") || path.contains("\\ServerSocked_MC9090_TEST\\")) && path.contains("\\src\\")) { + n = 1; + } else if ((path.contains("\\argus_page\\") || path.contains("\\argus_page_entw\\") || path.contains("\\gcc2\\") || path.contains("\\gcc2_entw\\") || path.contains("\\geiswebportal\\") || path.contains("\\geiswebportal_entw\\")) && path.contains("\\src\\")) { + n = 0; + } else { + Object[] options = { "XML + PoJo", "PoJo with Annotations", "Cancel" }; + n = JOptionPane.showOptionDialog(Activator.frame, "Choose the output format of your mappings.", "Output format", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); + options = null; + if (n == -1 || n == 2) { + return; + } + } + + for (final int currentSelectedIndex : selectedIndexes) { + currentTable = list.getModel().getElementAt(currentSelectedIndex).trim().toUpperCase(); + currentTable = currentTable.substring(0, currentTable.indexOf(" -")); + String tableHeading = list.getModel().getElementAt(currentSelectedIndex).trim().substring(list.getModel().getElementAt(currentSelectedIndex).trim().indexOf(" - ") + 3); + switch (n) { + case 0: + try { + String resultXMLString = convert(currentTable, db, path + '\\' + currentTable.toUpperCase() + '\\' + Character.toUpperCase(currentTable.charAt(0)) + currentTable.substring(1, currentTable.length()).toLowerCase() + ".java"); + final String outputFile = path + '\\' + currentTable.toUpperCase() + '\\' + Character.toUpperCase(currentTable.charAt(0)) + currentTable.substring(1, currentTable.length()).toLowerCase() + ".hbm.xml"; + Tools.write(outputFile, resultXMLString); + createPoJo(shell, outputFile, db, currentTable, tableHeading); + } catch (final IOException e) { + e.printStackTrace(); + } + break; + case 1: { + String resultXMLString = convert(currentTable, db, path + '\\' + currentTable.toUpperCase() + '\\' + Character.toUpperCase(currentTable.charAt(0)) + currentTable.substring(1, currentTable.length()).toLowerCase() + ".java"); + if (tableHeading.endsWith(" -")) { + tableHeading = tableHeading.substring(0, tableHeading.length() - 2); + } + createOutput(currentTable, db, resultXMLString, path + '\\' + currentTable.toUpperCase() + '\\' + Character.toUpperCase(currentTable.charAt(0)) + currentTable.substring(1, currentTable.length()).toLowerCase() + ".java", tableHeading); + + if ((path.contains("\\GeisPlugin\\") || path.contains("\\geis_shared\\") || path.contains("\\geis_database\\") || path.contains("\\geis_database_entw\\")) && path.contains("\\src\\")) { + try { + final File cfg_xml = new File(path.substring(0, path.indexOf("src")+4) + "META-INF\\" + db + ".cfg.xml"); + if (cfg_xml.exists()) { + try { + String inputXML = Tools.readUTF8(cfg_xml.toString()); + final String mappingClass = path.substring(path.indexOf("src")+4).replace('\\', '.') + '.' + currentTable.toUpperCase() + '.' + Character.toUpperCase(currentTable.charAt(0)) + currentTable.substring(1, currentTable.length()).toLowerCase(); + if (!inputXML.contains(mappingClass)) { + inputXML = inputXML.replace("", "\t\n\t"); + Tools.writeUTF8withFolderCreation(cfg_xml.toString(), inputXML); + } + } catch (final Exception e) { + e.printStackTrace(); + } + } else { + final File cfg_mvn_xml = new File(path.substring(0, path.indexOf("\\src\\main\\java\\") + 9) + "\\resources\\META-INF\\" + db + ".cfg.xml"); + final String mappingClass = path.substring(path.indexOf("\\src\\main\\java\\") + 15).replace('\\', '.') + '.' + currentTable.toUpperCase() + '.' + Character.toUpperCase(currentTable.charAt(0)) + currentTable.substring(1, currentTable.length()).toLowerCase(); + if (cfg_mvn_xml.exists()) { + try { + String inputXML = Tools.readUTF8(cfg_mvn_xml.toString()); + if (!inputXML.contains(mappingClass)) { + inputXML = inputXML.replace("", "\t\n\t"); + Tools.writeUTF8withFolderCreation(cfg_mvn_xml.toString(), inputXML); + } + } catch (final Exception e) { + e.printStackTrace(); + } + } + } + + } catch (final Exception e) { + if (Platform.isRunning() && shell != null) { + MessageDialog.openError(shell, "Fehler", e.getClass() + " - " + e.getMessage() + "\nPlease go sure that you are using the latest plugin version!"); + } else { + e.printStackTrace(); + } + } + } + break; + } + } + } + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (final SQLException e) { + e.printStackTrace(); + } + } + } + + private void createPoJo(final Shell shell, final String firstElement, String DB, String table, String tableHeading) { + final Map columnHeadings = getColumnHeadings(DB, table); + sql_type = ""; + buf = ""; + try { + String paggageStr = ""; + try { + paggageStr = firstElement.substring(firstElement.lastIndexOf("src\\") + 4, firstElement.length()); + paggageStr = paggageStr.replace('\\', '.'); + paggageStr = paggageStr.split(".hbm.xml")[0]; + paggageStr = "package " + paggageStr.substring(0, paggageStr.lastIndexOf('.')) + ';'; + } catch (final Exception e) { + MessageDialog.openInformation(shell, "", "patsch"); + } + + String filepath = firstElement; + filepath = filepath.replace("/", "\\"); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + + dbFactory.setValidating(false); + dbFactory.setNamespaceAware(true); + dbFactory.setFeature("http://xml.org/sax/features/namespaces", false); + dbFactory.setFeature("http://xml.org/sax/features/validation", false); + dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); + dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + dBuilder.toString(); + //System.out.println(filepath); + Document doc = dBuilder.parse(filepath); + doc.getDocumentElement().normalize(); + String className = doc.getElementsByTagName("class").item(0).getAttributes().getNamedItem("table").getNodeValue(); + className = className.substring(0, 1).toUpperCase() + className.substring(1).toLowerCase(); + String outputFilePath = filepath.subSequence(0, filepath.lastIndexOf('\\')) + "\\" + className + ".java"; + if (new File(outputFilePath).exists() && Platform.isRunning() && shell != null) { + if (!MessageDialog.openQuestion(shell, "File existing", "PoJo is already existing! Do you want to overwrite it?")) { + return; + } + } + + buf += (paggageStr + "\n\n" + "import java.util.Date;\n" + "import java.io.Serializable;\n" + "import java.math.BigDecimal;\n" + "import java.math.BigInteger;\n\n" + "/**" + (tableHeading != null && !tableHeading.trim().isEmpty() ? "\n * " + tableHeading : "") + "\n * DE: \n *\n * EN: \n * \n * \n * Program changes\n * **************************************************************************************\n * Date\t\t\t* Ticket\t* KonzFirm\t* Responsible\t* programmer *\n * Change\t\t\t\t\t\t\t\t\t\t*\n * **************************************************************************************\n *\n * @author " + System.getProperty("user.name") + "\n * @version 1.0\n *\n */" + "\n\npublic class " + className + " implements Serializable {\n\n\tprivate static final long serialVersionUID = 1L;\n"); + + NodeList nodes = doc.getElementsByTagName("property"); + try { + String id = doc.getElementsByTagName("id").item(0).getAttributes().getNamedItem("name").getNodeValue(); + + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** " + columnHeadings.get(id.toUpperCase()) + "*/"; + } + + if (keyType.get(id.toUpperCase()).equals("integer")) { + buf += ("\n\tprivate Integer " + id + " = null;"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic Integer get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final Integer " + id + ") { this." + id + " = " + id + "; }\n"); + } else { + int size = keyLength.get(id.toUpperCase()); + if (size > 18) { + buf += ("\n\tprivate BigDecimal " + id + " = null;"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic BigDecimal get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final BigDecimal " + id + ") { this." + id + " = " + id + "; }\n"); + } else if (size > 9) { + buf += ("\n\tprivate Long " + id + " = null;"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic Long get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final Long " + id + ") { this." + id + " = " + id + "; }\n"); + } else { + buf += ("\n\tprivate Integer " + id + " = null;"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic Integer get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final Integer " + id + ") { this." + id + " = " + id + "; }\n"); + } + } + + } catch (final Exception e) { + } + + NodeList compID = doc.getElementsByTagName("key-property"); + if (compID != null && compID.getLength() > 0) { + createMappingNoAnnotations(compID, shell, columnHeadings); + } + + createMappingNoAnnotations(nodes, shell, columnHeadings); + + + buf += "\n}"; + if (!buf.contains("public BigDecimal ")) { + buf = buf.replace("import java.math.BigDecimal;\n", ""); + } + if (!buf.contains("public BigInteger ")) { + buf = buf.replace("import java.math.BigInteger;\n", ""); + } + if (!buf.contains("public Date ")) { + buf = buf.replace("import java.util.Date;\n", ""); + } + Tools.write(outputFilePath, buf); + try { + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (final Exception e) { + } + } catch (final Exception e) { + if (Platform.isRunning() && shell != null) { + MessageDialog.openError(shell, "Fehler", "Fehlernummer " + "!\n " + e.getMessage() + "Please go sure that you are using the latest plugin version!\n\nSQL Type:" + sql_type); + } else { + e.printStackTrace(); + } + } + } + + private void createMappingNoAnnotations(final NodeList nodes, final Shell shell, final Map columnHeadings) { + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + String type = ""; + String name = node.getAttributes().getNamedItem("name").getNodeValue(); + String getSetName = Character.toUpperCase(name.charAt(0)) + name.toLowerCase().substring(1, name.length()); + if (columnHeadings.containsKey(name.toUpperCase())) { + buf += "\n\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/"; + } + try { + sql_type = ((Element) node).getElementsByTagName("column").item(0).getAttributes().getNamedItem("sql-type").getNodeValue(); + } catch (Exception e) { + sql_type = node.getAttributes().getNamedItem("type").getNodeValue().trim(); + if (sql_type.equals("string")) { + sql_type = "character"; + sql_type += "(" + node.getAttributes().getNamedItem("length").getNodeValue().trim() + ")"; + } + } + + if (sql_type.startsWith("decimal")) { + sql_type = sql_type.replaceAll("decimal", "numeric"); + sql_type = sql_type.substring(0, sql_type.length() - 1) + ",0)"; + } + + if (sql_type.startsWith("character") || sql_type.startsWith("varchar") || sql_type.startsWith("nchar") || sql_type.startsWith("clob")) { + buf += ("\n\tprivate String " + name + " = \"\";"); + type = "String"; + } else { + + if (sql_type.startsWith("numeric")) { + int nachKommaStellen = Integer.valueOf(sql_type.substring(sql_type.lastIndexOf(',') + 1, sql_type.length() - 1)); + int size = Integer.valueOf(sql_type.substring(sql_type.indexOf('(') + 1, sql_type.lastIndexOf(','))); + + if (nachKommaStellen == 0) { + if (size > 18) { + buf += ("\n\tprivate BigDecimal " + name + " = BigDecimal.ZERO;"); + type = "BigDecimal"; + } else if (size > 9) { + buf += ("\n\tprivate Long " + name + " = 0L;"); + type = "Long"; + } else { + buf += ("\n\tprivate Integer " + name + " = 0;"); + type = "Integer"; + } + } else { + buf += ("\n\tprivate Double " + name + " = 0.0D;"); + type = "Double"; + + } + } else + if (sql_type.startsWith("short")) { + buf += ("\n\tprivate Short " + name + " = 0;"); + type = "Short"; + } else + if (sql_type.startsWith("date") || sql_type.startsWith("timestamp") || sql_type.startsWith("time")) { + buf += ("\n\tprivate Date " + name + " = null;"); + type = "Date"; + } else if (sql_type.startsWith("integer")) { + buf += ("\n\tprivate Integer " + name + " = 0;"); + type = "Integer"; + } else { + MessageDialog.openInformation(shell, "Info", "Unknown type:\n" + sql_type); + continue; + } + } + if (columnHeadings.containsKey(name.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(name.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic " + type + " get" + getSetName + "() { return " + name + "; }"); + if (columnHeadings.containsKey(name.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(name.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + getSetName + "(final " + type + " " + name + ") { this." + name + " = " + name + "; }\n"); + } + } + } + + //private final static String url = "jdbc:as400://as400;metadata source=0"; + + private String buf = ""; + private String sql_type = ""; + private List primKeys = new ArrayList(); + private Map keyLength = new HashMap(); + private Map keyType = new HashMap(); + + private List getPrimaryKeys(final String db, final String table) { + StringBuilder sql = new StringBuilder() + .append(" select ") + .append(" RTRIM(c.column_name)") + .append(" from qsys2.syscolumns c") + .append(" join qsys2.systables t") + .append(" on c.table_schema = t.table_schema") + .append(" and c.table_name = t.table_name") + .append(" left outer join sysibm.sqlstatistics k") + .append(" on c.table_schema = k.table_schem") + .append(" and c.table_name = k.table_name") + .append(" and c.table_name = k.index_name") + .append(" and c.column_name = k.column_name") + .append(" where c.table_schema = '").append(db).append("'") + .append(" and c.table_name = '").append(table).append("'") + .append(" and k.ordinal_position IS NOT NULL") + .append(" ORDER BY k.ordinal_position"); + /** + .append(" SELECT") + .append(" RTRIM(DBKFLD)") + .append(" FROM") + .append(" QSYS.QADBXREF") + .append(" LEFT JOIN") + .append(" QSYS.QADBKFLD") + .append(" on DBXFIL = DBKFIL and DBXLIB = DBKLIB") + .append(" WHERE") + .append(" DBXLIB = '").append(db).append("'") + .append(" and DBXLFI='").append(table).append("'") + .append(" ORDER BY DBKPOS"); + **/ + + Connection jdbc = null; + + try { + jdbc = Tools.getConnection(); + try (Statement stmt = jdbc.createStatement(); + ResultSet rs = stmt.executeQuery(sql.toString());) { + final List result = new ArrayList(); + while (rs.next()) { + result.add(rs.getString(1)); + } + return result; + } + } catch (Exception e) { + e.printStackTrace(); + } + return Collections.emptyList(); + } + + public Map getColumnDefault(final String db, final String table) { + Connection jdbc = null; + Statement stmt = null; + ResultSet rs = null; + + try { + jdbc = Tools.getConnection(); + stmt = jdbc.createStatement(); + rs = stmt.executeQuery("SELECT RTRIM(a.COLUMN_NAME), RTRIM(b.COLUMN_DEFAULT) FROM qsys2.SYSCOLUMNS a LEFT JOIN qsys2.columns b ON a.TBNAME=b.TABLE_NAME AND a.TABLE_SCHEMA = b.TABLE_SCHEMA AND a.COLUMN_NAME = b.COLUMN_NAME WHERE a.TBNAME = '" + table + "' AND a.TABLE_SCHEMA = '" + db + "' AND b.COLUMN_DEFAULT IS NOT NULL AND b.COLUMN_DEFAULT != ''''''"); + + final Map descriptions = new HashMap(); + + while (rs.next()) { + descriptions.put(rs.getString(1).toUpperCase(), rs.getString(2)); + } + + return descriptions; + } catch (final Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + rs = null; + } + if (stmt != null) { + try { + stmt.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + stmt = null; + } + } + return Collections.emptyMap(); + } + + public Map getColumnHeadings(final String db, final String table) { + Connection jdbc = null; + Statement stmt = null; + ResultSet rs = null; + + try { + jdbc = Tools.getConnection(); + stmt = jdbc.createStatement(); + rs = stmt.executeQuery("SELECT RTRIM(COLUMN_NAME), RTRIM(COLUMN_HEADING) FROM qsys2.SYSCOLUMNS WHERE TBNAME = '" + table + "' AND TABLE_SCHEMA = '" + db + "' AND COLUMN_HEADING != '' ORDER BY ORDINAL_POSITION ASC"); + + final Map descriptions = new HashMap(); + + while (rs.next()) { + descriptions.put(rs.getString(1).toUpperCase(), rs.getString(2)); + } + + return descriptions; + } catch (final Exception e) { + e.printStackTrace(); + } finally { + if (rs != null) { + try { + rs.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + rs = null; + } + if (stmt != null) { + try { + stmt.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + stmt = null; + } + } + return Collections.emptyMap(); + } + + private LinkedHashMap getTable(final String db, final String table) { + LinkedHashMap tablesMap = new LinkedHashMap(); + + Connection jdbc = null; + try { + jdbc = Tools.getConnection(); + ResultSet rs = jdbc.getMetaData().getPrimaryKeys(null, db, table); + while (rs.next()) { + primKeys.add(rs.getString(4));//"COLUMN_NAME" + } + if (rs != null) { + rs.close(); + rs = null; + } + } catch (final Exception e) { + e.printStackTrace(); + } + + try { + jdbc = Tools.getConnection(); + Statement stmt = jdbc.createStatement(); + String sql = "SELECT * FROM " + db + '.' + table; + stmt.setFetchSize(1); + ResultSet rs = stmt.executeQuery(sql); + ResultSetMetaData rsmd = rs.getMetaData(); + boolean hasID = false; + + for (int i = 1; i < rsmd.getColumnCount() + 1; ++i) { + boolean ID = false; + if (i == 1 && rsmd.isSigned(i) && rsmd.isReadOnly(i) && rsmd.isNullable(i) == ResultSetMetaData.columnNoNulls && rsmd.isSearchable(i) && !rsmd.isCaseSensitive(i) && rsmd.getColumnType(i) == 4 && rsmd.getColumnName(i).toUpperCase().contains("ID")) { + if (!primKeys.contains(rsmd.getColumnTypeName(i))) { + ID = true; + } + } + //System.out.println(rsmd.getColumnName(i)+ " precision: " + rsmd.getPrecision(i) + " scale: " + rsmd.getScale(i) + " type: " + rsmd.getColumnTypeName(i)); + DatabaseTableObjekt local = new DatabaseTableObjekt(rsmd.getColumnTypeName(i), rsmd.getColumnLabel(i), rsmd.getColumnType(i), rsmd.getScale(i), rsmd.getPrecision(i), ID, rsmd.isNullable(i) == 0, rsmd.getColumnDisplaySize(i)); + //System.out.println(rsmd.getColumnLabel(i) + " " + rsmd.getColumnTypeName(i)); + tablesMap.put(rsmd.getColumnName(i), local); + keyLength.put(rsmd.getColumnLabel(i), rsmd.getPrecision(i)); + keyType.put(rsmd.getColumnLabel(i), rsmd.getColumnTypeName(i).toLowerCase()); + if (local.isID()) { + hasID = true; + } + } + + if (primKeys.isEmpty() && !hasID) { + primKeys.addAll(getPrimaryKeys(db, table)); + if (primKeys.isEmpty() && !hasID) { + if (Platform.isRunning()) { + MessageDialog.openInformation(shell, "Warning", "Please manually modify your mapping file later, no ID field was found in " + db + "." + table); + } else { + JOptionPane.showOptionDialog(Activator.frame, "Please manually modify your mapping file later, no ID field was found in " + db + "." + table, "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null); + } + } + } + + if (rs != null) { + rs.close(); + rs = null; + } + if (stmt != null) { + stmt.close(); + stmt = null; + } + } catch (final Exception e) { + e.printStackTrace(); + } + return tablesMap; + } + + private String convert(final String table, final String DB, final String pack) { + //System.out.println(pack); + primKeys.clear(); + LinkedHashMap myTable = getTable(DB, table); + + final Map defaults = getColumnDefault(DB, table); + + String paggageStr = ""; + try { + if (pack.contains("\\src\\main\\java\\de\\geis\\datenbanken")) { + paggageStr = pack.substring(pack.lastIndexOf("src\\main\\java\\") + 14, pack.length()); + } else { + paggageStr = pack.substring(pack.lastIndexOf("src\\") + 4, pack.length()); + } + paggageStr = paggageStr.replace('\\', '.'); + paggageStr = paggageStr.split(".java")[0]; + paggageStr = paggageStr.substring(0, paggageStr.lastIndexOf('.')); + } catch (final Exception e) { + e.printStackTrace(); + if (shell != null) { + MessageDialog.openInformation(shell, "", "patsch"); + } + } + + StringBuilder resultString = new StringBuilder(); + resultString.append("\n\n\n\t\n"); + + if (!primKeys.isEmpty()) { + + if (primKeys.size() > 1) { + + resultString.append("\t\t\n"); + for (String myStr : primKeys) { + DatabaseTableObjekt currentDBObj = myTable.get(myStr); + String myStrLower = myStr.toLowerCase(); + resultString.append("\t\t\t\n"); + } + resultString.append("\t\t\n"); + } else { + DatabaseTableObjekt currentDBObj = myTable.get(primKeys.get(0)); + if (currentDBObj.getColumnTypeString().toLowerCase().equals("bigint") || (currentDBObj.getColumnTypeString().toLowerCase().equals("numeric") && currentDBObj.getPrecision() > 18)) { + resultString.append("\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n"); + + } else { + resultString.append("\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n"); + } + } + } + + for (final String local : myTable.keySet()) { + + if (primKeys.contains(local)) + continue; + + DatabaseTableObjekt currentDBObj = myTable.get(local); + String localLower = local.toLowerCase(); + + if (currentDBObj.isID() && primKeys.isEmpty()) { + resultString.append("\t\t\n\t\t\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n"); + continue; + } + + resultString.append("\t\t\n"); + } + resultString.append("\t\n"); + + return resultString.toString(); + } + + @SuppressWarnings("static-access") + public static void main(final String[] args) { + //Um Design beim Ausführen über Main-Methode zu laden + Activator.frame.isDefaultLookAndFeelDecorated(); +// new GenerateHibernateMapping(null, "C:\\projects\\GeisPlugin\\src\\main\\java\\de\\geis\\datenbanken"); + + new GenerateHibernateMapping(null, FileSystemView.getFileSystemView().getHomeDirectory().toString()); + System.exit(0); + } + + private void createOutput(final String table, final String DB, final String xml, final String outputFilePath, final String tableHeading) { + sql_type = ""; + buf = ""; + final Map columnHeadings = getColumnHeadings(DB, table); + try { + + String packageStr = ""; + try { + if (outputFilePath.contains("\\src\\main\\java\\de\\geis\\datenbanken")) { + packageStr = outputFilePath.substring(outputFilePath.lastIndexOf("src\\main\\java\\") + 14, outputFilePath.length()); + } else { + packageStr = outputFilePath.substring(outputFilePath.lastIndexOf("src\\") + 4, outputFilePath.length()); + } + packageStr = packageStr.replace('\\', '.'); + packageStr = packageStr.split(".java")[0]; + packageStr = "package " + packageStr.substring(0, packageStr.lastIndexOf('.')) + ';'; + } catch (final Exception e) { + e.printStackTrace(); + if (shell != null) { + MessageDialog.openInformation(shell, "Error 2", e.getMessage()); + } + } + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + + dbFactory.setValidating(false); + dbFactory.setNamespaceAware(true); + dbFactory.setFeature("http://xml.org/sax/features/namespaces", false); + dbFactory.setFeature("http://xml.org/sax/features/validation", false); + dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); + dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(new InputSource(new StringReader(xml))); + doc.getDocumentElement().normalize(); + String className = doc.getElementsByTagName("class").item(0).getAttributes().getNamedItem("table").getNodeValue(); + className = className.substring(0, 1).toUpperCase() + className.substring(1).toLowerCase(); + + buf += (packageStr + "\n\n" + "import java.util.Date;\n" + "import java.io.Serializable;\nimport javax.persistence.*;\n\nimport org.hibernate.annotations.Type;\n\n" + "import java.math.BigDecimal;\n\n" + "import java.math.BigInteger;\n\n" + "/**" + (tableHeading != null && !tableHeading.trim().isEmpty() ? "\n * " + tableHeading : "") + "\n * DE: \n *\n * EN: \n * \n * \n * Program changes\n * **************************************************************************************\n * Date\t\t\t* Ticket\t* KonzFirm\t* Responsible\t* programmer *\n * Change\t\t\t\t\t\t\t\t\t\t*\n * **************************************************************************************\n *\n * @author " + System.getProperty("user.name") + "\n * @version 1.0\n *\n */" + "\n\n@Entity\n" + "@Table(name=\"" + className.toUpperCase() + "\")\n" + "//@NamedQuery(name=\"" + className + ".findAll\", query=\"SELECT g FROM " + className.toUpperCase() + " g WHERE g.konzPLACEHOLDER=:konzPLACEHOLDER AND g.firmPLACEHOLDER=:firmPLACEHOLDER\")\n" + "public class " + className + " implements Serializable {\n\n\tprivate static final long serialVersionUID = 1L;\n"); + + NodeList nodes = doc.getElementsByTagName("property"); + try { + String id = doc.getElementsByTagName("id").item(0).getAttributes().getNamedItem("name").getNodeValue(); + try { + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** " + columnHeadings.get(id.toUpperCase()) + "*/"; + } + buf += "\n\t@Id\n\t@GeneratedValue(strategy=GenerationType.IDENTITY)\n\t@Column(unique=true, nullable=false)\n\t"; + if (keyType.get(id.toUpperCase()).equals("integer")) { + buf += "private Integer " + id + " = null;"; + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic Integer get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()).toLowerCase() + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final Integer " + id + ") { this." + id + " = " + id + "; }\n"); + } else { + int size = keyLength.get(id.toUpperCase()); + if (size > 18) { + buf += "private BigDecimal " + id + " = null;"; + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic BigDecimal get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()).toLowerCase() + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final BigDecimal " + id + ") { this." + id + " = " + id + "; }\n"); + } else if (size > 9) { + buf += "private Long " + id + " = null;"; + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic Long get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()).toLowerCase() + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final Long " + id + ") { this." + id + " = " + id + "; }\n"); + } else { + buf += "private Integer " + id + " = null;"; + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic Integer get" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()).toLowerCase() + "() { return " + id + "; }"); + if (columnHeadings.containsKey(id.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(id.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + Character.toUpperCase(id.charAt(0)) + id.substring(1, id.length()) + "(final Integer " + id + ") { this." + id + " = " + id + "; }\n"); + } + } + + } catch (final Exception e) { + e.printStackTrace(); + if (shell != null) { + MessageDialog.openInformation(shell, "Error 3", e.getMessage()); + } + } + } catch (Exception e) { + + } + + Map defaults = getColumnDefault(DB, table); + + NodeList compID = doc.getElementsByTagName("key-property"); + if (compID != null && compID.getLength() > 0) { + createMappingWithAnnotations(compID, true, columnHeadings, defaults); + } + + createMappingWithAnnotations(nodes, false, columnHeadings, defaults); + + + if (buf.contains(" g WHERE g.konzPLACEHOLDER=:konzPLACEHOLDER AND g.firmPLACEHOLDER=:firmPLACEHOLDER")) { + buf = buf.replaceAll(" g WHERE g.konzPLACEHOLDER=:konzPLACEHOLDER AND g.firmPLACEHOLDER=:firmPLACEHOLDER", ""); + } + + buf += "\n}"; + if (!buf.contains("public BigDecimal ")) { + buf = buf.replace("import java.math.BigDecimal;\n", ""); + } + if (!buf.contains("public BigInteger ")) { + buf = buf.replace("import java.math.BigInteger;\n", ""); + } + if (!buf.contains("public Date ")) { + buf = buf.replace("import java.util.Date;\n", ""); + buf = buf.replace("import org.hibernate.annotations.Type;\n\n", ""); + } + Tools.writeUTF8withFolderCreation(outputFilePath, buf); + } catch (final Exception e) { + e.printStackTrace(); + if (shell != null) { + MessageDialog.openInformation(shell, "Error 4", e.getMessage()); + } + } + } + + private void createMappingWithAnnotations(final NodeList nodes, final boolean id, final Map columnHeadings, final Map defaults) { + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + + if (node.getNodeType() == Node.ELEMENT_NODE) { + boolean notNullable = false; + String type = ""; + String name = node.getAttributes().getNamedItem("name").getNodeValue(); + String getSetName = Character.toUpperCase(name.charAt(0)) + name.toLowerCase().substring(1, name.length()); + try { + sql_type = ((Element) node).getElementsByTagName("column").item(0).getAttributes().getNamedItem("sql-type").getNodeValue(); + } catch (Exception e) { + sql_type = node.getAttributes().getNamedItem("type").getNodeValue().trim(); + if (sql_type.equals("string")) { + sql_type = "character"; + sql_type += "(" + node.getAttributes().getNamedItem("length").getNodeValue().trim() + ")"; + } + } + try { + if (((Element) node).getElementsByTagName("column").item(0).getAttributes().getNamedItem("not-null").getNodeValue().equals("true")) { + notNullable = true; + } + } catch (Exception e) { + + } + + if (sql_type.startsWith("varchar")) { + sql_type = sql_type.replaceAll("varchar", "character"); + } + + if (sql_type.startsWith("decimal")) { + sql_type = sql_type.replaceAll("decimal", "numeric"); + sql_type = sql_type.substring(0, sql_type.length() - 1) + ",0)"; + } + + if (id) { + if (columnHeadings.containsKey(name.toUpperCase())) { + buf += "\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/\n"; + } + if (defaults.containsKey(name.toUpperCase())) { + switch (defaults.get(name.toUpperCase())) { + case "USER": + case "CURRENT_TIMESTAMP": + buf += "\t@Generated(GenerationTime.ALWAYS)\n"; + break; + } + } + buf += ("\n\n\t@Id\n"); + } else { + buf += ("\n\n"); + } + + if (sql_type.startsWith("integer")) { + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/\n"; + } + if (!id && defaults.containsKey(name.toUpperCase())) { + switch (defaults.get(name.toUpperCase())) { + case "USER": + case "CURRENT_TIMESTAMP": + buf += "\t@Generated(GenerationTime.ALWAYS)\n"; + break; + } + } + if (notNullable) { + buf += ("\t@Column(nullable = false)"); + } else { + buf += ("\t@Column"); + } + buf += ("\n\tprivate Integer " + name + " = 0;"); + type = "Integer"; + } else if (sql_type.startsWith("character") || sql_type.startsWith("nchar") || sql_type.startsWith("graphic") || sql_type.startsWith("clob")) { + if (name.endsWith("konz")) { + buf = buf.replaceAll("konzPLACEHOLDER", name); + } + + else + if (name.endsWith("firm")) { + buf = buf.replaceAll("firmPLACEHOLDER", name); + } + + int size = 0; + if (sql_type.startsWith("character")) { + size = Integer.valueOf(sql_type.substring(10, sql_type.length() - 1)); + } else if (sql_type.startsWith("graphic")) { + size = Integer.valueOf(sql_type.substring(8, sql_type.length() - 1)); + } else if (sql_type.startsWith("clob")) { + size = Integer.valueOf(sql_type.substring(5, sql_type.length() - 1)); + } else { + size = Integer.valueOf(sql_type.substring(6, sql_type.length() - 1)); + } + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/\n"; + } + if (!id && defaults.containsKey(name.toUpperCase())) { + switch (defaults.get(name.toUpperCase())) { + case "USER": + case "CURRENT_TIMESTAMP": + buf += "\t@Generated(GenerationTime.ALWAYS)\n"; + break; + } + } + if (notNullable) { + buf += ("\t@Column(length=" + size + ", nullable = false)"); + } else { + buf += ("\t@Column(length=" + size + ")"); + } + buf += ("\n\tprivate String " + name + " = \"\";"); + type = "String"; + } + + else { + if (sql_type.startsWith("numeric")) { + int nachKommaStellen = Integer.valueOf(sql_type.substring(sql_type.lastIndexOf(',') + 1, sql_type.length() - 1)); + int size = Integer.valueOf(sql_type.substring(sql_type.indexOf('(') + 1, sql_type.lastIndexOf(','))); + + if (nachKommaStellen == 0) { + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/\n"; + } + if (!id && defaults.containsKey(name.toUpperCase())) { + switch (defaults.get(name.toUpperCase())) { + case "USER": + case "CURRENT_TIMESTAMP": + buf += "\t@Generated(GenerationTime.ALWAYS)\n"; + break; + } + } + if (notNullable) { + buf += ("\t@Column(precision=" + size + ", nullable = false)"); + } else { + buf += ("\t@Column(precision=" + size + ")"); + } + if (size > 18) { + buf += ("\n\tprivate BigDecimal " + name + " = BigDecimal.ZERO;"); + type = "BigDecimal"; + } else if (size > 9) { + buf += ("\n\tprivate Long " + name + " = 0L;"); + type = "Long"; + + } else { + buf += ("\n\tprivate Integer " + name + " = 0;"); + type = "Integer"; + } + } else { + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/\n"; + } + if (!id && defaults.containsKey(name.toUpperCase())) { + switch (defaults.get(name.toUpperCase())) { + case "USER": + case "CURRENT_TIMESTAMP": + buf += "\t@Generated(GenerationTime.ALWAYS)\n"; + break; + } + } + if (notNullable) { + buf += ("\t@Column(precision=" + size + ", scale=" + nachKommaStellen + ", nullable = false)"); + } else { + buf += ("\t@Column(precision=" + size + ", scale=" + nachKommaStellen + ")"); + } + buf += ("\n\tprivate Double " + name + " = 0.0D;"); + type = "Double"; + + } + } + + else { + + if (sql_type.startsWith("short")) { + int size = Integer.valueOf(sql_type.substring(sql_type.indexOf('(') + 1, sql_type.lastIndexOf(')'))); + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/\n"; + } + if (!id && defaults.containsKey(name.toUpperCase())) { + switch (defaults.get(name.toUpperCase())) { + case "USER": + case "CURRENT_TIMESTAMP": + buf += "\t@Generated(GenerationTime.ALWAYS)\n"; + break; + } + } + if (notNullable) { + buf += ("\t@Column(precision=" + size + ", nullable = false)"); + } else { + buf += ("\t@Column(precision=" + size + ")"); + } + buf += ("\n\tprivate Short " + name + " = 0;"); + type = "Short"; + } else + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\t" + "/** " + columnHeadings.get(name.toUpperCase()) + "*/\n"; + } + if (!id && defaults.containsKey(name.toUpperCase())) { + switch (defaults.get(name.toUpperCase())) { + case "USER": + case "CURRENT_TIMESTAMP": + buf += "\t@Generated(GenerationTime.ALWAYS)\n"; + break; + } + } + if (sql_type.startsWith("timestamp")) { + buf += ("\t@Column\n\t@Type(type=\"timestamp\")"); + buf += ("\n\tprivate Date " + name + " = null;"); + type = "Date"; + } else if (sql_type.startsWith("date")) { + buf += ("\t@Column\n\t@Type(type=\"date\")"); + buf += ("\n\tprivate Date " + name + " = null;"); + type = "Date"; + } else if (sql_type.startsWith("time")) { + buf += ("\t@Column\n\t@Type(type=\"time\")"); + buf += ("\n\tprivate Date " + name + " = null;"); + type = "Date"; + } else { + MessageDialog.openInformation(shell, "Info", "Unknown type:\n" + sql_type); + continue; + } + } + } + + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\n\t" + "/** get \"" + columnHeadings.get(name.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic " + type + " get" + getSetName + "() { return " + name + "; }"); + if (!id && columnHeadings.containsKey(name.toUpperCase())) { + buf += "\n\t" + "/** set \"" + columnHeadings.get(name.toUpperCase()) + "\"*/"; + } + buf += ("\n\tpublic void set" + getSetName + "(final " + type + " " + name + ") { this." + name + " = " + name + "; }\n"); + + if (buf.contains("@Generated(GenerationTime.ALWAYS)") && !buf.contains("import org.hibernate.annotations.Generated")) { + buf = buf.replaceFirst(Pattern.quote("import org.hibernate.annotations.Type;"), "import org.hibernate.annotations.Generated;\nimport org.hibernate.annotations.GenerationTime;\nimport org.hibernate.annotations.Type;"); + } + } + } + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/GenerateMapping.java b/GeisPlugin/src/geisplugin/popup/actions/GenerateMapping.java new file mode 100644 index 0000000..2b41481 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/GenerateMapping.java @@ -0,0 +1,73 @@ +package geisplugin.popup.actions; + +import geisplugin.Tools; + +import java.io.File; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class GenerateMapping extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + if (Tools.isNotUpToDate()) { + return null; + } + Shell shell = HandlerUtil.getActiveShell(event); + + String path = ""; + try { + path = Tools.getCurrentSelectedProject().getLocation().toFile().toString().replace('/', '\\') + "\\"; + } catch (Exception e) { + } + + if (path.isEmpty()) { + MessageDialog.openInformation(shell, "Info", "Error, can't find a valid DB path, using desktop"); + path = "C:\\Users" + System.getProperty("user.name") + "\\Desktop"; + } else { + if (new File(path + "\\src\\main\\java\\de\\geis\\datenbanken").isDirectory()) { + path += "\\src\\main\\java\\de\\geis\\datenbanken"; + } else if (new File(path + "src\\all\\geis\\db").isDirectory()) { + path += "src\\all\\geis\\db"; + } else + if (new File(path + "src\\de\\geis\\db").isDirectory()) { + path += "src\\de\\geis\\db"; + } else { + path += "src\\de\\geis\\datenbanken"; + } + } + + new GenerateHibernateMapping(shell, path); + + try { + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (final Exception e) { + MessageDialog.openError(shell, "Info", "Error, can't refresh your workplace automatically"); + } + + return null; + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/GenerateReflectionGetSet.java b/GeisPlugin/src/geisplugin/popup/actions/GenerateReflectionGetSet.java new file mode 100644 index 0000000..012db0a --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/GenerateReflectionGetSet.java @@ -0,0 +1,98 @@ +package geisplugin.popup.actions; + +import geisplugin.Tools; + +import java.sql.SQLException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class GenerateReflectionGetSet extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + Shell shell = HandlerUtil.getActiveShell(event); + for (Object firstElement : ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).toList()) { + try { + if (firstElement instanceof ICompilationUnit) { + createOutput(shell, firstElement); + } else { + MessageDialog.openInformation(shell, "Info", "Please select Java file"); + } + } catch (Exception e) { + MessageDialog.openError(shell, "Fehler", "Fehler " + e.getMessage()); + } + } + return null; + } + + private void createOutput(final Shell shell, final Object firstElement) { + ICompilationUnit cu = (ICompilationUnit) firstElement; + String file = cu.getResource().getRawLocation().toString(); + try { + + String fileAsString = Tools.read(file); + + int where = fileAsString.lastIndexOf('}'); + + String afterEnd = ""; + + if (where < fileAsString.length()) { + afterEnd = fileAsString.substring(where + 1); + } + + fileAsString = fileAsString.substring(0, where) + "\n\tpublic void set(String fieldname, Object value) {\t\t\n\t\t\ttry {\n\t\t\t\tif (value != null) {\n\t\t\t\t\t\n\t\t\t\t\tif (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.String\") ) {\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, value);\t\n\t\t\t\t\t\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.Long\") ) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (value == null)\n\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, Long.parseLong(value.toString()));\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.Integer\") ) {\n\t\t\t\t\t\tif (value.toString().trim().length() == 0)\n\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, Integer.parseInt(value.toString()));\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.Double\") ) {\n\t\t\t\t\t\tif (value.toString().trim().length() == 0)\n\t\t\t\t\t\t\tvalue = 0.0;\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, Double.parseDouble(value.toString()));\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.util.Date\") ) {\n\t\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, value);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t} catch (Exception e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t}\n\t\n\tpublic Object get(String fieldname) {\n\t\tObject result = null;\n\t\t\n\t\ttry {\n\t\t\t\n\t\t\tif (fieldname == null || fieldname.trim().length() == 0)\n\t\t\t\treturn \"\";\n\t\t\t\n\t\t\tresult = CCTools.getValueOf(this, fieldname.toLowerCase());\t\n\t\t\t\n\t\t\tif (result == null)\n\t\t\t\tresult = \"\";\n\t\t\t\n\t\t\t\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn result;\n\t}\n\t\n\tpublic String getType(String fieldname) {\n\t\tString result = null;\n\t\ttry {\n\t\t\t\n\t\t\tif (fieldname == null || fieldname.trim().length() == 0)\n\t\t\t\treturn \"\";\n\t\t\t\n\t\t\tresult = this.getClass().getField(fieldname.trim().toLowerCase()).getType().getName();\t\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn result;\n\t}" + "\n\n}" + afterEnd; + + fileAsString = fileAsString.replace("public", "public").replaceFirst("private static final long serialVersionUID", "public static final long serialVersionUID"); + + Tools.writeNoPathCreation(file, fileAsString); + + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (final Exception e) { + MessageDialog.openError(shell, "Error", "Error!\n " + e.getMessage()); + } + + } +} \ No newline at end of file diff --git a/GeisPlugin/src/geisplugin/popup/actions/GetMetaData.java b/GeisPlugin/src/geisplugin/popup/actions/GetMetaData.java new file mode 100644 index 0000000..df17b83 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/GetMetaData.java @@ -0,0 +1,236 @@ +package geisplugin.popup.actions; + +import geisplugin.Activator; +import geisplugin.Tools; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileSystemView; + +import jxl.Workbook; +import jxl.write.Label; +import jxl.write.Number; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + */ + +public class GetMetaData extends AbstractHandler { + + public static void main(String[] args) { + try { + new GetMetaData().getMetaData(); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + if (Tools.isNotUpToDate()) { + return null; + } + shell = HandlerUtil.getActiveShell(event); + try { + getMetaData(); + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + return null; + } + + private static Shell shell = null; + + private void getMetaData() { + + String[] dbs = null; + + try { + dbs = Tools.getDBs(); + } catch (Exception e) { + } + + if (dbs == null || dbs.length == 0) { + + if (shell != null) { + MessageDialog.openInformation(shell, "Info", "Couldn't find any databases, go sure your AS400 driver does exist and read the plugin documentation!"); + } else { + JOptionPane.showMessageDialog(Activator.frame, "Couldn't find any databases, go sure your AS400 driver does exist and read the plugin documentation!"); + } + return; + } + + String db = (String) JOptionPane.showInputDialog(Activator.frame, "Which Database?", "Select a Database", JOptionPane.PLAIN_MESSAGE, null, dbs, "GEISDTT"); + + dbs = null; + + if (db == null) { + return; + } + + db = db.substring(0, db.indexOf(" - ")); + System.out.println(db); + + //url = "jdbc:as400://as400;libraries=" + db + ";metadata source=0"; + + getMetaDataWholeDBExcel(db, Tools.getTables(db)); + } + + @SuppressWarnings("null") + private void getMetaDataWholeDBExcel(final String db, final String[] tables) { + + if (tables == null || tables.length == 0) { + if (shell != null) { + MessageDialog.openError(shell, "Info", db + " is empty."); + } else { + JOptionPane.showMessageDialog(Activator.frame, db + " is empty."); + } + return; + } + + Connection jdbc = null; + ResultSet rs = null; + Statement stmt = null; + WritableWorkbook workbook = null; + + int currentSheet = 0; + String outputFilePath = FileSystemView.getFileSystemView().getHomeDirectory() + "\\" + db + "_metadata.xls"; + + //System.out.println(url); + + DatabaseMetaData dbMetaData = null; + try { + workbook = Workbook.createWorkbook(new File(outputFilePath)); + jdbc = Tools.getConnection(); + //System.out.println(url); + stmt = jdbc.createStatement(); + + + for (String currentTabelle : tables) { + currentTabelle = currentTabelle.substring(0, currentTabelle.indexOf(" - ")); + dbMetaData = jdbc.getMetaData(); + rs = dbMetaData.getColumns("GEISDB01", db, currentTabelle, null); + + WritableSheet sheet = workbook.createSheet(currentTabelle, currentSheet); + currentSheet++; + + sheet.setColumnView(0, 13); + sheet.addCell(new Label(0, 0, "Column Name")); + + sheet.setColumnView(1, 18); + sheet.addCell(new Label(1, 0, "Column Type Name")); + + sheet.setColumnView(2, 12); + sheet.addCell(new Label(2, 0, "Column Type")); + + sheet.setColumnView(3, 8); + sheet.addCell(new Label(3, 0, "Precision")); + + sheet.setColumnView(4, 5); + sheet.addCell(new Label(4, 0, "Scale")); + + sheet.setColumnView(5, 50); + sheet.addCell(new Label(5, 0, "Remark")); + + int i = 1; + + while (rs.next()) { + sheet.addCell(new Label(0, i, rs.getString(4)));//"COLUMN_NAME" + sheet.addCell(new Label(1, i, rs.getString(6)));//"TYPE_NAME" + sheet.addCell(new Number(2, i, rs.getInt(5)));//"DATA_TYPE" + sheet.addCell(new Number(3, i, rs.getInt(7)));//"COLUMN_SIZE" + sheet.addCell(new Number(4, i, rs.getInt(9)));//"DECIMAL_DIGITS" + sheet.addCell(new Label(5, i, rs.getString(12)));//"REMARKS" + i++; + } + + if (rs != null) { + rs.close(); + rs = null; + } + } + + if (stmt != null) { + stmt.close(); + stmt = null; + } + } catch (Exception e) { + e.printStackTrace(); + } + + finally { + dbMetaData = null; + } + try { + workbook.write(); + workbook.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + try { + Desktop.getDesktop().open(new File(outputFilePath)); + } catch (IOException e) { + if (shell != null) { + MessageDialog.openInformation(shell, "Info", "Done, exported " + outputFilePath); + } else { + JOptionPane.showMessageDialog(Activator.frame, "Done, exported " + outputFilePath); + } + } + } +} \ No newline at end of file diff --git a/GeisPlugin/src/geisplugin/popup/actions/GetMetaDataTable.java b/GeisPlugin/src/geisplugin/popup/actions/GetMetaDataTable.java new file mode 100644 index 0000000..a1cb6d9 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/GetMetaDataTable.java @@ -0,0 +1,217 @@ +package geisplugin.popup.actions; + +import geisplugin.Activator; +import geisplugin.Tools; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileSystemView; + +import jxl.Workbook; +import jxl.write.Label; +import jxl.write.Number; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + */ + +public class GetMetaDataTable extends AbstractHandler { + + public static void main(final String[] args) { + try { + new GetMetaDataTable().getMetaData(); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + if (Tools.isNotUpToDate()) { + return null; + } + shell = HandlerUtil.getActiveShell(event); + try { + getMetaData(); + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + return null; + } + + private static Shell shell = null; + + private void getMetaData() { + String[] dbs = null; + + try { + dbs = Tools.getDBs(); + } catch (Exception e) { + } + + if (dbs == null || dbs.length == 0) { + + if (shell != null) { + MessageDialog.openInformation(shell, "Info", "Couldn't find any databases, go sure your AS400 driver does exist and read the plugin documentation!"); + } else { + JOptionPane.showMessageDialog(Activator.frame, "Couldn't find any databases, go sure your AS400 driver does exist and read the plugin documentation!"); + } + return; + } + + String db = (String) JOptionPane.showInputDialog(Activator.frame, "Which Database?", "Select a Database", JOptionPane.PLAIN_MESSAGE, null, dbs, "GEISDTT"); + + dbs = null; + + if (db == null) { + return; + } + + db = db.substring(0, db.indexOf(" - ")); + + String[] tables = Tools.getTables(db); + + if (tables == null || tables.length == 0) { + if (shell != null) { + MessageDialog.openError(shell, "Info", "No tables found for " + db + '.'); + } else { + JOptionPane.showMessageDialog(Activator.frame, "No tables found for " + db + '.'); + } + return; + } + + String table = (String) JOptionPane.showInputDialog(Activator.frame, "Which Table?", "Select a Table", JOptionPane.PLAIN_MESSAGE, null, tables, tables[0]); + + tables = null; + + if (table != null && !table.trim().isEmpty()) { + table = table.substring(0, table.indexOf(" - ")); + getMetaDataExcel(table, db); + } + + } + + public void getMetaDataExcel(final String table, final String db) { + Connection jdbc = null; + + String outputFilePath = FileSystemView.getFileSystemView().getHomeDirectory() + "\\" + db + '_' + table + "_metadata.xls"; + + try { + jdbc = Tools.getConnection(); + Statement stmt = jdbc.createStatement(); + ResultSet rs = jdbc.getMetaData().getColumns("GEISDB01", db, table, "%"); + + WritableWorkbook workbook = Workbook.createWorkbook(new File(outputFilePath)); + + WritableSheet sheet = workbook.createSheet(table, 0); + + sheet.setColumnView(0, 13); + sheet.addCell(new Label(0, 0, "Column Name")); + + sheet.setColumnView(1, 18); + sheet.addCell(new Label(1, 0, "Column Type Name")); + + sheet.setColumnView(2, 12); + sheet.addCell(new Label(2, 0, "Column Type")); + + sheet.setColumnView(3, 8); + sheet.addCell(new Label(3, 0, "Precision")); + + sheet.setColumnView(4, 5); + sheet.addCell(new Label(4, 0, "Scale")); + + sheet.setColumnView(5, 50); + sheet.addCell(new Label(5, 0, "Remark")); + + int i = 1; + + while (rs.next()) { + sheet.addCell(new Label(0, i, rs.getString(4)));//"COLUMN_NAME" + sheet.addCell(new Label(1, i, rs.getString(6)));//"TYPE_NAME" + sheet.addCell(new Number(2, i, rs.getInt(5)));//"DATA_TYPE" + sheet.addCell(new Number(3, i, rs.getInt(7)));//"COLUMN_SIZE" + sheet.addCell(new Number(4, i, rs.getInt(9)));//"DECIMAL_DIGITS" + sheet.addCell(new Label(5, i, rs.getString(12)));//"REMARKS" + i++; + } + + workbook.write(); + workbook.close(); + + if (rs != null) { + rs.close(); + rs = null; + } + if (stmt != null) { + stmt.close(); + stmt = null; + } + } catch (Exception e) { + e.printStackTrace(); + } + + try { + Desktop.getDesktop().open(new File(outputFilePath)); + } catch (IOException e) { + if (shell != null) { + MessageDialog.openInformation(shell, "Info", "Done, exported " + outputFilePath); + } else { + JOptionPane.showMessageDialog(Activator.frame, "Done, exported " + outputFilePath); + } + } + } +} \ No newline at end of file diff --git a/GeisPlugin/src/geisplugin/popup/actions/GetTableMetaData.java b/GeisPlugin/src/geisplugin/popup/actions/GetTableMetaData.java new file mode 100644 index 0000000..7d8ca06 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/GetTableMetaData.java @@ -0,0 +1,183 @@ +package geisplugin.popup.actions; + +import geisplugin.Activator; +import geisplugin.Tools; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.swing.JOptionPane; +import javax.swing.filechooser.FileSystemView; + +import jxl.Workbook; +import jxl.write.Label; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + */ + +public class GetTableMetaData extends AbstractHandler { + + public static void main(final String[] args) { + try { + new GetTableMetaData().getTableMetaData(); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + } + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + if (Tools.isNotUpToDate()) { + return null; + } + shell = HandlerUtil.getActiveShell(event); + try { + getTableMetaData(); + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + return null; + } + + private static Shell shell = null; + + private void getTableMetaData() { + String[] dbs = null; + + try { + dbs = Tools.getDBs(); + } catch (Exception e) { + } + + if (dbs == null || dbs.length == 0) { + + if (shell != null) { + MessageDialog.openInformation(shell, "Info", "Couldn't find any databases, go sure your AS400 driver does exist and read the plugin documentation!"); + } else { + JOptionPane.showMessageDialog(Activator.frame, "Couldn't find any databases, go sure your AS400 driver does exist and read the plugin documentation!"); + } + return; + } + + String db = (String) JOptionPane.showInputDialog(Activator.frame, "Which Database?", "Select a Database", JOptionPane.PLAIN_MESSAGE, null, dbs, "GEISDTT"); + + dbs = null; + + if (db == null) { + return; + } + + //url = "jdbc:as400://as400;libraries=" + db + ";metadata source=0"; + + db = db.substring(0, db.indexOf(" - ")); + + getTables(db); + } + + private void getTables(final String db) { + + String outputFilePath = FileSystemView.getFileSystemView().getHomeDirectory() + "\\" + db + "_tables_metadata.xls"; + //System.out.println(outputFilePath); + Connection jdbc = null; + WritableWorkbook workbook = null; + + try { + workbook = Workbook.createWorkbook(new File(outputFilePath)); + jdbc = Tools.getConnection(); + + WritableSheet sheet = workbook.createSheet(db, 0); + + sheet.setColumnView(0, 15); + sheet.addCell(new Label(0, 0, "Table Name")); + sheet.setColumnView(1, 60); + sheet.addCell(new Label(1, 0, "Remarks")); + + ResultSet rs = jdbc.getMetaData().getTables("GEISDB01", db, null, new String[] { "TABLE" }); + int i = 1; + while (rs.next()) { + sheet.addCell(new Label(0, i, rs.getString(3))); + sheet.addCell(new Label(1, i, rs.getString(5))); + i++; + } + + try { + workbook.write(); + workbook.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + rs.close(); + if (rs != null) { + rs.close(); + rs = null; + } + + try { + Desktop.getDesktop().open(new File(outputFilePath)); + } catch (IOException e) { + if (shell != null) { + MessageDialog.openInformation(shell, "Info", "Done, exported " + outputFilePath); + } else { + JOptionPane.showMessageDialog(Activator.frame, "Done, exported " + outputFilePath); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/GeisPlugin/src/geisplugin/popup/actions/LinkClassWithManagedbeans.java b/GeisPlugin/src/geisplugin/popup/actions/LinkClassWithManagedbeans.java new file mode 100644 index 0000000..7acea03 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/LinkClassWithManagedbeans.java @@ -0,0 +1,142 @@ +package geisplugin.popup.actions; + +import java.sql.SQLException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +import geisplugin.Tools; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class LinkClassWithManagedbeans extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + Shell shell = HandlerUtil.getActiveShell(event); + for (final Object firstElement : ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).toList()) { + try { + if (firstElement instanceof ICompilationUnit) { + createOutput(shell, (ICompilationUnit) firstElement); + } else { + MessageDialog.openInformation(shell, "Info", "Please select a Java source file"); + } + } catch (Exception e) { + MessageDialog.openError(shell, "Error", "Error " + e.getMessage()); + } + } + return null; + } + + private void createOutput(final Shell shell, final ICompilationUnit element) { + final String file = element.getResource().getRawLocation().toString(); + + //MessageDialog.openInformation(shell, "file", file); + + int i = 0; + + try { + + String fileAsString = Tools.read(file); + + i = 1; + + if (!fileAsString.contains("@CCGenClass (expressionBase=\"")) { + i = 2; + MessageDialog.openError(shell, "Error", "This is no CCGenClass"); + return; + } + + i = 3; + int index = fileAsString.indexOf("@CCGenClass (expressionBase=\"") + 29; + i = 4; + String expression = fileAsString.substring(index); + i = 5; + index = expression.indexOf('"'); + i = 6; + expression = expression.substring(0, index); + expression = expression.substring(expression.indexOf('.') + 1, expression.length() - 1); + i = 7; + + //Path vom Projekt + // -> nicht direkt möglich, aber im CC eigentlich immer in /src/managedbeans/dispatcherinfo.xml + + String dispatcherInfo = file.substring(0, file.indexOf("/src") + 4) + "/managedbeans/dispatcherinfo.xml"; + + i = 8; + + //verlinkte .xmls finden -> rekursiv + // manuelle Suche vs. XML-DOM API + + //alle .xmls anzeigen und auswählbar machen -> ähnlich der Tabellen-/DB-Auswahl + + String packageStr = fileAsString.substring(fileAsString.indexOf("package") + 8); + packageStr = packageStr.substring(0, packageStr.indexOf(';')); + //MessageDialog.openInformation(shell, "packageStr", packageStr); + + i = 9; + + String classStr = file.substring(file.lastIndexOf("/") + 1); + classStr = classStr.substring(0, classStr.lastIndexOf('.')); + //MessageDialog.openInformation(shell, "classStr", classStr); + + i = 10; + + String content = Tools.read(dispatcherInfo); + + i = 11; + + content = content.substring(0, content.lastIndexOf("")).trim() + "\r\n\t\r\n\r\n"; + + i = 12; + + Tools.writeNoPathCreation(dispatcherInfo, content); + + i = 13; + + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (final Exception e) { + MessageDialog.openError(shell, "Error", "Error Code: " + i + ", Line: " + e.getStackTrace()[0].getLineNumber() + ", Message: " + e.getMessage()); + } + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/NESAS107.java b/GeisPlugin/src/geisplugin/popup/actions/NESAS107.java new file mode 100644 index 0000000..39b3768 --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/NESAS107.java @@ -0,0 +1,71 @@ +package geisplugin.popup.actions; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +public class NESAS107 extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + Shell shell = HandlerUtil.getActiveShell(event); + final String today = new SimpleDateFormat("d/M/yyyy").format(new Date()); + try { +// String log = Files.readAllLines(Paths.get("\\\\nesas008\\C$\\Program Files\\UltraVNC\\mslogon.log"), Charset.forName("UTF-8")).stream() +// .filter(s -> s.startsWith(today) && s.contains("Connection received from ") && s.contains("using")) +// .collect(Collectors.joining("\n")); +// MessageDialog.openInformation(shell, "Log", log); + + StringBuilder log = new StringBuilder(); + Pattern pattern = Pattern.compile("^\\d+\\/\\d+\\/\\d+\\s((?:[0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9])\\s+(?:.*)\\s+((?:25[0-5]\\.|2[0-4][0-9]\\.|[01]?[0-9][0-9]?\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(?:\\s\\w+$|\\s\\w+\\\\n|\\s\\w+\\s(\\w+))"); + + HashMap map = new HashMap(); + for (String string : Files.readAllLines(Paths.get("\\\\nesas107\\C$\\Program Files\\UltraVNC\\mslogon.log"), Charset.forName("UTF-8"))) { + if (string.startsWith(today) && string.contains("Connection received") && string.contains("using") || string.startsWith(today) && string.contains("disconnected") && string.contains("Client ")) { + Matcher matcher = pattern.matcher(string); + while (matcher.find()) { + if ((map.get(matcher.group(2)) == null || map.get(matcher.group(2)).trim().isEmpty()) && matcher.group(3) != null) { + map.put(matcher.group(2), matcher.group(1)+";"+matcher.group(2)+";"+matcher.group(3)); + continue; + } + if (string.startsWith(today) && string.contains("disconnected") && string.contains("Client ") && map.get(matcher.group(2)) != null) { + String[] t1 = map.get(matcher.group(2)).split(";"); + if (t1.length > 2) { + log.append("Connection received from " + t1[0] + " till " + matcher.group(1) + " with user " + t1[2] + " and IP " + t1[1] + "\n"); + map.put(t1[1], ""); + } + } + } + } + } + if (!map.isEmpty()) { + for (Entry entry : map.entrySet()) { + if (entry.getValue().equals("")) { + continue; + } + String[] t1 = entry.getValue().split(";"); + log.append("Currently online is user "+ t1[2] + " since " + t1[0] + " with IP "+ t1[1] + "\n"); + } + } + MessageDialog.openInformation(shell, "Log", log.toString()); + } catch (final IOException e) { + MessageDialog.openError(shell, "Fehler", "Fehler " + e.getMessage()); + } + return null; + } + +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/RemoveGenerateReflectionGetSet.java b/GeisPlugin/src/geisplugin/popup/actions/RemoveGenerateReflectionGetSet.java new file mode 100644 index 0000000..de4cb2a --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/RemoveGenerateReflectionGetSet.java @@ -0,0 +1,93 @@ +package geisplugin.popup.actions; + +import geisplugin.Tools; + +import java.sql.SQLException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class RemoveGenerateReflectionGetSet extends AbstractHandler { + + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + Shell shell = HandlerUtil.getActiveShell(event); + for (Object firstElement : ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).toList()) { + try { + if (firstElement instanceof ICompilationUnit) { + createOutput(shell, firstElement); + } else { + MessageDialog.openInformation(shell, "Info", "Please select Java source file"); + } + } catch (Exception e) { + MessageDialog.openError(shell, "Error", "Error " + e.getMessage()); + } + } + return null; + } + + private void createOutput(final Shell shell, final Object firstElement) { + try { + + String file = ((ICompilationUnit) firstElement).getResource().getRawLocation().toString(); + + String fileAsString = Tools.read(file); + + fileAsString = fileAsString.replace("\n\tpublic void set(String fieldname, Object value) {\t\t\n\t\t\ttry {\n\t\t\t\tif (value != null) {\n\t\t\t\t\t\n\t\t\t\t\tif (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.String\") ) {\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, value);\t\n\t\t\t\t\t\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.Long\") ) {\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (value == null)\n\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, Long.parseLong(value.toString()));\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.Integer\") ) {\n\t\t\t\t\t\tif (value.toString().trim().length() == 0)\n\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, Integer.parseInt(value.toString()));\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.lang.Double\") ) {\n\t\t\t\t\t\tif (value.toString().trim().length() == 0)\n\t\t\t\t\t\t\tvalue = 0.0;\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, Double.parseDouble(value.toString()));\t\n\t\t\t\t\t} else if (this.getClass().getField(fieldname.toLowerCase()).getType().getName().equals(\"java.util.Date\") ) {\n\t\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.getClass().getField(fieldname.toLowerCase()).set(this, value);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t} catch (Exception e) {\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t}\n\t\n\tpublic Object get(String fieldname) {\n\t\tObject result = null;\n\t\t\n\t\ttry {\n\t\t\t\n\t\t\tif (fieldname == null || fieldname.trim().length() == 0)\n\t\t\t\treturn \"\";\n\t\t\t\n\t\t\tresult = CCTools.getValueOf(this, fieldname.toLowerCase());\t\n\t\t\t\n\t\t\tif (result == null)\n\t\t\t\tresult = \"\";\n\t\t\t\n\t\t\t\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn result;\n\t}\n\t\n\tpublic String getType(String fieldname) {\n\t\tString result = null;\n\t\ttry {\n\t\t\t\n\t\t\tif (fieldname == null || fieldname.trim().length() == 0)\n\t\t\t\treturn \"\";\n\t\t\t\n\t\t\tresult = this.getClass().getField(fieldname.trim().toLowerCase()).getType().getName();\t\n\t\t} catch (Exception e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn result;\n\t}", ""); + + //TODO + //RegEx welches auch gemoddete Versionenen erkennt, z.B.; + //von + //public void set(String fieldname, Object value)[...] + //bis + //return result;[...]} + + Tools.writeNoPathCreation(file, fileAsString); + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (Exception e) { + MessageDialog.openError(shell, "Error", "Error!\n " + e.getMessage()); + } + } +} diff --git a/GeisPlugin/src/geisplugin/popup/actions/WhiteSpaceAction.java b/GeisPlugin/src/geisplugin/popup/actions/WhiteSpaceAction.java new file mode 100644 index 0000000..0de3f9b --- /dev/null +++ b/GeisPlugin/src/geisplugin/popup/actions/WhiteSpaceAction.java @@ -0,0 +1,97 @@ +package geisplugin.popup.actions; + +import geisplugin.Tools; + +import java.sql.SQLException; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IResource; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * DE: + * + * EN: + * + * + * Program changes + * ************************************************************************************** + * Date * Ticket * KonzFirm * Responsible * programmer * + * Change * + * ************************************************************************************** + * + * @author huellmante + * @version 1.0 + * + */ + +public class WhiteSpaceAction extends AbstractHandler { + + @SuppressWarnings("restriction") + @Override + public Object execute(final ExecutionEvent event) throws ExecutionException { + try { + if (Tools.isNotUpToDate()) { + return null; + } + } finally { + try { + if (Tools.con != null && !Tools.con.isClosed()) { + try { + Tools.con.rollback(); + Tools.con.close(); + } catch (final SQLException e) { + } + Tools.con = null; + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + Shell shell = HandlerUtil.getActiveShell(event); + boolean ok = false; + + for (final Object selection : ((IStructuredSelection) HandlerUtil.getActiveMenuSelection(event)).toList()) { + + String path; + + if (selection instanceof ICompilationUnit) { + path = ((ICompilationUnit) selection).getResource().getRawLocation().toString().trim(); + } else + if (selection instanceof org.eclipse.core.internal.resources.File) { + path = ((org.eclipse.core.internal.resources.File) selection).getRawLocation().toString().trim(); + } else { + return null; + } + + try { + + final String input = Tools.read(path); + final StringBuilder fileAsString = new StringBuilder(input.length()); + + for (final String myString : input.split("\n", 0)) { + fileAsString.append(Tools.trimEnd(myString)); + fileAsString.append('\n'); + } + fileAsString.setLength(fileAsString.length() - 1); + Tools.writeNoPathCreation(path, fileAsString.toString()); + Tools.getCurrentSelectedProject().refreshLocal(IResource.DEPTH_INFINITE, null); + ok = true; + } catch (final Exception e) { + MessageDialog.openError(shell, "Exception", "Exception!\n " + e.getMessage()); + } + } + if (ok) { + MessageDialog.openInformation(shell, "Success", "Done!"); + } else { + MessageDialog.openWarning(shell, "Error", "Couldn't trim selected files"); + } + return null; + } +} \ No newline at end of file diff --git a/GeisPlugin/src/icons/db.gif b/GeisPlugin/src/icons/db.gif new file mode 100644 index 0000000..caa5aa3 Binary files /dev/null and b/GeisPlugin/src/icons/db.gif differ diff --git a/GeisPlugin/src/icons/geis.gif b/GeisPlugin/src/icons/geis.gif new file mode 100644 index 0000000..f6f63bf Binary files /dev/null and b/GeisPlugin/src/icons/geis.gif differ diff --git a/GeisPlugin/src/icons/java.gif b/GeisPlugin/src/icons/java.gif new file mode 100644 index 0000000..1461357 Binary files /dev/null and b/GeisPlugin/src/icons/java.gif differ