diff --git a/.gitignore b/.gitignore index b1a83d9..6f85526 100644 --- a/.gitignore +++ b/.gitignore @@ -1,41 +1,7 @@ -# maven tycho build output -target - -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# Runtime Eclipse -runtime-EclipseApplication/ - -# Temp filesystem -RemoteSystemsTempFiles/ - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse - -internalChangelog.txt \ No newline at end of file +.classpath +.project +.polyglot.META-INF +.polyglot.feature.xml +.settings/ +bin/ +target/ diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml deleted file mode 100644 index 12e63a2..0000000 --- a/.mvn/extensions.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - org.eclipse.tycho.extras - tycho-pomless - 1.0.0 - - diff --git a/README.md b/README.md index 74edf09..e1617d5 100644 --- a/README.md +++ b/README.md @@ -11,30 +11,12 @@ or ask for push access here. Tell about new fork by adding new issue. I will hap ## What is this ? -This repository is a fork of [https://code.google.com/p/csvedit/](https://code.google.com/p/csvedit/) created by Mathieu Savy in 2104. It contains the latest functionalities available for CSVEdit but most of the new features are still being tested. If you look for a more reliable version of the plugin you should probably visit the original repository. - -- The previous stable release 1.1.3 was available [on Eclipse Marketplace](https://marketplace.eclipse.org/content/csv-edit). -- The version available in this repository is 1.2.x - -The intention was to contribute features from here to the original repository once they are mature. +This repository is a fork of [https://github.com/Mathieuu/CsvEdit](https://github.com/Mathieuu/CsvEdit) created by Mathieu Savy in 2013 +which in itself is a fork of [https://code.google.com/p/csvedit/](https://code.google.com/p/csvedit/) created by Frederic Henri in 2010. ### How to get the latest version -HELP WANTED WITH PUBLISHING 1.2+ build - -0. NOT AVAILABLE Via Eclipse marketplace at -or drag-n-drop the image on the Eclipse toolbar -[![Drag onto your running Eclipse toolbar. *Requires Eclipse Marketplace Client](images/resurrector-CSV-logo.png)](http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=3739198) - -1. NOT AVAILABLE The latest version (1.2) 2017-10-31 built is NO LONGER available with update-site `http://www.nodeclipse.org/updates/csvedit/`. -In Eclipse Help -> Install new software, add the URL and follow the instructions. - -2. Or from this repository: -[https://raw.githubusercontent.com/SegFaultError/CsvEdit/master/csvedit.update/site.xml](https://raw.githubusercontent.com/SegFaultError/CsvEdit/master/csvedit.update/site.xml) - -- [] TODO 3. Offline site archive from GitHub releases. - -4. Other option is to build from sources with maven `mvn package` and install from local repository archive, that will be in `csvedit.site/target/repository`. +[https://gnl42.github.io/CsvEdit2-update/](https://gnl42.github.io/CsvEdit2-update/) ### CSVEdit @@ -42,27 +24,34 @@ CSVEdit make CSVFile edition easier. + Edit from the source editor - The source editor has been enhanced to help you differentiate your data from the different column using a color mechanism + The source editor has been enhanced to help you differentiate your data from the different column using a color mechanism + Edit from a table view representing the csv data - The table editing is definitely the added value of the plugin and allows a bunch of operation on your csv file among the following features - - - Easy editing of data - - Insertion and deletion of table rows - - Insertion and deletion of table column - - Filtering of data - - Customize view with hidding/display of column to simplify the view - - Manage your column with moving/resizing columns - - Sorting data in column - - Manage your own CSV settings - + The table editing is definitely the added value of the plugin and allows a bunch of operation on your csv file among the following features + + - Easy editing of data + - Insertion and deletion of table rows + - Insertion and deletion of table column + - Filtering of data + - Customize view with hidding/display of column to simplify the view + - Manage your column with moving/resizing columns + - Sorting data in column + - Manage your own CSV settings + ![](images/Editor_Table_Tab.png) ![](images/Editor_Source_Tab.png) -![](images/Preferences.png) +![](images/Preferences.png) ## History +### Version 2.0.0 2024 + +Update for Eclipse 2023-12 +Various bug fixes + +### + Optional maven/tycho build was added in 2017 by Paul Verest. ### New features of 1.2.x diff --git a/csvedit.feature/.gitignore b/csvedit.feature/.gitignore deleted file mode 100644 index b71f363..0000000 --- a/csvedit.feature/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse \ No newline at end of file diff --git a/csvedit.feature/.project b/csvedit.feature/.project deleted file mode 100644 index e05670e..0000000 --- a/csvedit.feature/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - csvedit.feature - - - - - - org.eclipse.pde.FeatureBuilder - - - - - - org.eclipse.pde.FeatureNature - - diff --git a/csvedit.feature/feature.xml b/csvedit.feature/feature.xml index 24e93c0..29f7cd0 100644 --- a/csvedit.feature/feature.xml +++ b/csvedit.feature/feature.xml @@ -1,12 +1,12 @@ + version="2.1.0.qualifier" + provider-name="George Lindholm" + plugin="me.glindholm.plugin.csvedit2"> - + This aims to create a CSV file editor in Eclipse with features such as : - view csv file in source editor or table editor @@ -46,23 +46,19 @@ permissions and limitations under the License. - - + + id="wrapped.org.jumpmind.symmetric.symmetric-csv" + version="0.0.0"/> + id="me.glindholm.plugin.csvedit2" + version="0.0.0"/> + + diff --git a/csvedit.feature/pom.xml b/csvedit.feature/pom.xml new file mode 100644 index 0000000..e9d05a5 --- /dev/null +++ b/csvedit.feature/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + me.glindholm.plugin + csvedit2 + 2.1.0-SNAPSHOT + + me.glindholm.plugin.csvedit2.feature + eclipse-feature + [feature] CSV Edit + diff --git a/csvedit.plugin.ui/.classpath b/csvedit.plugin.ui/.classpath deleted file mode 100644 index 2295842..0000000 --- a/csvedit.plugin.ui/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/csvedit.plugin.ui/.gitignore b/csvedit.plugin.ui/.gitignore deleted file mode 100644 index b71f363..0000000 --- a/csvedit.plugin.ui/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse \ No newline at end of file diff --git a/csvedit.plugin.ui/.project b/csvedit.plugin.ui/.project deleted file mode 100644 index 8871fdd..0000000 --- a/csvedit.plugin.ui/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - csvedit.plugin.ui - - - - - - 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/csvedit.plugin.ui/META-INF/MANIFEST.MF b/csvedit.plugin.ui/META-INF/MANIFEST.MF index 2097de5..6070ccb 100644 --- a/csvedit.plugin.ui/META-INF/MANIFEST.MF +++ b/csvedit.plugin.ui/META-INF/MANIFEST.MF @@ -1,10 +1,10 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Eclipse CSV Editor UI contributions -Bundle-SymbolicName: org.fhsolution.eclipse.plugins.csvedit.ui;singleton:=true -Bundle-Version: 1.2.0 -Bundle-Vendor: www.fhsolution.com -Fragment-Host: org.fhsolution.eclipse.plugins.csvedit;bundle-version="1.2.0" -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-SymbolicName: me.glindholm.plugin.csvedit2.ui;singleton:=true +Bundle-Version: 2.1.0.qualifier +Bundle-Vendor: George Lindholm +Fragment-Host: me.glindholm.plugin.csvedit2 +Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: org.eclipse.ui.ide, org.eclipse.core.resources diff --git a/csvedit.plugin.ui/build.properties b/csvedit.plugin.ui/build.properties index 1cbc97d..96a5ce9 100644 --- a/csvedit.plugin.ui/build.properties +++ b/csvedit.plugin.ui/build.properties @@ -1,6 +1,7 @@ source.. = src/ -output.. = bin/ +output.. = target/classes/ + bin.includes = META-INF/,\ .,\ fragment.xml,\ - lib/ + icons/ diff --git a/csvedit.plugin.ui/fragment.xml b/csvedit.plugin.ui/fragment.xml index 723d89a..9e429fa 100644 --- a/csvedit.plugin.ui/fragment.xml +++ b/csvedit.plugin.ui/fragment.xml @@ -4,27 +4,27 @@ + class="me.glindholm.plugin.csvedit2.customeditor.preferences.PreferenceInitializer"> + id="me.glindholm.plugin.csvedit2.views.CSVEditView"> diff --git a/csvedit.plugin/icons/csv.gif b/csvedit.plugin.ui/icons/csv.gif similarity index 100% rename from csvedit.plugin/icons/csv.gif rename to csvedit.plugin.ui/icons/csv.gif diff --git a/csvedit.plugin.ui/lib/javacsv.jar b/csvedit.plugin.ui/lib/javacsv.jar deleted file mode 100644 index 75f404d..0000000 Binary files a/csvedit.plugin.ui/lib/javacsv.jar and /dev/null differ diff --git a/csvedit.plugin.ui/pom.xml b/csvedit.plugin.ui/pom.xml new file mode 100644 index 0000000..32e8aae --- /dev/null +++ b/csvedit.plugin.ui/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + me.glindholm.plugin + csvedit2 + 2.1.0-SNAPSHOT + + me.glindholm.plugin.csvedit2.ui + eclipse-plugin + [bundle] Eclipse CSV Editor UI contributions + diff --git a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/DefaultCSVMultipageEditor.java b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/DefaultCSVMultipageEditor.java similarity index 62% rename from csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/DefaultCSVMultipageEditor.java rename to csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/DefaultCSVMultipageEditor.java index 7639ed5..76bf513 100644 --- a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/DefaultCSVMultipageEditor.java +++ b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/DefaultCSVMultipageEditor.java @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.customeditor; +package me.glindholm.plugin.csvedit2.customeditor; -import org.fhsolution.eclipse.plugins.csvedit.customeditor.model.DefaultCSVFile; -import org.fhsolution.eclipse.plugins.csvedit.customeditor.model.PreferencesCSVOptionsProvider; -import org.fhsolution.eclipse.plugins.csvedit.editors.MultiPageCSVEditor; -import org.fhsolution.eclipse.plugins.csvedit.model.AbstractCSVFile; +import me.glindholm.plugin.csvedit2.customeditor.model.DefaultCSVFile; +import me.glindholm.plugin.csvedit2.customeditor.model.PreferencesCSVOptionsProvider; +import me.glindholm.plugin.csvedit2.editors.MultiPageCSVEditor; +import me.glindholm.plugin.csvedit2.model.AbstractCSVFile; public class DefaultCSVMultipageEditor extends MultiPageCSVEditor { @@ -26,19 +26,20 @@ public class DefaultCSVMultipageEditor extends MultiPageCSVEditor { /** * Create the CSV file */ - protected AbstractCSVFile createCSVFile() - { + @Override + protected AbstractCSVFile createCSVFile() { preferences = new PreferencesCSVOptionsProvider(); return new DefaultCSVFile(preferences); } /** - * Create the different tab for the multi editor and set the focus to the - * page according to user preferences. + * Create the different tab for the multi editor and set the focus to the page according to user + * preferences. * - * @see org.fhsolution.eclipse.plugins.csvedit.editors.MultiPageCSVEditor#createPages() + * @see me.glindholm.plugin.csvedit2.editors.MultiPageCSVEditor#createPages() */ - protected void createPages () { + @Override + protected void createPages() { super.createPages(); setActivePage(preferences.getDefaultPage()); } diff --git a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/model/DefaultCSVFile.java b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/model/DefaultCSVFile.java similarity index 73% rename from csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/model/DefaultCSVFile.java rename to csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/model/DefaultCSVFile.java index 303dff0..50faa4b 100644 --- a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/model/DefaultCSVFile.java +++ b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/model/DefaultCSVFile.java @@ -12,18 +12,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.customeditor.model; +package me.glindholm.plugin.csvedit2.customeditor.model; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import org.fhsolution.eclipse.plugins.csvedit.model.AbstractCSVFile; -import org.fhsolution.eclipse.plugins.csvedit.model.ICsvOptionsProvider; +import me.glindholm.plugin.csvedit2.model.AbstractCSVFile; +import me.glindholm.plugin.csvedit2.model.ICsvOptionsProvider; /** * - * {@link DefaultCSVFile} implements the {@link AbstractCSVFile} abstract - * methods based on the values stored in the preferences system + * {@link DefaultCSVFile} implements the {@link AbstractCSVFile} abstract methods based on the + * values stored in the preferences system + * * @author jpizar * @author msavy * @@ -35,11 +36,11 @@ public class DefaultCSVFile extends AbstractCSVFile { /** * Constructor + * * @param provider the {@link PreferencesCSVOptionsProvider} */ - public DefaultCSVFile(ICsvOptionsProvider provider) { - super(); - this.optionsProvider = provider; + public DefaultCSVFile(final ICsvOptionsProvider provider) { + optionsProvider = provider; } @Override @@ -52,6 +53,11 @@ public boolean getSensitiveSearch() { return optionsProvider.getSensitiveSearch(); } + @Override + public char getCustomHeaderDelimiter() { + return optionsProvider.getCustomHeaderDelimiter().charAt(0); + } + @Override public char getCustomDelimiter() { return optionsProvider.getCustomDelimiter().charAt(0); @@ -59,20 +65,20 @@ public char getCustomDelimiter() { @Override public char getCommentChar() { - String commentChar = optionsProvider.getCommentChar(); + final String commentChar = optionsProvider.getCommentChar(); char result = Character.UNASSIGNED; if (commentChar != null && commentChar != "") { - result = commentChar.charAt(0); + result = commentChar.charAt(0); } return result; } @Override public char getTextQualifier() { - String qualifierChar = optionsProvider.getTextQualifier(); + final String qualifierChar = optionsProvider.getTextQualifier(); char result = Character.UNASSIGNED; if (qualifierChar != null && qualifierChar != "" && qualifierChar.length() > 0) { - result = qualifierChar.charAt(0); + result = qualifierChar.charAt(0); } return result; } @@ -81,7 +87,7 @@ public char getTextQualifier() { public boolean useQualifier() { return optionsProvider.useTextQualifier(); } - + @Override public String getInCellDelimiter() { return optionsProvider.getInCellDelimiter(); @@ -89,16 +95,16 @@ public String getInCellDelimiter() { @Override public String getRegexTableMarker() { - - String result = ""; - + + String result = ""; + try { Pattern.compile(optionsProvider.getRegexTableMarker()); result = optionsProvider.getRegexTableMarker(); - } catch (PatternSyntaxException exception) { - + } catch (final PatternSyntaxException exception) { + } - + return result; } } \ No newline at end of file diff --git a/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/model/PreferencesCSVOptionsProvider.java b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/model/PreferencesCSVOptionsProvider.java new file mode 100644 index 0000000..ef8fdc0 --- /dev/null +++ b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/model/PreferencesCSVOptionsProvider.java @@ -0,0 +1,99 @@ +/* Copyright 2011 csvedit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.glindholm.plugin.csvedit2.customeditor.model; + +import me.glindholm.plugin.csvedit2.Activator; +import me.glindholm.plugin.csvedit2.customeditor.preferences.PreferenceConstants; +import me.glindholm.plugin.csvedit2.model.ICsvOptionsProvider; + +/** + * + * @author fhenri, msavy + * + */ +public class PreferencesCSVOptionsProvider implements ICsvOptionsProvider { + + private final boolean useFirstLineAsHeader; + private final boolean sensitiveSearch; + private final boolean useQualifier; + private final String customDelimiter; + private final String customHeaderDelimiter; + private final String commentChar; + private final String defaultPage; + private final String textQualifier; + private final String inCellDelimiter; + private final String regexTableMarker; + + public PreferencesCSVOptionsProvider() { + useFirstLineAsHeader = Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.USE_FIRST_LINE_AS_HEADER); + customDelimiter = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CUSTOM_DELIMITER); + customHeaderDelimiter = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CUSTOM_HEADER_DELIMITER); + sensitiveSearch = Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.CASE_SENSITIVE_SEARCH); + commentChar = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.COMMENT_CHAR); + textQualifier = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.TEXT_QUALIFIER); + useQualifier = Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.USE_QUALIFIER); + defaultPage = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.DEFAULT_VIEW_PAGE); + inCellDelimiter = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.INCELL_DELIMITER); + regexTableMarker = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.REGEX_HEADER_TABLE); + } + + @Override + public String getCustomDelimiter() { + return customDelimiter; + } + + @Override + public boolean getUseFirstLineAsHeader() { + return useFirstLineAsHeader; + } + + @Override + public boolean getSensitiveSearch() { + return sensitiveSearch; + } + + @Override + public String getCustomHeaderDelimiter() { + return customHeaderDelimiter; + } + @Override + public String getCommentChar() { + return commentChar; + } + + public int getDefaultPage() { + return Integer.parseInt(defaultPage); + } + + @Override + public String getTextQualifier() { + return textQualifier; + } + + @Override + public boolean useTextQualifier() { + return useQualifier; + } + + @Override + public String getRegexTableMarker() { + return regexTableMarker; + } + + @Override + public String getInCellDelimiter() { + return inCellDelimiter; + } +} diff --git a/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/CSVPreferencePage.java b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/CSVPreferencePage.java new file mode 100644 index 0000000..2688a44 --- /dev/null +++ b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/CSVPreferencePage.java @@ -0,0 +1,135 @@ +/* Copyright 2011 csvedit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.glindholm.plugin.csvedit2.customeditor.preferences; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.ComboFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.StringFieldEditor; +import org.eclipse.swt.SWT; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +import me.glindholm.plugin.csvedit2.Activator; + +/** + * This class represents a preference page that is contributed to the Preferences dialog. By + * subclassing FieldEditorPreferencePage, we can use the field support built into JFace + * that allows us to create a page that is small and knows how to save, restore and apply itself. + *

+ * This page is used to modify preferences only. They are stored in the preference store that + * belongs to the main plug-in class. That way, preferences can be accessed directly via the + * preference store. + * + * @author fhenri + * + */ +public class CSVPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + + /** + * Public constructor + */ + public CSVPreferencePage() { + super(GRID); + setPreferenceStore(Activator.getDefault().getPreferenceStore()); + setDescription("Some options that will be use for all the csv files"); + } + + /** + * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to + * manipulate various types of preferences. Each field editor knows how to save and restore itself. + * + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() + */ + @Override + public void createFieldEditors() { + + final String[][] pagesLabelsAndValues = new String[2][2]; + pagesLabelsAndValues[0][0] = "Table"; + pagesLabelsAndValues[0][1] = "0"; + pagesLabelsAndValues[1][0] = "Source"; + pagesLabelsAndValues[1][1] = "1"; + addField(new ComboFieldEditor(PreferenceConstants.DEFAULT_VIEW_PAGE, "Select the default tab to view csv file:", pagesLabelsAndValues, + getFieldEditorParent())); + + final BooleanFieldEditor firstLineIsHeader = new BooleanFieldEditor(PreferenceConstants.USE_FIRST_LINE_AS_HEADER, "&Use the first line of the CSV file as the column headers", + getFieldEditorParent()); + addField(firstLineIsHeader); + + final CustomDelimiterFieldEditor headerDelimiter = new CustomDelimiterFieldEditor(PreferenceConstants.CUSTOM_HEADER_DELIMITER, "Choose the delimiter to use for header:", getFieldEditorParent()); + addField(headerDelimiter); + + firstLineIsHeader.getDescriptionControl(getFieldEditorParent()).addListener(SWT.Selection, event -> { + final boolean enabled = firstLineIsHeader.getBooleanValue(); + headerDelimiter.setEnabled(enabled, getFieldEditorParent()); + }); + + addField(new CustomDelimiterFieldEditor(PreferenceConstants.CUSTOM_DELIMITER, "Choose the delimiter to use:", getFieldEditorParent())); + + // final StringFieldEditor customDelimiterField = new StringFieldEditor(PreferenceConstants.CUSTOM_DELIMITER, "Choose the delimiter to use:", 2, + // getFieldEditorParent()); + // customDelimiterField.setTextLimit(1); + // customDelimiterField.setEmptyStringAllowed(false); + // addField(customDelimiterField); + + final StringFieldEditor textQualifierChar = new StringFieldEditor(PreferenceConstants.TEXT_QUALIFIER, + "Define the character used as a text qualifier of the data:", 2, getFieldEditorParent()); + textQualifierChar.setTextLimit(1); + textQualifierChar.setEmptyStringAllowed(false); + addField(textQualifierChar); + + addField(new BooleanFieldEditor(PreferenceConstants.USE_QUALIFIER, "For the text qualifier to be used for all fields", getFieldEditorParent())); + + final StringFieldEditor commentChar = new StringFieldEditor(PreferenceConstants.COMMENT_CHAR, "Choose the character to use as a comment:", 2, + getFieldEditorParent()); + commentChar.setTextLimit(1); + commentChar.setEmptyStringAllowed(true); + addField(commentChar); + + addField(new BooleanFieldEditor(PreferenceConstants.CASE_SENSITIVE_SEARCH, "&Case sensitive filtering", getFieldEditorParent())); + + final StringFieldEditor regexField = new StringFieldEditor(PreferenceConstants.REGEX_HEADER_TABLE, + "Header regex indicating that the column should be displayed as table", StringFieldEditor.UNLIMITED, getFieldEditorParent()); + regexField.setEmptyStringAllowed(true); + addField(regexField); + + final StringFieldEditor incellDelimiterField = new StringFieldEditor(PreferenceConstants.INCELL_DELIMITER, + "Delimiter to use as a value delimiter in a cell", StringFieldEditor.UNLIMITED, getFieldEditorParent()); + // incellDelimiterField.setTextLimit(1); //TODO test: does it really work with more than 1 character + // delimiter + incellDelimiterField.setEmptyStringAllowed(true); + addField(incellDelimiterField); + + } + + /** + * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk() + */ + @Override + public boolean performOk() { + // TODO here we should reload all opened csv file with the new pref. + return super.performOk(); + } + + /** + * + * + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + @Override + public void init(final IWorkbench workbench) { + } + +} \ No newline at end of file diff --git a/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/CustomDelimiterFieldEditor.java b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/CustomDelimiterFieldEditor.java new file mode 100644 index 0000000..de47612 --- /dev/null +++ b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/CustomDelimiterFieldEditor.java @@ -0,0 +1,104 @@ + +package me.glindholm.plugin.csvedit2.customeditor.preferences; + +import org.eclipse.jface.preference.ComboFieldEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; + +public class CustomDelimiterFieldEditor extends ComboFieldEditor { + private Combo combo; + private static final String[] delItems = { ",", ";", "|", "tab" }; + + public CustomDelimiterFieldEditor(final String name, final String labelText, final Composite parent) { + super(name, labelText, new String[][] {}, parent); + createControl(parent); + combo.setTextLimit(3); + } + + @Override + protected void adjustForNumColumns(final int numColumns) { + final GridData gd = (GridData) combo.getLayoutData(); + gd.horizontalSpan = numColumns - 1; + gd.grabExcessHorizontalSpace = gd.horizontalSpan == 1; + } + + @Override + protected void doFillIntoGrid(final Composite parent, final int numColumns) { + getLabelControl(parent); + if (combo == null) { + combo = new Combo(parent, SWT.DROP_DOWN | SWT.BORDER); + combo.setItems(delItems); + combo.addModifyListener(e -> valueChanged()); + combo.addVerifyListener(e -> { + if (e.text.length() == 0 || // + !"tab".equals(e.text) && e.text.length() > 1) { + e.doit = false; + } + }); + } + final GridData gd = new GridData(); + gd.horizontalSpan = numColumns - 1; + gd.horizontalAlignment = GridData.FILL; + combo.setLayoutData(gd); + } + + @Override + protected void doLoad() { + updateComboForValue(getPreferenceStore().getString(getPreferenceName())); + } + + @Override + protected void doLoadDefault() { + updateComboForValue(getPreferenceStore().getDefaultString(getPreferenceName())); + } + + @Override + protected void doStore() { + String value = combo.getText(); + if ("tab".equals(value)) { + value = "\t"; + } + getPreferenceStore().setValue(getPreferenceName(), value); + } + + @Override + public int getNumberOfControls() { + return 2; + } + + @Override + public void setEnabled(final boolean enabled, final Composite parent) { + // super.setEnabled(enabled, parent); + combo.setEnabled(enabled); + super.getLabelControl(parent).setEnabled(enabled); + } + + private void updateComboForValue(final String value) { + if (combo != null) { + if ("\t".equals(value)) { + combo.setText("tab"); + } else { + combo.setText(value); + } + } + } + + private void valueChanged() { + setPresentsDefaultValue(false); + final boolean oldState = isValid(); + refreshValidState(); + final boolean newState = isValid(); + if (newState != oldState) { + fireStateChanged(IS_VALID, oldState, newState); + } + String newValue = combo.getText(); + if ("tab".equals(newValue)) { + newValue = "\t"; + } + if (!newValue.equals(getPreferenceStore().getString(getPreferenceName()))) { + fireValueChanged(VALUE, getPreferenceStore().getString(getPreferenceName()), newValue); + } + } +} diff --git a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/PreferenceConstants.java b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/PreferenceConstants.java similarity index 90% rename from csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/PreferenceConstants.java rename to csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/PreferenceConstants.java index 1e5180c..e3abd58 100644 --- a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/PreferenceConstants.java +++ b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/PreferenceConstants.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.customeditor.preferences; +package me.glindholm.plugin.csvedit2.customeditor.preferences; /** * Constant definitions for plug-in preferences @@ -32,4 +32,5 @@ public class PreferenceConstants { public static final String INCELL_DELIMITER = "inCellDelimiter"; public static final String REGEX_HEADER_TABLE = "regexHeaderTable"; public static final String DEFAULT_VIEW_PAGE = "defaultPagePreference"; + public static final String CUSTOM_HEADER_DELIMITER = "headerDelimiterPreference"; } diff --git a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/PreferenceInitializer.java b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/PreferenceInitializer.java similarity index 84% rename from csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/PreferenceInitializer.java rename to csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/PreferenceInitializer.java index 00d7e7c..a2af586 100644 --- a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/PreferenceInitializer.java +++ b/csvedit.plugin.ui/src/me/glindholm/plugin/csvedit2/customeditor/preferences/PreferenceInitializer.java @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.customeditor.preferences; +package me.glindholm.plugin.csvedit2.customeditor.preferences; import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; import org.eclipse.jface.preference.IPreferenceStore; -import org.fhsolution.eclipse.plugins.csvedit.Activator; + +import me.glindholm.plugin.csvedit2.Activator; /** * Class used to initialize default preference values. @@ -31,10 +32,12 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { * * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() */ + @Override public void initializeDefaultPreferences() { - IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + final IPreferenceStore store = Activator.getDefault().getPreferenceStore(); store.setDefault(PreferenceConstants.USE_FIRST_LINE_AS_HEADER, true); store.setDefault(PreferenceConstants.CASE_SENSITIVE_SEARCH, false); + store.setDefault(PreferenceConstants.CUSTOM_HEADER_DELIMITER, ","); store.setDefault(PreferenceConstants.CUSTOM_DELIMITER, ","); store.setDefault(PreferenceConstants.TEXT_QUALIFIER, "\""); store.setDefault(PreferenceConstants.USE_QUALIFIER, false); diff --git a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/model/PreferencesCSVOptionsProvider.java b/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/model/PreferencesCSVOptionsProvider.java deleted file mode 100644 index 464db3a..0000000 --- a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/model/PreferencesCSVOptionsProvider.java +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright 2011 csvedit - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.fhsolution.eclipse.plugins.csvedit.customeditor.model; - -import org.fhsolution.eclipse.plugins.csvedit.Activator; -import org.fhsolution.eclipse.plugins.csvedit.customeditor.preferences.PreferenceConstants; -import org.fhsolution.eclipse.plugins.csvedit.model.ICsvOptionsProvider; - -/** - * - * @author fhenri, msavy - * - */ -public class PreferencesCSVOptionsProvider implements ICsvOptionsProvider { - - private boolean useFirstLineAsHeader; - private boolean sensitiveSearch; - private boolean useQualifier; - private String customDelimiter; - private String commentChar; - private String defaultPage; - private String textQualifier; - private String inCellDelimiter; - private String regexTableMarker; - - public PreferencesCSVOptionsProvider () - { - useFirstLineAsHeader = - Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.USE_FIRST_LINE_AS_HEADER); - customDelimiter = - Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.CUSTOM_DELIMITER); - sensitiveSearch = - Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.CASE_SENSITIVE_SEARCH); - commentChar = - Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.COMMENT_CHAR); - textQualifier = - Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.TEXT_QUALIFIER); - useQualifier = - Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.USE_QUALIFIER); - defaultPage = - Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.DEFAULT_VIEW_PAGE); - inCellDelimiter = - Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.INCELL_DELIMITER); - regexTableMarker = - Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.REGEX_HEADER_TABLE); - } - - public String getCustomDelimiter () { - return customDelimiter; - } - - public boolean getUseFirstLineAsHeader () { - return useFirstLineAsHeader; - } - - public boolean getSensitiveSearch () { - return sensitiveSearch; - } - - public String getCommentChar () { - return commentChar; - } - - public int getDefaultPage () { - return Integer.parseInt(defaultPage); - } - - public String getTextQualifier() { - return textQualifier; - } - - public boolean useTextQualifier() { - return useQualifier; - } - - public String getRegexTableMarker() { - return regexTableMarker; - } - - public String getInCellDelimiter() { - return inCellDelimiter; - } -} diff --git a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/CSVPreferencePage.java b/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/CSVPreferencePage.java deleted file mode 100644 index c9cd923..0000000 --- a/csvedit.plugin.ui/src/org/fhsolution/eclipse/plugins/csvedit/customeditor/preferences/CSVPreferencePage.java +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright 2011 csvedit - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.fhsolution.eclipse.plugins.csvedit.customeditor.preferences; - -import org.eclipse.jface.preference.BooleanFieldEditor; -import org.eclipse.jface.preference.ComboFieldEditor; -import org.eclipse.jface.preference.FieldEditorPreferencePage; -import org.eclipse.jface.preference.StringFieldEditor; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.fhsolution.eclipse.plugins.csvedit.Activator; - -/** - * This class represents a preference page that is contributed to the - * Preferences dialog. By subclassing FieldEditorPreferencePage, we - * can use the field support built into JFace that allows us to create a page - * that is small and knows how to save, restore and apply itself. - *

- * This page is used to modify preferences only. They are stored in the - * preference store that belongs to the main plug-in class. That way, - * preferences can be accessed directly via the preference store. - * - * @author fhenri - * - */ -public class CSVPreferencePage extends FieldEditorPreferencePage -implements IWorkbenchPreferencePage { - - /** - * Public constructor - */ - public CSVPreferencePage() { - super(GRID); - setPreferenceStore(Activator.getDefault().getPreferenceStore()); - setDescription("Some options that will be use for all the csv files"); - } - - /** - * Creates the field editors. Field editors are abstractions of the common - * GUI blocks needed to manipulate various types of preferences. Each field - * editor knows how to save and restore itself. - * - * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors() - */ - public void createFieldEditors() { - - String[][] pagesLabelsAndValues = new String[2][2]; - pagesLabelsAndValues[0][0] = "Table"; - pagesLabelsAndValues[0][1] = "0"; - pagesLabelsAndValues[1][0] = "Source"; - pagesLabelsAndValues[1][1] = "1"; - addField(new ComboFieldEditor( - PreferenceConstants.DEFAULT_VIEW_PAGE, - "Select the default tab to view csv file:", - pagesLabelsAndValues, - getFieldEditorParent())); - - addField(new BooleanFieldEditor( - PreferenceConstants.USE_FIRST_LINE_AS_HEADER, - "&Use the first line of the CSV file as the column headers", - getFieldEditorParent())); - - StringFieldEditor customDelimiterField = new StringFieldEditor( - PreferenceConstants.CUSTOM_DELIMITER, - "Choose the delimiter to use:", 2, getFieldEditorParent()); - customDelimiterField.setTextLimit(1); - customDelimiterField.setEmptyStringAllowed(false); - addField(customDelimiterField); - - StringFieldEditor textQualifierChar = new StringFieldEditor( - PreferenceConstants.TEXT_QUALIFIER, - "Define the character used as a text qualifier of the data:", 2, getFieldEditorParent()); - customDelimiterField.setTextLimit(1); - customDelimiterField.setEmptyStringAllowed(false); - addField(textQualifierChar); - addField(new BooleanFieldEditor( - PreferenceConstants.USE_QUALIFIER, - "For the text qualifier to be used for all fields", - getFieldEditorParent())); - - StringFieldEditor commentChar = new StringFieldEditor( - PreferenceConstants.COMMENT_CHAR, - "Choose the character to use as a comment:", 2, getFieldEditorParent()); - customDelimiterField.setTextLimit(1); - customDelimiterField.setEmptyStringAllowed(true); - addField(commentChar); - - addField(new BooleanFieldEditor( - PreferenceConstants.CASE_SENSITIVE_SEARCH, - "&Case sensitive filtering", - getFieldEditorParent())); - - - StringFieldEditor regexField = new StringFieldEditor( - PreferenceConstants.REGEX_HEADER_TABLE, - "Header regex indicating that the column should be displayed as table", StringFieldEditor.UNLIMITED, getFieldEditorParent()); - regexField.setEmptyStringAllowed(true); - addField(regexField); - - - StringFieldEditor incellDelimiterField = new StringFieldEditor( - PreferenceConstants.INCELL_DELIMITER, - "Delimiter to use as a value delimiter in a cell", StringFieldEditor.UNLIMITED, getFieldEditorParent()); - //incellDelimiterField.setTextLimit(1); //TODO test: does it really work with more than 1 character delimiter - incellDelimiterField.setEmptyStringAllowed(true); - addField(incellDelimiterField); - - } - - /** - * @see org.eclipse.jface.preference.FieldEditorPreferencePage#performOk() - */ - public boolean performOk () { - // TODO here we should reload all opened csv file with the new pref. - return super.performOk(); - } - - /** - * - * - * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) - */ - public void init(IWorkbench workbench) { - } - -} \ No newline at end of file diff --git a/csvedit.plugin/.classpath b/csvedit.plugin/.classpath deleted file mode 100644 index d115351..0000000 --- a/csvedit.plugin/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/csvedit.plugin/.gitignore b/csvedit.plugin/.gitignore deleted file mode 100644 index b71f363..0000000 --- a/csvedit.plugin/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse \ No newline at end of file diff --git a/csvedit.plugin/.project b/csvedit.plugin/.project deleted file mode 100644 index d498890..0000000 --- a/csvedit.plugin/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - csvedit.plugin - - - - - - 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/csvedit.plugin/META-INF/MANIFEST.MF b/csvedit.plugin/META-INF/MANIFEST.MF index 6853fa5..b44b10c 100644 --- a/csvedit.plugin/META-INF/MANIFEST.MF +++ b/csvedit.plugin/META-INF/MANIFEST.MF @@ -1,10 +1,10 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Eclipse CSV Editor -Bundle-SymbolicName: org.fhsolution.eclipse.plugins.csvedit;singleton:=true -Bundle-Version: 1.2.0 -Bundle-Activator: org.fhsolution.eclipse.plugins.csvedit.Activator -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-SymbolicName: me.glindholm.plugin.csvedit2;singleton:=true +Bundle-Version: 2.1.0.qualifier +Bundle-Activator: me.glindholm.plugin.csvedit2.Activator +Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.jface.text, @@ -12,16 +12,16 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.editors, org.eclipse.ui.ide Bundle-ActivationPolicy: lazy -Bundle-ClassPath: ., - lib/javacsv.jar -Export-Package: org.fhsolution.eclipse.plugins.csvedit.editors; +Bundle-ClassPath: . +Export-Package: me.glindholm.plugin.csvedit2.editors; uses:="org.eclipse.jface.action, org.eclipse.ui.texteditor, org.eclipse.core.runtime, org.eclipse.ui, org.eclipse.core.resources, org.eclipse.jface.viewers, - org.fhsolution.eclipse.plugins.csvedit.model, + me.glindholm.plugin.csvedit2.plugins.csvedit.model, org.eclipse.ui.part", - org.fhsolution.eclipse.plugins.csvedit.model;uses:="com.csvreader" -Bundle-Vendor: www.fhsolution.com + me.glindholm.plugin.csvedit2.model;uses:="com.csvreader" +Import-Package: org.jumpmind.symmetric.csv +Bundle-Vendor: George Lindholm diff --git a/csvedit.plugin/build.properties b/csvedit.plugin/build.properties index 8f36d7c..bda1ecd 100644 --- a/csvedit.plugin/build.properties +++ b/csvedit.plugin/build.properties @@ -1,9 +1,7 @@ source.. = src/ + +output.. = target/classes/ bin.includes = plugin.xml,\ META-INF/,\ - .,\ - icons/,\ - lib/javacsv.jar -jre.compilation.profile=J2SE-1.5 -jars.compile.order = . -src.includes = lib/ + . +jre.compilation.profile=JavaSE-17 diff --git a/csvedit.plugin/lib/javacsv.jar b/csvedit.plugin/lib/javacsv.jar deleted file mode 100644 index 75f404d..0000000 Binary files a/csvedit.plugin/lib/javacsv.jar and /dev/null differ diff --git a/csvedit.plugin/pom.xml b/csvedit.plugin/pom.xml new file mode 100644 index 0000000..00aa968 --- /dev/null +++ b/csvedit.plugin/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + me.glindholm.plugin + csvedit2 + 2.1.0-SNAPSHOT + + me.glindholm.plugin.csvedit2 + eclipse-plugin + [bundle] Eclipse CSV Editor + diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/Activator.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/Activator.java similarity index 78% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/Activator.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/Activator.java index 1b6110e..d4358cf 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/Activator.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/Activator.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit; +package me.glindholm.plugin.csvedit2; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -27,7 +27,7 @@ public class Activator extends AbstractUIPlugin { // The plug-in ID - public static final String PLUGIN_ID = "org.fhsolution.eclipse.csvedit"; + public static final String PLUGIN_ID = "me.glindholm.plugin.csvedit2.csvedit"; // The shared instance private static Activator plugin; @@ -35,14 +35,15 @@ public class Activator extends AbstractUIPlugin { /** * The constructor */ - public Activator () { + public Activator() { } /** * * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) */ - public void start (BundleContext context) throws Exception { + @Override + public void start(final BundleContext context) throws Exception { super.start(context); plugin = this; } @@ -51,7 +52,8 @@ public void start (BundleContext context) throws Exception { * * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ - public void stop (BundleContext context) throws Exception { + @Override + public void stop(final BundleContext context) throws Exception { plugin = null; super.stop(context); } @@ -61,18 +63,17 @@ public void stop (BundleContext context) throws Exception { * * @return the shared instance */ - public static Activator getDefault () { + public static Activator getDefault() { return plugin; } /** - * Returns an image descriptor for the image file at the given - * plug-in relative path + * Returns an image descriptor for the image file at the given plug-in relative path * * @param path the path * @return the image descriptor */ - public static ImageDescriptor getImageDescriptor (String path) { + public static ImageDescriptor getImageDescriptor(final String path) { return imageDescriptorFromPlugin(PLUGIN_ID, path); } } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/AttributeEditorCellModifier.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/AttributeEditorCellModifier.java similarity index 60% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/AttributeEditorCellModifier.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/AttributeEditorCellModifier.java index 58eec3f..d45bc16 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/AttributeEditorCellModifier.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/AttributeEditorCellModifier.java @@ -13,19 +13,17 @@ * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.detailededitor; +package me.glindholm.plugin.csvedit2.detailededitor; import org.eclipse.jface.viewers.ICellModifier; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.TableItem; /** -* -* @author fhenri -* @author msavy -* -*/ + * + * @author fhenri + * @author msavy + * + */ public class AttributeEditorCellModifier implements ICellModifier { /** @@ -34,46 +32,47 @@ public class AttributeEditorCellModifier implements ICellModifier { * @return true if the property can be modified, and false if it is not modifiable * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String) */ - public boolean canModify (Object element, String property) { + @Override + public boolean canModify(final Object element, final String property) { return true; } /** - * Returns the value for the given property of the given element. - * Returns "" if the element does not have the given property. + * Returns the value for the given property of the given element. Returns "" if the element does not + * have the given property. * * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String) */ - public Object getValue (Object element, String property) { - int elementIndex = Integer.parseInt(property); - AttributeRow row = (AttributeRow) element; + @Override + public Object getValue(final Object element, final String property) { + final int elementIndex = Integer.parseInt(property); + final AttributeRow row = (AttributeRow) element; - if(elementIndex < row.getNumberOfElements()) { + if (elementIndex < row.getNumberOfElements()) { return row.getElementAt(elementIndex); - } - else { + } else { return ""; } } /** - * Modifies the value for the given property of the given element. - * Has no effect if the element does not have the given property, - * or if the property cannot be modified. + * Modifies the value for the given property of the given element. Has no effect if the element does + * not have the given property, or if the property cannot be modified. * - * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object) + * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, + * java.lang.Object) */ - public void modify (Object element, String property, Object value) { - int elementIndex = Integer.parseInt(property); + @Override + public void modify(final Object element, final String property, final Object value) { + final int elementIndex = Integer.parseInt(property); if (element instanceof TableItem) { - AttributeRow row = (AttributeRow) ((TableItem) element).getData(); + final AttributeRow row = (AttributeRow) ((TableItem) element).getData(); - if(elementIndex < row.getNumberOfElements()) { + if (elementIndex < row.getNumberOfElements()) { row.setRowEntry(elementIndex, value.toString()); - } - else { - for (int i=row.getNumberOfElements();i entries; + + /** Row changes listener */ + private final IAttributeChangesListener listener; + + /** + * Constructor + * + * @param line + * @param listener + */ + public AttributeRow(final List line, final IAttributeChangesListener listener) { + entries = new ArrayList<>(line); + this.listener = listener; + } + + /** + * Constructor + * + * @param lineElements + * @param listener + */ + public AttributeRow(final String[] lineElements, final IAttributeChangesListener listener) { + this(Arrays.asList(lineElements), listener); + } + + /** + * Create an empty row + * + * @param nbOfColumns + * @param delimiter + * @param listener + * @return + */ + public static AttributeRow createEmptyLine(final int nbOfColumns, final IAttributeChangesListener listener) { + final List line = new LinkedList<>(); + for (int i = 0; i < nbOfColumns; i++) { + line.add(""); + } + return new AttributeRow(line, listener); + } + + /** + * @return + */ + public ArrayList getEntries() { + return entries; + } + + /** + * @return + */ + public String[] getEntriesAsArray() { + return entries.toArray(new String[entries.size()]); + } + + /** + * @param elementIndex + * @param elementString + */ + public void setRowEntry(final int elementIndex, final String elementString) { + if (entries.get(elementIndex).compareTo(elementString) != 0) { + entries.set(elementIndex, elementString); + listener.rowChanged(this, elementIndex); + } + } + + /** + * return the element at a given index. This method makes sure that if the current line does not + * have as many elements as the header, it will not break and return an empty string + * + * @param index + * @return the element at a given index + */ + public String getElementAt(final int index) { + if (index >= entries.size()) { + return ""; + } + return entries.get(index); + } + + /** + * Return the number of elements in this row + * + * @return number of elements in this row + */ + public int getNumberOfElements() { + return entries.size(); + } + + /** + * @param element + */ + public void addElement(final String element) { + entries.add(element); + } + + /** + * Remove an element of the row represented by its index + * + * @param index + */ + public void removeElementAt(final int index) { + entries.remove(index); + } + + /** + * Give the String representation of a CSVRow object. + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + String result = ""; + for (final String s : entries) { + // FIXME get preferences here + result = result.concat(s).concat(","); + } + return result; + } + + /** + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return Objects.hash(entries); + } + + @Override + public boolean equals(final Object anObject) { + // The commented lines implies that if two rows have the same content, + // the cell editor will modify + // the first one found instead of the focused one + // each row is unique + + /* + * //System.out.println("compare:\n[" + this + "] and\n[" + anObject + "]"); if (!(anObject + * instanceof AttributeRow)) { return false; } + * + * AttributeRow thisRow = (AttributeRow) anObject; for (int i=0; i model = new ArrayList<>(); + + IAttributeChangesListener listener = (row, index) -> tableViewer.refresh(); + + /** + * Default constructor Add an empty TableViewer to a Composite view + */ + public DetailedAttributeTableViewer(final Composite composite) { + + tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); + final Table table = tableViewer.getTable(); + table.setLinesVisible(true); + table.setHeaderVisible(true); + final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + gd.minimumHeight = 100; + table.setLayoutData(gd); + } + + /** + * Fill the table + * + * @param headers + * @param content a List where each String[] is a column of the table + */ + public void fillTable(final List headers, final List content) { + + for (int i = 0; i < headers.size(); i++) { + final TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.LEFT); + + column.getColumn().setText(headers.get(i)); + column.getColumn().setWidth(200); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(true); + + final int index = i; + + column.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(final Object element) { + return ((AttributeRow) element).getElementAt(index); + } + }); + } + + model = new ArrayList<>(); + + if (content.size() > 0) { + // We first look for the biggest column, it will be the reference to generate all AttributeRow + int biggestColumn = 0; + + for (int i = 0; i < content.size(); i++) { + if (content.get(biggestColumn).length < content.get(i).length) { + biggestColumn = i; + } + } + + // For each row of the biggest column (String[]), we look for the rows + // at the same level in other columns and we build a AttributeRow with those data + for (int i = 0; i < content.get(biggestColumn).length; i++) { + final List attributes = new ArrayList<>(); + for (int j = 0; j < content.size(); j++) { + if (i < content.get(j).length) { + attributes.add(content.get(j)[i]); + } else { + attributes.add(""); + } + } + model.add(new AttributeRow(attributes, listener)); + } + } + + tableViewer.setContentProvider(new ArrayContentProvider()); + tableViewer.setInput(model); + + defineCellEditing(tableViewer, headers.size()); + addRightClickItems(tableViewer); + } + + /** + * Make cells of the tableViewer editable + */ + private void defineCellEditing(final TableViewer tableViewer, final int numberOfColumns) { + final String[] columnProperties = new String[numberOfColumns]; + final CellEditor[] cellEditors = new CellEditor[numberOfColumns]; + + for (int i = 0; i < numberOfColumns; i++) { + columnProperties[i] = Integer.toString(i); + cellEditors[i] = new TextCellEditor(tableViewer.getTable()); + } + + tableViewer.setColumnProperties(columnProperties); + + tableViewer.setCellEditors(cellEditors); + tableViewer.setCellModifier(new AttributeEditorCellModifier()); + + } + + /** + * Describe the behavior of right click on the tableViewer + */ + private void addRightClickItems(final TableViewer tableViewer) { + + // create menu item to delete column + final Menu tableHeaderMenu = new Menu(tableViewer.getTable()); + + // create menu item to insert column + final MenuItem insertColumnItem = new MenuItem(tableHeaderMenu, SWT.PUSH); + insertColumnItem.setText("Add row"); + insertColumnItem.setSelection(false); + insertColumnItem.addListener(SWT.Selection, event -> { + // call insert/add column page + final AttributeRow row = (AttributeRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + + final IAttributeChangesListener listener = (row1, index) -> tableViewer.refresh(); + + final List emptyAttributes = new ArrayList<>(); + for (int i = 0; i < tableViewer.getTable().getColumnCount(); i++) { + emptyAttributes.add("#TO_FILL#"); + } + + final AttributeRow emptyRow = new AttributeRow(emptyAttributes, listener); + + if (row != null) { + model.add(model.indexOf(row) + 1, emptyRow); + } else { + model.add(emptyRow); + } + + tableViewer.refresh(); + }); + + final MenuItem deleteColumnItem = new MenuItem(tableHeaderMenu, SWT.PUSH); + deleteColumnItem.setText("Delete Row"); + deleteColumnItem.setSelection(false); + deleteColumnItem.addListener(SWT.Selection, event -> { + + AttributeRow row = (AttributeRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + + while (row != null) { + row = (AttributeRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + if (row != null) { + model.remove(model.indexOf(row)); + tableViewer.refresh(); + } + } + }); + + // Link to the tableViewer + tableViewer.getTable().addListener(SWT.MenuDetect, event -> { + tableViewer.getTable().setMenu(tableHeaderMenu); + tableViewer.refresh(); + }); + } + + public TableViewer getTableViewer() { + return tableViewer; + } + + public void setTableViewer(final TableViewer tableViewer) { + this.tableViewer = tableViewer; + } + + public List getModel() { + return model; + } + + public void setModele(final List model) { + this.model = model; + } +} diff --git a/csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/DetailedEditor.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/DetailedEditor.java new file mode 100644 index 0000000..9835f95 --- /dev/null +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/DetailedEditor.java @@ -0,0 +1,248 @@ +/* Copyright 2011 csvedit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package me.glindholm.plugin.csvedit2.detailededitor; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import me.glindholm.plugin.csvedit2.model.CSVRow; + +/** + * Class providing methods to add a custom tableViewer to a Composite + * + * @author msavy + * + */ +public class DetailedEditor { + + Shell shell; + protected List componentList = new ArrayList<>(); + + protected CSVRow row; // The row to modify + protected List headerList; // A list of the headers for each column + // of the row + + protected String inCellDelimiter; + protected String regexTableMarker; + + final static String UNKNOWN_URL_FORMAT = "_UNKNOWN_URL_FORMAT:"; + + public Shell getShell() { + return shell; + } + + public void setShell(final Shell shell) { + this.shell = shell; + } + + /** + * Default constructor, open a new window + * + */ + public DetailedEditor(final Display display, final List headerList, final CSVRow row, final String inCellDelimiter, final String regexTableMarker) { + + shell = new Shell(display); + shell.setLayout(new FillLayout()); + shell.setText("Detailed CSV edition"); + + shell.setSize(800, 600); + + // If there is more columns for the header than there is for the column, + // we had empty columns in the row + // It happen when the row's last columns are empty and separators are + // forgotten. + // The CSV reader can't guess there is a column to create + if (row.getNumberOfElements() > 0 && headerList.size() > row.getNumberOfElements()) { + for (int i = row.getNumberOfElements() - 1; i < headerList.size(); i++) { + row.addElement(""); + } + } + + this.headerList = headerList; + this.row = row; + + this.inCellDelimiter = inCellDelimiter; + this.regexTableMarker = regexTableMarker; + + final ScrolledComposite scrolledComposite = new ScrolledComposite(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + scrolledComposite.setExpandHorizontal(true); + scrolledComposite.setExpandVertical(true); + + final Composite composite = new Composite(scrolledComposite, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + + generateComponents(composite); +// new Label(composite, SWT.NONE); + + final Composite compositeBtn = new Composite(composite, SWT.NONE); + final GridData gd_compositeBtn = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_compositeBtn.heightHint = 55; + gd_compositeBtn.widthHint = 220; + compositeBtn.setLayoutData(gd_compositeBtn); + + final Button btnApply = new Button(compositeBtn, SWT.NONE); + btnApply.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + } + }); + btnApply.setBounds(19, 14, 75, 30); + btnApply.addListener(SWT.Selection, e -> { + switch (e.type) { + case SWT.Selection: + updateRow(); + shell.dispose(); + break; + } + }); + btnApply.setText("Apply"); + + final Button btnCancel = new Button(compositeBtn, SWT.NONE); + btnCancel.setBounds(141, 14, 75, 30); + btnCancel.addListener(SWT.Selection, e -> { + switch (e.type) { + case SWT.Selection: + shell.dispose(); + break; + } + }); + btnCancel.setText("Cancel"); + + shell.setMinimumSize(400, 200); + + scrolledComposite.setContent(composite); + scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + + // The components must be filled only after the scrolled composite size + // has been set + // Otherwise the size of the scrolled composite would adapt its size to + // the content of its components + fillComponents(); + } + + /** + * Generates components of the DetailedView depending of their type + * + */ + private void generateComponents(final Composite composite) { + + for (int i = 0; i < headerList.size() && !headerList.get(i).equals(""); i++) { + + final Label label = new Label(composite, SWT.NONE); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + + if (headerList.get(i).matches(regexTableMarker)) { + final DetailedAttributeTableViewer tableViewer = new DetailedAttributeTableViewer(composite); + componentList.add(tableViewer); + + } else { + label.setText(headerList.get(i)); + + final Text text = new Text(composite, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + componentList.add(text); + } + } + } + + /** + * Fills components according to data provided by the field attribute "row" + * + */ + private void fillComponents() { + + for (int i = 0; i < componentList.size(); i++) { + + // Fill text components + String text = row.getElementAt(i); + if (text == null) { + text = ""; + } + if (componentList.get(i) instanceof Text) { + ((Text) componentList.get(i)).setText(text); + + // Fill table viewer components + } else if (componentList.get(i) instanceof DetailedAttributeTableViewer) { + + final List headers = new ArrayList<>(); + headers.add(headerList.get(i)); + + final String column1[] = text.split("[^|]\\|[^|]"); + for (int j = 0; j < column1.length; j++) { + column1[j] = column1[j].trim(); + } + + final List content = new ArrayList<>(); + if (!(column1.length == 1 && column1[0].equals(""))) { + content.add(column1); + } + ((DetailedAttributeTableViewer) componentList.get(i)).fillTable(headers, content); + } + } + } + + private void updateRow() { + + for (int i = 0; i < headerList.size() && !headerList.get(i).equals(""); i++) { + + Object component = componentList.get(i); + if (component instanceof Text) { + row.setRowEntry(i, ((Text) component).getText()); + + // if update source is a table viewer + } else if (component instanceof DetailedAttributeTableViewer) { + + final List model = ((DetailedAttributeTableViewer) component).getModel(); + final StringBuilder updatedStr = new StringBuilder(); + + for (final AttributeRow atts : model) { + + if (atts.getElementAt(0).equals("")) { + continue; + } + + updatedStr.append(atts.getElementAt(0).trim()); + updatedStr.append(" | "); + } + + String finalStr = updatedStr.toString(); + if (finalStr.length() > 0 && finalStr.substring(finalStr.length() - 3).equals(" | ")) { + finalStr = finalStr.substring(0, finalStr.length() - 3); + } + + row.setRowEntry(i, finalStr); + } + } + } + + public void open() { + shell.open(); + } +} \ No newline at end of file diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/IAttributeChangesListener.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/IAttributeChangesListener.java similarity index 72% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/IAttributeChangesListener.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/IAttributeChangesListener.java index 4e61274..63c99bf 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/IAttributeChangesListener.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/detailededitor/IAttributeChangesListener.java @@ -13,22 +13,22 @@ * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.detailededitor; +package me.glindholm.plugin.csvedit2.detailededitor; /** * Class providing methods to add a custom tableViewer to a Composite + * * @author fhenri * @author msavy * */ public interface IAttributeChangesListener { - /** - * Element at the given index position has changes in - * @param row the {@link AttributeRow} which changed - * @param index the index position - */ - void rowChanged(AttributeRow row, int index); + /** + * Element at the given index position has changes in + * + * @param row the {@link AttributeRow} which changed + * @param index the index position + */ + void rowChanged(AttributeRow row, int index); } - - diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/CSVEditorCellModifier.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/CSVEditorCellModifier.java similarity index 61% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/CSVEditorCellModifier.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/CSVEditorCellModifier.java index fd17c16..5576dc8 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/CSVEditorCellModifier.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/CSVEditorCellModifier.java @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.editors; +package me.glindholm.plugin.csvedit2.editors; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.swt.widgets.TableItem; -import org.fhsolution.eclipse.plugins.csvedit.model.CSVRow; + +import me.glindholm.plugin.csvedit2.model.CSVRow; /** * @@ -31,46 +32,47 @@ public class CSVEditorCellModifier implements ICellModifier { * @return true if the property can be modified, and false if it is not modifiable * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String) */ - public boolean canModify (Object element, String property) { + @Override + public boolean canModify(final Object element, final String property) { return true; } /** - * Returns the value for the given property of the given element. - * Returns "" if the element does not have the given property. + * Returns the value for the given property of the given element. Returns "" if the element does not + * have the given property. * * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String) */ - public Object getValue (Object element, String property) { - int elementIndex = Integer.parseInt(property); - CSVRow row = (CSVRow) element; + @Override + public Object getValue(final Object element, final String property) { + final int elementIndex = Integer.parseInt(property); + final CSVRow row = (CSVRow) element; - if(elementIndex < row.getNumberOfElements()) { + if (elementIndex < row.getNumberOfElements()) { return row.getElementAt(elementIndex); - } - else { + } else { return ""; } } /** - * Modifies the value for the given property of the given element. - * Has no effect if the element does not have the given property, - * or if the property cannot be modified. + * Modifies the value for the given property of the given element. Has no effect if the element does + * not have the given property, or if the property cannot be modified. * - * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object) + * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, + * java.lang.Object) */ - public void modify (Object element, String property, Object value) { - int elementIndex = Integer.parseInt(property); + @Override + public void modify(final Object element, final String property, final Object value) { + final int elementIndex = Integer.parseInt(property); if (element instanceof TableItem) { - CSVRow row = (CSVRow) ((TableItem) element).getData(); + final CSVRow row = (CSVRow) ((TableItem) element).getData(); - if(elementIndex < row.getNumberOfElements()) { + if (elementIndex < row.getNumberOfElements()) { row.setRowEntry(elementIndex, value.toString()); - } - else { - for (int i=row.getNumberOfElements();i tableModified(); + + private Label searchLabel; + + private Text searchText; + + /** + * Creates a multi-page editor example. + */ + public MultiPageCSVEditor() { + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + model = createCSVFile(); + } + + /** + * Create the CSV file object. Class that extends the MultiPageCSVEditor must implement this + * class. + * + * @return an {@link AbstractCSVFile} object which provides the contents as well as some formatting + * information such as the delimiter and extra meta information + */ + protected abstract AbstractCSVFile createCSVFile(); + + /** + * Creates the pages of the multi-page editor. + * + * @see org.eclipse.ui.part.MultiPageEditorPart#createPages() + */ + @Override + protected void createPages() { + try { + createTablePage(); + createSourcePage(); + updateTitle(); + populateTablePage(); + } catch (final Exception e) { + System.err.println(e); + e.printStackTrace(); + } + } + + /** + * Creates page 0 of the multi-page editor, which contains a text editor. + */ + private void createSourcePage() { + try { + editor = new CSVTextEditor(model.getCustomDelimiter()); + addPage(editor, getEditorInput()); + setPageText(indexSRC, "CSV Source"); + } catch (final PartInitException e) { + ErrorDialog.openError(getSite().getShell(), "Error creating nested text editor", null, e.getStatus()); + } + } + + /** + * + */ + private void createTablePage() { + final Composite parent = getContainer(); + + // XXX move all the creation into its own component + final Canvas canvas = new Canvas(parent, SWT.None); + + final GridLayout layout = new GridLayout(6, false); + canvas.setLayout(layout); + + searchLabel = new Label(canvas, SWT.NONE); + searchLabel.setText("Filter: "); + searchText = new Text(canvas, SWT.BORDER | SWT.SEARCH); + searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); + + // Create and configure the buttons + final Button duplicate = new Button(canvas, SWT.PUSH | SWT.CENTER); + final GridData buttonDuplicateGridData = createGridDataForButton(parent, duplicate, "Duplicate", "Duplicate the current row"); + duplicate.setLayoutData(buttonDuplicateGridData); + duplicate.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + final CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + if (row != null) { + model.duplicateRow(row); + tableModified(); + } + } + }); + + final Button insert = new Button(canvas, SWT.PUSH | SWT.CENTER); + final GridData buttonInsertGridData = createGridDataForButton(parent, insert, "Insert Row", "Insert a new row before the current one"); + insert.setLayoutData(buttonInsertGridData); + insert.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + final CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + if (row != null) { + model.addRowAfterElement(row); + tableModified(); + } + } + }); + /* + * insert.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { //if(((e.stateMask + * & SWT.CTRL) != 0) & (e.keyCode == 'd')) { //if (e.stateMask == SWT.CTRL && e.keyCode == 'd') { if + * (e.character == SWT.DEL) { CSVRow row = (CSVRow) ((IStructuredSelection) + * tableViewer.getSelection()).getFirstElement(); if (row != null) { model.addLineAfterElement(row); + * tableViewer.refresh(); tableModified(); } } } }); + */ + + final Button add = new Button(canvas, SWT.PUSH | SWT.CENTER); + final GridData buttonAddGridData = createGridDataForButton(parent, add, "Add Row", "Add a new row at the end of the file"); + add.setLayoutData(buttonAddGridData); + add.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + model.addRow(); + tableModified(); + } + }); + + final Button delete = new Button(canvas, SWT.PUSH | SWT.CENTER); + final GridData buttonDelGridData = createGridDataForButton(parent, delete, "Delete Row", "Delete the current row"); + delete.setLayoutData(buttonDelGridData); + delete.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + + while (row != null) { + row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + if (row != null) { + model.removeRow(row); + tableModified(); + } + } + } + }); + /* + * insert.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.stateMask == + * SWT.CTRL && e.keyCode == 'd') { CSVRow row = (CSVRow) ((IStructuredSelection) + * tableViewer.getSelection()).getFirstElement(); if (row != null) { model.removeLine(row); + * tableViewer.refresh(); tableModified(); } } } }); + */ + /* + * + * // manage 1st line - should only be visible if global option is set if + * (pref.getUseFirstLineAsHeader()) { Label encodingLineLabel = new Label(canvas, SWT.NONE); + * encodingLineLabel.setText("Display 1st line"); final Button encodingLineBtn = new Button(canvas, + * SWT.CHECK); encodingLineBtn.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); + * encodingLineBtn.setSelection(true); encodingLineBtn.addSelectionListener(new SelectionAdapter() { + * public void widgetSelected(SelectionEvent e) { + * model.displayFirstLine(encodingLineBtn.getSelection()); updateTableFromTextEditor(); } }); } + * sensitiveBtn.addSelectionListener(new SelectionAdapter() { public void + * widgetSelected(SelectionEvent e) { tableFilter.setSearchText(searchText.getText(), + * sensitiveBtn.getSelection()); labelProvider.setSearchText(searchText.getText()); + * tableViewer.refresh(); } }); + */ + tableViewer = new TableViewer(canvas, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + tableViewer.setUseHashlookup(true); + final Table table = tableViewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + + // set the sorter for the table + tableSorter = new CSVTableSorter(); + tableViewer.setComparator(tableSorter); + + // set a table filter + final CSVTableFilter tableFilter = new CSVTableFilter(); + tableViewer.addFilter(tableFilter); + + // add the filtering and coloring when searching specific elements. + searchText.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(final KeyEvent ke) { + tableFilter.setSearchText(searchText.getText(), model.getSensitiveSearch()); + final String filterText = searchText.getText(); + for (int i = 0; i < tableViewer.getColumnProperties().length; i++) { + final CellLabelProvider labelProvider = tableViewer.getLabelProvider(i); + if (labelProvider != null) { + ((CSVLabelProvider) labelProvider).setSearchText(filterText); + } + } + tableViewer.refresh(); + } + }); + + /* + * // create a TableCursor to navigate around the table final TableCursor cursor = new + * TableCursor(table, SWT.NONE); // create an editor to edit the cell when the user hits "ENTER" // + * while over a cell in the table final ControlEditor editor = new ControlEditor(cursor); + * editor.grabHorizontal = true; editor.grabVertical = true; + * + * cursor.addSelectionListener(new SelectionAdapter() { // This is called as the user navigates + * around the table public void widgetSelected(SelectionEvent e) { // Select the row in the table + * where the TableCursor is table.setSelection(new TableItem[] {cursor.getRow()}); } + * + * // when the user hits "ENTER" in the TableCursor, // pop up a text editor so that user can change + * the text of the cell public void widgetDefaultSelected(SelectionEvent e) { // Begin an editing + * session final Text text = new Text(cursor, SWT.NONE); + * + * // Copy the text from the cell to the Text int column = cursor.getColumn(); + * text.setText(cursor.getRow().getText(column)); + * + * // Add a handler to detect key presses text.addKeyListener(new KeyAdapter() { public void + * keyPressed(KeyEvent e) { // tab will save & move to the next column if (e.character == SWT.TAB) { + * TableItem row = cursor.getRow(); int column = cursor.getColumn(); row.setText(column, + * text.getText()); text.dispose(); cursor.setSelection(row, column+1); tableModified(); } // close + * the text editor and copy the data over // when the user hits "ENTER" if (e.character == SWT.CR) { + * TableItem row = cursor.getRow(); row.setText(cursor.getColumn(), text.getText()); + * tableModified(); text.dispose(); } // close the text editor when the user hits "ESC" if + * (e.character == SWT.ESC) { text.dispose(); } } }); // close the text editor when the user tabs + * away text.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { + * text.dispose(); } }); editor.setEditor(text); text.setFocus(); } }); + * + * /* // Hide the TableCursor when the user hits the "CTRL" or "SHIFT" key. // This allows the user + * to select multiple items in the table. cursor.addKeyListener(new KeyAdapter() { public void + * keyPressed(KeyEvent e) { + * + * // delete line if (e.character == SWT.DEL) { TableItem row = cursor.getRow(); tableModified(); + * row.dispose(); //table.showItem(row); //cursor.setSelection(row, 0); } + * + * // insert line if (e.character == (char) SWT.F8) { TableItem row = cursor.getRow(); + * row.dispose(); } + * + * // add line + * + * cursor.setVisible(true); cursor.setFocus(); + * + * if (e.keyCode == SWT.CTRL || e.keyCode == SWT.SHIFT || (e.stateMask & SWT.CONTROL) != 0 || + * (e.stateMask & SWT.SHIFT) != 0) { cursor.setVisible(false); return; } } }); + * + * // When the user double clicks in the TableCursor, pop up a text editor so that // they can + * change the text of the cell. cursor.addMouseListener(new MouseAdapter() { public void + * mouseDown(MouseEvent e) { final Text text = new Text(cursor, SWT.NONE); TableItem row = + * cursor.getRow(); int column = cursor.getColumn(); text.setText(row.getText(column)); + * text.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { // close the text + * editor and copy the data over // when the user hits "ENTER" if (e.character == SWT.CR) { + * TableItem row = cursor.getRow(); int column = cursor.getColumn(); row.setText(column, + * text.getText()); tableModified(); text.dispose(); } // close the text editor when the user hits + * "ESC" if (e.character == SWT.ESC) { text.dispose(); } } }); // close the text editor when the + * user clicks away text.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { + * text.dispose(); } }); editor.setEditor(text); text.setFocus(); } }); + * + * // Show the TableCursor when the user releases the "SHIFT" or "CTRL" key. // This signals the end + * of the multiple selection task. table.addKeyListener(new KeyAdapter() { public void + * keyReleased(KeyEvent e) { + * + * if (e.keyCode == SWT.CONTROL && (e.stateMask & SWT.SHIFT) != 0) return; if (e.keyCode == + * SWT.SHIFT && (e.stateMask & SWT.CONTROL) != 0) return; if (e.keyCode != SWT.CONTROL && + * (e.stateMask & SWT.CONTROL) != 0) return; if (e.keyCode != SWT.SHIFT && (e.stateMask & SWT.SHIFT) + * != 0) return; + * + * TableItem[] selection = table.getSelection(); TableItem row = (selection.length == 0) ? + * table.getItem(table.getTopIndex()) : selection[0]; table.showItem(row); cursor.setSelection(row, + * 0); cursor.setVisible(true); cursor.setFocus(); } }); + */ + + /* + * tableViewer.addDoubleClickListener(new IDoubleClickListener() { + * + * public void doubleClick(DoubleClickEvent event) { + * + * CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + * DetailedView input = new DetailedView(Display.getDefault(), model.getHeader(), row); + * + * input.open(); + * + * } }); + */ + + // Layout the viewer + final GridData gridData = new GridData(); + gridData.verticalAlignment = GridData.FILL; + gridData.horizontalSpan = 6; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + gridData.horizontalAlignment = GridData.FILL; + tableViewer.getControl().setLayoutData(gridData); + + addPage(canvas); + setPageText(indexTBL, "CSV Table"); + } + + private static GridData createGridDataForButton(final Composite parent, final Button button, String myText, String toolTip) { + Text textName = new Text(parent, SWT.BORDER); + textName.setText(myText); + Point size = textName.computeSize(SWT.DEFAULT, SWT.DEFAULT); + + button.setText(textName.getText()); + button.setToolTipText(toolTip); + final GridData buttonDuplicateGridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + buttonDuplicateGridData.widthHint = size.x; + return buttonDuplicateGridData; + } + + /** + * Set Name of the file to the tab + */ + private void updateTitle() { + final IEditorInput input = getEditorInput(); + setPartName(input.getName()); + setTitleToolTip(input.getToolTipText()); + } + + /** + * @throws Exception + */ + private void populateTablePage() throws Exception { + tableViewer.setContentProvider(new CSVContentProvider()); + + // make the selection available + getSite().setSelectionProvider(tableViewer); + + tableViewer.getTable().getDisplay().asyncExec(this::updateTableFromTextEditor); + } + + /** + * + */ + public void tableModified() { + tableViewer.refresh(); + final boolean wasPageModified = isPageModified; + isPageModified = true; + if (!wasPageModified) { + firePropertyChange(IEditorPart.PROP_DIRTY); + editor.validateEditorInputState(); // will invoke: + // FileModificationValidator.validateEdit() + // (expected by some repository + // providers) + } + } + + /** + * + */ + private void updateTableFromTextEditor() { + + tableHeaderMenu = new Menu(tableViewer.getTable()); + + // PropertyFile propertyFile = (PropertyFile) treeViewer.getInput(); + model.removeModelListener(csvFileListener); + + model.setInput(editor.getDocumentProvider().getDocument(editor.getEditorInput()).get()); + + final MenuItem detailedEditItem = new MenuItem(tableHeaderMenu, SWT.PUSH, 0); + detailedEditItem.setText("Edit"); + detailedEditItem.setSelection(false); + detailedEditItem.addListener(SWT.Selection, event -> { + + final CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); + + if (row != null) { + final DetailedEditor input = new DetailedEditor(Display.getDefault(), model.getHeader(), row, model.getInCellDelimiter(), + model.getRegexTableMarker()); + input.open(); + } + }); + +// new MenuItem(tableHeaderMenu, SWT.SEPARATOR, 1); + + final TableColumn[] columns = tableViewer.getTable().getColumns(); + if (columns.length > 0) { // if table header columns already created + // update column header text + for (int i = 0; i < model.getHeader().size(); i++) { + if (i < columns.length) { + columns[i].setText(model.getHeader().get(i)); + addMenuItemToColumn(columns[i], i); + } + } + } else { + // create columns + for (int i = 0; i < model.getHeader().size(); i++) { + final TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.LEFT); + final int index = i; + column.getColumn().setText(model.getHeader().get(i)); + column.getColumn().setWidth(100); + column.getColumn().setResizable(true); + column.getColumn().setMoveable(true); + column.setLabelProvider(new CSVLabelProvider()); + addMenuItemToColumn(column.getColumn(), index); + } + } + + if (model.isFirstLineHeader()) { +// new MenuItem(tableHeaderMenu, SWT.SEPARATOR); +// + // create menu item to delete column + final MenuItem deleteColumnItem = new MenuItem(tableHeaderMenu, SWT.PUSH); + deleteColumnItem.setText("Delete Column"); + deleteColumnItem.setSelection(false); + deleteColumnItem.addListener(SWT.Selection, event -> { + // call delete column page + final DeleteColumnPage dcPage = new DeleteColumnPage(getSite().getShell(), model.getArrayHeader()); + if (dcPage.open() == Window.OK) { + final String[] colToDelete = dcPage.getColumnSelected(); + for (final String column : colToDelete) { + final int colIndex = findColumnForName(column); + tableViewer.getTable().getColumn(colIndex).dispose(); + // +2 because the first two items are Edit and a separator + tableHeaderMenu.getItem(colIndex + 2).dispose(); + model.removeColumn(column); + } + tableModified(); + } + }); + + // create menu item to insert column + final MenuItem insertColumnItem = new MenuItem(tableHeaderMenu, SWT.PUSH); + insertColumnItem.setText("Add Column"); + insertColumnItem.setSelection(false); + insertColumnItem.addListener(SWT.Selection, event -> { + // call insert/add column page + final InsertColumnPage acPage = new InsertColumnPage(getSite().getShell(), model.getArrayHeader()); + if (acPage.open() == Window.OK) { + final String colToInsert = acPage.getColumnNewName(); + model.addColumn(colToInsert); + + tableViewer.setInput(model); + final TableColumn column = new TableColumn(tableViewer.getTable(), SWT.LEFT); + column.setText(colToInsert); + column.setWidth(100); + column.setResizable(true); + column.setMoveable(true); + + addMenuItemToColumn(column, model.getColumnCount() - 1); + defineCellEditing(); + + tableModified(); + } + }); + } + + tableViewer.setInput(model); + model.addModelListener(csvFileListener); + + tableViewer.getTable().addListener(SWT.MenuDetect, event -> tableViewer.getTable().setMenu(tableHeaderMenu)); + + defineCellEditing(); + } + + /** + * + */ + private void defineCellEditing() { + final String[] columnProperties = new String[model.getColumnCount()]; + final CellEditor[] cellEditors = new CellEditor[model.getColumnCount()]; + + for (int i = 0; i < model.getColumnCount(); i++) { + columnProperties[i] = Integer.toString(i); + cellEditors[i] = new TextCellEditor(tableViewer.getTable()); + } + + tableViewer.setColumnProperties(columnProperties); + + // XXX can be replaced by tableViewer.setEditingSupport() + tableViewer.setCellEditors(cellEditors); + tableViewer.setCellModifier(new CSVEditorCellModifier()); + + } + + /** + * Find a column in the Table by its name + * + * @param columnName + * @return the index of the Column indicated by its name + */ + private int findColumnForName(final String columnName) { + final int index = -1; + final TableColumn[] tableColumns = tableViewer.getTable().getColumns(); + for (int i = 0; i < tableColumns.length; i++) { + final TableColumn column = tableColumns[i]; + if (columnName.equalsIgnoreCase(column.getText())) { + return i; + } + } + return index; + } + + /** + * @param column + * @param index + */ + private void addMenuItemToColumn(final TableColumn column, final int index) { + + // create menu item + final MenuItem itemName = new MenuItem(tableHeaderMenu, SWT.CHECK, index); + itemName.setText(column.getText()); + itemName.setSelection(column.getResizable()); + itemName.addListener(SWT.Selection, event -> { + if (itemName.getSelection()) { + column.setWidth(100); + column.setResizable(true); + } else { + column.setWidth(0); + column.setResizable(false); + } + }); + + // Setting the right sorter + column.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + int dir = tableViewer.getTable().getSortDirection(); + switch (dir) { + case SWT.UP: + dir = SWT.DOWN; + break; + case SWT.DOWN: + dir = SWT.NONE; + break; + case SWT.NONE: + dir = SWT.UP; + break; + } + tableSorter.setColumn(index, dir); + tableViewer.getTable().setSortDirection(dir); + if (dir == SWT.NONE) { + tableViewer.getTable().setSortColumn(null); + } else { + tableViewer.getTable().setSortColumn(column); + } + tableViewer.refresh(); + } + }); + + } + + /** + * The MultiPageEditorPart implementation of this IWorkbenchPart method + * disposes all nested editors. This method is automatically called when the editor is closed and + * marks the end of the editor's life cycle. It cleans up any platform resources, such as images, + * clipboard, and so on, which were created by this class. + * + * @see org.eclipse.ui.part.MultiPageEditorPart#dispose() + */ + @Override + public void dispose() { + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); + if (tableHeaderMenu != null && !tableHeaderMenu.isDisposed()) { + tableHeaderMenu.dispose(); + tableHeaderMenu = null; + } + if (editor != null) { + editor.dispose(); + editor = null; + } + + if (searchLabel != null && !searchLabel.isDisposed()) { + searchLabel.dispose(); + searchLabel = null; + } + + if (searchText != null && !searchText.isDisposed()) { + searchText.dispose(); + searchText = null; + } + + super.dispose(); + } + + /** + * Saves the multi-page editor's document. If the save is successful, the part should fire a + * property changed event (PROP_DIRTY property), reflecting the new dirty state. If the save is + * canceled via user action, or for any other reason, the part should invoke setCanceled on the + * IProgressMonitor to inform the caller + * + * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + public void doSave(final IProgressMonitor monitor) { + if (getActivePage() == indexTBL && isPageModified) { + updateTextEditorFromTable(); + } else { + updateTableFromTextEditor(); + } + + isPageModified = false; + editor.doSave(monitor); + } + + /** + * Returns whether the "Save As" operation is supported by this part. + * + * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() + */ + @Override + public boolean isSaveAsAllowed() { + return true; + } + + /** + * Saves the multi-page editor's document as another file. Also updates the text for page 0's tab, + * and updates this multi-page editor's input to correspond to the nested editor's. + * + * @see org.eclipse.ui.part.EditorPart#doSaveAs() + */ + @Override + public void doSaveAs() { + if (getActivePage() == indexTBL && isPageModified) { + updateTextEditorFromTable(); + } else { + updateTableFromTextEditor(); + } + + isPageModified = false; + + editor.doSaveAs(); + setInput(editor.getEditorInput()); + updateTitle(); + } + + /** + * Initializes this editor with the given editor site and input. This method is automatically called + * shortly after editor construction; it marks the start of the editor's lifecycle. + * + * The MultiPageEditorExample implementation of this method checks that the input is an + * instance of IFileEditorInput. + * + * @see org.eclipse.ui.part.MultiPageEditorPart#init(org.eclipse.ui.IEditorSite, + * org.eclipse.ui.IEditorInput) + */ + @Override + public void init(final IEditorSite site, final IEditorInput editorInput) throws PartInitException { + /* + * String message = "Input is " + editorInput + " of instance " + editorInput.getClass().getName(); + * IStatus status = new Status(IStatus.ERROR, "csvedit", IStatus.ERROR, message, null); + * Activator.getDefault().getLog().log(status); + */ + + /* + * if (!(editorInput instanceof IFileEditorInput)) throw new + * PartInitException("Invalid Input: Must be IFileEditorInput"); + */ + super.init(site, editorInput); + } + + /** + * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int) + */ + @Override + protected void handlePropertyChange(final int propertyId) { + if (propertyId == IEditorPart.PROP_DIRTY) { + isPageModified = isDirty(); + } + super.handlePropertyChange(propertyId); + } + + /** + * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty() + */ + @Override + public boolean isDirty() { + return isPageModified || super.isDirty(); + } + + /** + * Calculates the contents of page 2 when the it is activated. + * + * @see org.eclipse.ui.part.MultiPageEditorPart#pageChange(int) + */ + @Override + protected void pageChange(final int newPageIndex) { + switch (newPageIndex) { + case indexSRC: + if (isDirty()) { + updateTextEditorFromTable(); + } + break; + case indexTBL: + if (isDirty()) { + updateTableFromTextEditor(); + } + break; + } + isPageModified = false; + super.pageChange(newPageIndex); + } + + /** + * + */ + private void updateTextEditorFromTable() { + editor.getDocumentProvider().getDocument(editor.getEditorInput()).set(((AbstractCSVFile) tableViewer.getInput()).getTextRepresentation()); + } + + /** + * When the focus shifts to the editor, this method is called; it must then redirect focus to the + * appropriate editor based on which page is currently selected. + * + * @see org.eclipse.ui.part.MultiPageEditorPart#setFocus() + */ + @Override + public void setFocus() { + switch (getActivePage()) { + case indexSRC: + editor.setFocus(); + break; + case indexTBL: + tableViewer.getTable().setFocus(); + break; + } + } + + /** + * Closes all project files on project close. + * + * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) + */ + @Override + public void resourceChanged(final IResourceChangeEvent event) { + if (event.getType() == IResourceChangeEvent.PRE_CLOSE) { + Display.getDefault().asyncExec(() -> { + final IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages(); + for (final IWorkbenchPage page : pages) { + if (((FileEditorInput) editor.getEditorInput()).getFile().getProject().equals(event.getResource())) { + final IEditorPart editorPart = page.findEditor(editor.getEditorInput()); + page.closeEditor(editorPart, true); + } + } + }); + } + } +} diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/MultiPageCSVEditorContributor.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/MultiPageCSVEditorContributor.java similarity index 73% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/MultiPageCSVEditorContributor.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/MultiPageCSVEditorContributor.java index e512a7b..8204d71 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/MultiPageCSVEditorContributor.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/MultiPageCSVEditorContributor.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.editors; +package me.glindholm.plugin.csvedit2.editors; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; @@ -22,9 +22,9 @@ import org.eclipse.ui.texteditor.ITextEditor; /** - * This is the contributor class defines in the Editor ContributorClass attribute - * of the pluging which adds new actions to the workbench menu and toolbar, - * reflecting the features of the editor type + * This is the contributor class defines in the Editor ContributorClass attribute of the pluging + * which adds new actions to the workbench menu and toolbar, reflecting the features of the editor + * type * * @author fhenri * @@ -34,36 +34,39 @@ public class MultiPageCSVEditorContributor extends MultiPageEditorActionBarContr /** * Creates a multi-page contributor. */ - public MultiPageCSVEditorContributor () { - super(); + public MultiPageCSVEditorContributor() { } /** * Returns the action registered with the given text editor. + * * @return IAction or null if editor is null. */ - protected IAction getAction (ITextEditor editor, String actionID) { - return (editor == null ? null : editor.getAction(actionID)); + protected IAction getAction(final ITextEditor editor, final String actionID) { + return editor == null ? null : editor.getAction(actionID); } /** * * @see org.eclipse.ui.part.MultiPageEditorActionBarContributor#setActivePage(org.eclipse.ui.IEditorPart) */ - public void setActivePage (IEditorPart part) { + @Override + public void setActivePage(final IEditorPart part) { } /** * * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager) */ - public void contributeToMenu (IMenuManager manager) { + @Override + public void contributeToMenu(final IMenuManager manager) { } /** * * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(org.eclipse.jface.action.IToolBarManager) */ - public void contributeToToolBar (IToolBarManager manager) { + @Override + public void contributeToToolBar(final IToolBarManager manager) { } } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVRegion.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVRegion.java similarity index 86% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVRegion.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVRegion.java index 5cd7a17..d06ff56 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVRegion.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVRegion.java @@ -12,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.editors.text; +package me.glindholm.plugin.csvedit2.editors.text; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITypedRegion; /** * {@link CSVRegion} defines a piece of information inside a CSV document + * * @author J. Andres Pizarro */ public class CSVRegion implements ITypedRegion { @@ -34,35 +35,38 @@ public class CSVRegion implements ITypedRegion { /** * Constructor + * * @param offset the region offset inside the document * @param length the region length - * @param index the region index + * @param index the region index */ - public CSVRegion(int offset, int length, int index) - { + public CSVRegion(final int offset, final int length, final int index) { m_offset = offset; m_length = length; m_index = index; } + @Override public int getLength() { return m_length; } + @Override public int getOffset() { return m_offset; } + @Override public String getType() { return IDocument.DEFAULT_CONTENT_TYPE; } /** * Get the index where this region is positioned inside a CSV line + * * @return the column index where this region is located */ - public int getColumnIndex() - { + public int getColumnIndex() { return m_index; } } \ No newline at end of file diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTextEditor.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTextEditor.java similarity index 74% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTextEditor.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTextEditor.java index 75c5241..962f326 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTextEditor.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTextEditor.java @@ -12,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.editors.text; +package me.glindholm.plugin.csvedit2.editors.text; import org.eclipse.ui.editors.text.TextEditor; /** - * {@link CSVTextEditor} extends basic {@link TextEditor} adding syntax highlighting - * for the separated elements + * {@link CSVTextEditor} extends basic {@link TextEditor} adding syntax highlighting for the + * separated elements + * * @author J. Andres Pizarro Gascon */ public class CSVTextEditor extends TextEditor { @@ -26,10 +27,8 @@ public class CSVTextEditor extends TextEditor { /** * Constructor */ - public CSVTextEditor(char delimiter) - { - CSVTextSourceViewerConfiguration csvTextConfig = - new CSVTextSourceViewerConfiguration(delimiter, getPreferenceStore()); + public CSVTextEditor(final char delimiter) { + final CSVTextSourceViewerConfiguration csvTextConfig = new CSVTextSourceViewerConfiguration(delimiter, getPreferenceStore()); setSourceViewerConfiguration(csvTextConfig); } } \ No newline at end of file diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTextSourceViewerConfiguration.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTextSourceViewerConfiguration.java similarity index 72% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTextSourceViewerConfiguration.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTextSourceViewerConfiguration.java index fd0a864..de456eb 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTextSourceViewerConfiguration.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTextSourceViewerConfiguration.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.editors.text; +package me.glindholm.plugin.csvedit2.editors.text; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.IDocument; @@ -22,33 +22,35 @@ import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; -class CSVTextSourceViewerConfiguration extends TextSourceViewerConfiguration -{ +class CSVTextSourceViewerConfiguration extends TextSourceViewerConfiguration { /** Delimiter */ private final char m_delimiter; /** * Constructor + * * @param prefStore the {@link IPreferenceStore} used by the base class constructor */ - public CSVTextSourceViewerConfiguration(char delimiter, IPreferenceStore prefStore) { + public CSVTextSourceViewerConfiguration(final char delimiter, final IPreferenceStore prefStore) { super(prefStore); m_delimiter = delimiter; } /* * (non-Javadoc) - * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer) + * + * @see + * org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse. + * jface.text.source.ISourceViewer) */ @Override - public IPresentationReconciler getPresentationReconciler( - ISourceViewer sourceViewer) { - PresentationReconciler reconciler = new PresentationReconciler(); + public IPresentationReconciler getPresentationReconciler(final ISourceViewer sourceViewer) { + final PresentationReconciler reconciler = new PresentationReconciler(); /* * Reconciler configuration */ - DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new CSVTokenScanner(m_delimiter)); + final DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new CSVTokenScanner(m_delimiter)); reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); return reconciler; diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVToken.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVToken.java similarity index 78% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVToken.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVToken.java index 91a8f68..7681ba7 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVToken.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVToken.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.editors.text; +package me.glindholm.plugin.csvedit2.editors.text; import org.eclipse.jface.text.TextAttribute; import org.eclipse.jface.text.rules.Token; @@ -22,12 +22,11 @@ public class CSVToken extends Token { /** * Different CSV tokens + * * @author japg */ - public enum CSVTokenType - { - ODD_COLUMN(new TextAttribute(null, null, SWT.NORMAL)), - EVEN_COLUMN(new TextAttribute(null, null, SWT.BOLD)), + public enum CSVTokenType { + ODD_COLUMN(new TextAttribute(null, null, SWT.NORMAL)), EVEN_COLUMN(new TextAttribute(null, null, SWT.BOLD)), SEPARATOR(new TextAttribute(null, null, SWT.NORMAL)); /** Text decoration */ @@ -35,19 +34,19 @@ public enum CSVTokenType /** * Constructor + * * @param attrs */ - private CSVTokenType(TextAttribute attrs) - { + CSVTokenType(final TextAttribute attrs) { m_textDecoration = attrs; } /** * Get text attributes for this token type + * * @return */ - TextAttribute getTextAttribute() - { + TextAttribute getTextAttribute() { return m_textDecoration; } } @@ -57,20 +56,21 @@ TextAttribute getTextAttribute() /** * Constructor + * * @param type * @param column */ - public CSVToken(CSVTokenType type, int column) { + public CSVToken(final CSVTokenType type, final int column) { super(type.getTextAttribute()); m_columnIndex = column; } /** * Get column index where this token is located + * * @return */ - public int getColumnIndex() - { + public int getColumnIndex() { return m_columnIndex; } } \ No newline at end of file diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTokenScanner.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTokenScanner.java similarity index 64% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTokenScanner.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTokenScanner.java index c47d79c..d3a57c4 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/text/CSVTokenScanner.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/editors/text/CSVTokenScanner.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.editors.text; +package me.glindholm.plugin.csvedit2.editors.text; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -20,7 +20,8 @@ import org.eclipse.jface.text.rules.IToken; import org.eclipse.jface.text.rules.ITokenScanner; import org.eclipse.jface.text.rules.Token; -import org.fhsolution.eclipse.plugins.csvedit.editors.text.CSVToken.CSVTokenType; + +import me.glindholm.plugin.csvedit2.editors.text.CSVToken.CSVTokenType; public class CSVTokenScanner implements ITokenScanner { @@ -42,7 +43,7 @@ public class CSVTokenScanner implements ITokenScanner { /** Current column */ private int m_currentColumn; - /** Current token offset*/ + /** Current token offset */ private int m_tokenOffset; /** Current token length */ @@ -51,14 +52,14 @@ public class CSVTokenScanner implements ITokenScanner { /** * Constructor * - * @param separator - * the separator to use for scanning tokens + * @param separator the separator to use for scanning tokens */ - public CSVTokenScanner(char separator) { + public CSVTokenScanner(final char separator) { m_delimiter = separator; } - public void setRange(IDocument document, int offset, int length) { + @Override + public void setRange(final IDocument document, final int offset, final int length) { m_document = document; m_docOffset = offset; m_docLength = length; @@ -71,83 +72,79 @@ public void setRange(IDocument document, int offset, int length) { m_tokenLength = 0; } + @Override public IToken nextToken() { - if (m_currentOffset >= (m_docOffset + m_docLength)) { + if (m_currentOffset >= m_docOffset + m_docLength) { return Token.EOF; } IToken result = Token.UNDEFINED; - int startOffset = m_currentOffset; + final int startOffset = m_currentOffset; int length = 0; try { // Get line information - IRegion lineRegion = m_document.getLineInformationOfOffset(m_currentOffset); - int lineMinOffset = lineRegion.getOffset(); - int lineMaxOffset = lineMinOffset + lineRegion.getLength(); + final IRegion lineRegion = m_document.getLineInformationOfOffset(m_currentOffset); + final int lineMinOffset = lineRegion.getOffset(); + final int lineMaxOffset = lineMinOffset + lineRegion.getLength(); // Read char - char current = m_document.getChar(m_currentOffset++); + final char current = m_document.getChar(m_currentOffset++); length++; // Check if we are at the end of the line - if (current == '\n') - { + if (current == '\n') { result = Token.WHITESPACE; m_tokenOffset = startOffset; m_tokenLength = length; m_currentColumn = 0; - } - else if (current == m_delimiter) { - result = new CSVToken(CSVTokenType.SEPARATOR, - m_currentColumn++); + } else if (current == m_delimiter) { + result = new CSVToken(CSVTokenType.SEPARATOR, m_currentColumn++); m_tokenOffset = startOffset; m_tokenLength = length; - //System.out.println("Token found [" + m_document.get(m_tokenOffset, m_tokenLength) + "]"); + // System.out.println("Token found [" + m_document.get(m_tokenOffset, m_tokenLength) + "]"); } else { // Look for the next delimiter or the next line boolean scan = true; while (scan) { // check if we are at the end of the line if (m_currentOffset >= lineMaxOffset) { - CSVTokenType type = ((m_currentColumn % 2) == 0) ? CSVTokenType.ODD_COLUMN : CSVTokenType.EVEN_COLUMN; + final CSVTokenType type = m_currentColumn % 2 == 0 ? CSVTokenType.ODD_COLUMN : CSVTokenType.EVEN_COLUMN; result = new CSVToken(type, m_currentColumn); m_tokenOffset = startOffset; m_tokenLength = length; - m_currentColumn= 0; - //System.out.println("Token found [" + m_document.get(m_tokenOffset, m_tokenLength) + "]"); + m_currentColumn = 0; + // System.out.println("Token found [" + m_document.get(m_tokenOffset, m_tokenLength) + "]"); scan = false; - } - else - { + } else { // iterate until a delimiter is found - char next = m_document.getChar(m_currentOffset); + final char next = m_document.getChar(m_currentOffset); if (next == m_delimiter) { - CSVTokenType type = ((m_currentColumn % 2) == 0) ? CSVTokenType.ODD_COLUMN : CSVTokenType.EVEN_COLUMN; + final CSVTokenType type = m_currentColumn % 2 == 0 ? CSVTokenType.ODD_COLUMN : CSVTokenType.EVEN_COLUMN; result = new CSVToken(type, m_currentColumn); m_tokenOffset = startOffset; m_tokenLength = length; - //System.out.println("Token found [" + m_document.get(m_tokenOffset, m_tokenLength) + "]"); + // System.out.println("Token found [" + m_document.get(m_tokenOffset, m_tokenLength) + "]"); scan = false; - } - else - { + } else { m_currentOffset++; length++; } } } } - } catch (BadLocationException e) { + } catch (final BadLocationException e) { e.printStackTrace(); result = Token.EOF; } return result; } + @Override public int getTokenOffset() { return m_tokenOffset; } + @Override public int getTokenLength() { return m_tokenLength; } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/filter/CSVTableFilter.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/filter/CSVTableFilter.java similarity index 67% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/filter/CSVTableFilter.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/filter/CSVTableFilter.java index 13bc541..9a80c75 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/filter/CSVTableFilter.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/filter/CSVTableFilter.java @@ -12,14 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.filter; +package me.glindholm.plugin.csvedit2.filter; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; -import org.fhsolution.eclipse.plugins.csvedit.model.CSVRow; + +import me.glindholm.plugin.csvedit2.model.CSVRow; /** * Filter the elements given a pattern. @@ -37,32 +38,34 @@ public class CSVTableFilter extends ViewerFilter { * * @param s string to search */ - public void setSearchText (String s, boolean isCaseSensitive) { + public void setSearchText(final String s, final boolean isCaseSensitive) { // Search must be a substring of the existing value - this.searchString = ".*" + s + ".*"; + searchString = ".*" + s + ".*"; if (isCaseSensitive) { - searchPattern = - Pattern.compile(searchString); + searchPattern = Pattern.compile(searchString); } else { - searchPattern = - Pattern.compile(searchString, Pattern.CASE_INSENSITIVE); + searchPattern = Pattern.compile(searchString, Pattern.CASE_INSENSITIVE); } } /** - * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, + * java.lang.Object, java.lang.Object) */ @Override - public boolean select (Viewer viewer, Object parentElement, Object element) { + public boolean select(final Viewer viewer, final Object parentElement, final Object element) { if (searchString == null || searchString.length() == 0) { return true; } // loop on all column of the current row to find matches - CSVRow row = (CSVRow) element; - for (String s:row.getEntries()) { - Matcher m = searchPattern.matcher(s); + final CSVRow row = (CSVRow) element; + for (String s : row.getEntries()) { + if (s == null) { + s = ""; + } + final Matcher m = searchPattern.matcher(s); if (m.matches()) { return true; } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/model/AbstractCSVFile.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/model/AbstractCSVFile.java similarity index 67% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/model/AbstractCSVFile.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/model/AbstractCSVFile.java index 6135c2a..75b8996 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/model/AbstractCSVFile.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/model/AbstractCSVFile.java @@ -12,17 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.model; +package me.glindholm.plugin.csvedit2.model; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import com.csvreader.CsvReader; -import com.csvreader.CsvWriter; +import org.jumpmind.symmetric.csv.CsvReader; +import org.jumpmind.symmetric.csv.CsvWriter; /** * @@ -44,59 +45,74 @@ public abstract class AbstractCSVFile implements IRowChangesListener { public AbstractCSVFile() { nbOfColumns = 1; displayFirstLine = true; - rows = new ArrayList(); - listeners = new ArrayList(); - header = new ArrayList(); + rows = new ArrayList<>(); + listeners = new ArrayList<>(); + header = new ArrayList<>(); } // TODO : all abstract methods should be moved to a specific interface /** * Check if first line in the file will be considered as the file header + * * @return true if the first line in the file represents the header */ public abstract boolean isFirstLineHeader(); /** * Check search in the text must be case sensitive + * * @return true if the search must be case sensitive. */ public abstract boolean getSensitiveSearch(); + /** + * Get custom delimiter to use as a separator for the header + * + * @return the delimiter + */ + public abstract char getCustomHeaderDelimiter(); + /** * Get custom delimiter to use as a separator + * * @return the delimiter */ public abstract char getCustomDelimiter(); /** * Get the character that defines comment lines - * @return the comment line starting character. If no comments are allowed in this - * file, then Character.UNASSIGNED constant must be returned; + * + * @return the comment line starting character. If no comments are allowed in this file, then + * Character.UNASSIGNED constant must be returned; * */ public abstract char getCommentChar(); /** * Get custom text qualifier to use as a text qualifier in the data + * * @return the text qualifier character to use as a text qualifier in the data */ public abstract char getTextQualifier(); /** * check if the text qualifier has to be use for all fields or not + * * @return true if the text qualifier is to be used for all data fields */ public abstract boolean useQualifier(); /** * Get the delimiter used to separate different values in a same csv cell + * * @return the delimiter used to separate values */ public abstract String getInCellDelimiter(); - + /** * Get the pattern to identify a column header where values can be splitted with the inCellDelimiter * and displayed in a table instead of a textfield + * * @return the regex */ public abstract String getRegexTableMarker(); @@ -104,14 +120,14 @@ public AbstractCSVFile() { /** * @param text */ - public void setInput(String text) { + public void setInput(final String text) { readLines(text); } /** * @param display */ - public void displayFirstLine(boolean display) { + public void displayFirstLine(final boolean display) { displayFirstLine = display; } @@ -119,14 +135,13 @@ public void displayFirstLine(boolean display) { * @param reader * @return */ - protected CsvReader initializeReader (Reader reader) - { - CsvReader csvReader = new CsvReader(reader); + protected CsvReader initializeReader(final Reader reader) { + final CsvReader csvReader = new CsvReader(reader); - char customDelimiter = getCustomDelimiter(); + final char customDelimiter = getCustomDelimiter(); csvReader.setDelimiter(customDelimiter); - char commentChar = getCommentChar(); + final char commentChar = getCommentChar(); if (commentChar != Character.UNASSIGNED) { csvReader.setComment(commentChar); // prevent loss of comment in csv source file @@ -142,28 +157,31 @@ protected CsvReader initializeReader (Reader reader) /** * @param fileText */ - protected void readLines(String fileText) { + protected void readLines(final String fileText) { rows.clear(); try { - CsvReader csvReader = initializeReader(new StringReader(fileText)); + final CsvReader csvReader = initializeReader(new StringReader(fileText)); // case when the first line is the encoding if (!displayFirstLine) { csvReader.skipLine(); } boolean setHeader = false; + if (isFirstLineHeader()) { + csvReader.setDelimiter(getCustomHeaderDelimiter()); + } while (csvReader.readRecord()) { - String[] rowValues = csvReader.getValues(); - CSVRow csvRow = new CSVRow(rowValues, this); + final String[] rowValues = csvReader.getValues(); + final CSVRow csvRow = new CSVRow(rowValues, this); if (!rowValues[0].startsWith(String.valueOf(getCommentChar()))) { if (isFirstLineHeader() && !setHeader) { setHeader = true; csvRow.setHeader(true); populateHeaders(rowValues); + csvReader.setDelimiter(getCustomDelimiter()); } - } - else { + } else { csvRow.setCommentLine(true); } rows.add(csvRow); @@ -178,7 +196,7 @@ protected void readLines(String fileText) { } csvReader.close(); - } catch (Exception e) { + } catch (final Exception e) { System.out.println("exception in readLines " + e); e.printStackTrace(); } @@ -190,17 +208,15 @@ protected void readLines(String fileText) { /** * @param entries */ - private void populateHeaders (String[] entries) { + private void populateHeaders(final String[] entries) { header.clear(); if (entries != null) { - for (String entry : entries) { - header.add(entry); - } + Collections.addAll(header, entries); -/* for (int i = header.size(); i < nbOfColumns; i++) { - header.add(""); - }*/ + /* + * for (int i = header.size(); i < nbOfColumns; i++) { header.add(""); } + */ } else { for (int i = 1; i < nbOfColumns + 1; i++) { header.add("Column" + i); @@ -218,7 +234,7 @@ public ArrayList getHeader() { /** * @return */ - public String[] getArrayHeader () { + public String[] getArrayHeader() { return header.toArray(new String[header.size()]); } @@ -228,42 +244,40 @@ public String[] getArrayHeader () { /** * */ - public void addRow () { - CSVRow row = CSVRow.createEmptyLine(nbOfColumns, this); + public void addRow() { + final CSVRow row = CSVRow.createEmptyLine(nbOfColumns, this); addRow(row); } /** * @param row */ - public void addRow (CSVRow row) { + public void addRow(final CSVRow row) { rows.add(row); } /** * @param row */ - public void addRowAfterElement (CSVRow row) { - CSVRow newRow = CSVRow.createEmptyLine(nbOfColumns, this); - int indexRow = findRow(row); + public void addRowAfterElement(final CSVRow row) { + final CSVRow newRow = CSVRow.createEmptyLine(nbOfColumns, this); + final int indexRow = findRow(row); if (indexRow != -1) { rows.add(indexRow, newRow); - } - else { + } else { addRow(newRow); } } - + /** * @param row */ - public void duplicateRow (CSVRow row) { - CSVRow newRow = new CSVRow(row, this); - int indexRow = findRow(row); + public void duplicateRow(final CSVRow row) { + final CSVRow newRow = new CSVRow(row, this); + final int indexRow = findRow(row); if (indexRow != -1) { rows.add(indexRow, newRow); - } - else { + } else { addRow(newRow); } } @@ -272,9 +286,9 @@ public void duplicateRow (CSVRow row) { * @param row * @return */ - public int findRow (CSVRow findRow) { + public int findRow(final CSVRow findRow) { for (int i = 0; i <= getArrayRows(true).length; i++) { - CSVRow row = getRowAt(i); + final CSVRow row = getRowAt(i); if (row.equals(findRow)) { return i; } @@ -292,10 +306,10 @@ public List getRows() { /** * @return */ - public Object[] getArrayRows (boolean includeCommentLine) { + public Object[] getArrayRows(final boolean includeCommentLine) { // filter header and comment rows - ArrayList myrows = new ArrayList(); - for (CSVRow row : rows) { + final ArrayList myrows = new ArrayList<>(); + for (final CSVRow row : rows) { // should we return the comment line if (row.isCommentLine()) { if (includeCommentLine) { @@ -314,36 +328,37 @@ else if (!row.isHeader()) { * @param index * @return */ - public CSVRow getRowAt (int index) { + public CSVRow getRowAt(final int index) { return rows.get(index); } /** - * @see org.fhsolution.eclipse.plugins.csvedit.model.IRowChangesListener#rowChanged(org.fhsolution.eclipse.plugins.csvedit.model.CSVRow, int) + * @see me.glindholm.plugin.csvedit2.model.IRowChangesListener#rowChanged(me.glindholm.plugin.csvedit2.model.CSVRow, + * int) */ - public void rowChanged (CSVRow row, int rowIndex) { - for (ICsvFileModelListener l : listeners) { - ((ICsvFileModelListener) l).entryChanged(row, rowIndex); + @Override + public void rowChanged(final CSVRow row, final int rowIndex) { + for (final ICsvFileModelListener l : listeners) { + l.entryChanged(row, rowIndex); } } /** * @param rowIndex */ - public void removeRow (int rowIndex) { + public void removeRow(final int rowIndex) { rows.remove(rowIndex); } /** * */ - public void removeRow (CSVRow row) { + public void removeRow(final CSVRow row) { if (!rows.remove(row)) { // TODO return error message } } - // ---------------------------------- // Helper method on column management // ---------------------------------- @@ -351,10 +366,10 @@ public void removeRow (CSVRow row) { /** * @param colName */ - public void addColumn (String colName) { + public void addColumn(final String colName) { nbOfColumns++; header.add(colName); - for (CSVRow row : rows) { + for (final CSVRow row : rows) { row.addElement(""); } } @@ -371,14 +386,14 @@ public int getColumnCount() { * * @param colIndex */ - public void removeColumn (int colIndex) { + public void removeColumn(final int colIndex) { if (isFirstLineHeader()) { header.remove(colIndex); nbOfColumns--; } - for (CSVRow row : rows) { + for (final CSVRow row : rows) { if (!row.isCommentLine()) { - System.out.println("remove elmt:["+colIndex+"] in row [" + row +"]"); + System.out.println("remove elmt:[" + colIndex + "] in row [" + row + "]"); row.removeElementAt(colIndex); } } @@ -389,38 +404,39 @@ public void removeColumn (int colIndex) { * * @param colIndex */ - public void removeColumn (String columnName) { + public void removeColumn(final String columnName) { if (columnName == null) { return; } - int colIndex = header.indexOf(columnName); + final int colIndex = header.indexOf(columnName); removeColumn(colIndex); } /** * @param csvFileListener */ - public void removeModelListener (ICsvFileModelListener csvFileListener) { + public void removeModelListener(final ICsvFileModelListener csvFileListener) { listeners.remove(csvFileListener); } /** * @param csvFileListener */ - public void addModelListener (ICsvFileModelListener csvFileListener) { - if (!listeners.contains(csvFileListener)) + public void addModelListener(final ICsvFileModelListener csvFileListener) { + if (!listeners.contains(csvFileListener)) { listeners.add(csvFileListener); + } } /** * Initialize the CsvWriter + * * @param writer * @return */ - protected CsvWriter initializeWriter (Writer writer) - { - char delimiter = getCustomDelimiter(); - CsvWriter csvWriter = new CsvWriter(writer, delimiter); + protected CsvWriter initializeWriter(final Writer writer) { + final char delimiter = getCustomDelimiter(); + final CsvWriter csvWriter = new CsvWriter(writer, delimiter); csvWriter.setTextQualifier(getTextQualifier()); csvWriter.setForceQualifier(useQualifier()); csvWriter.setComment(getCommentChar()); @@ -430,32 +446,27 @@ protected CsvWriter initializeWriter (Writer writer) /** * @return */ - public String getTextRepresentation () { + public String getTextRepresentation() { - StringWriter sw = new StringWriter(); + final StringWriter sw = new StringWriter(); try { - CsvWriter clw = initializeWriter(sw); + final CsvWriter clw = initializeWriter(sw); /* - if (isFirstLineHeader() && header.size() > 0) { - String[] headerArray = new String[header.size()]; - for (int i=0; i 0) { String[] headerArray = new String[header.size()]; + * for (int i=0; i line, IRowChangesListener listener) { - entries = new ArrayList(line); + public CSVRow(final List line, final IRowChangesListener listener) { + entries = new ArrayList<>(line); this.listener = listener; } /** * Constructor + * * @param row * @param listener */ - public CSVRow(CSVRow row, IRowChangesListener listener){ - - this.entries = (ArrayList)row.entries.clone(); - this.listener = listener; - this.isCommentLine = row.isCommentLine; - this.isHeader = row.isHeader; - } - + public CSVRow(final CSVRow row, final IRowChangesListener listener) { + + entries = new ArrayList<>(row.getEntries()); + this.listener = listener; + isCommentLine = row.isCommentLine; + isHeader = row.isHeader; + } + /** * Constructor + * * @param lineElements * @param listener */ - public CSVRow(String[] lineElements, IRowChangesListener listener) { + public CSVRow(final String[] lineElements, final IRowChangesListener listener) { this(Arrays.asList(lineElements), listener); } /** * Create an empty row + * * @param nbOfColumns * @param delimiter * @param listener * @return */ - public static CSVRow createEmptyLine (int nbOfColumns, IRowChangesListener listener) { - List line = new LinkedList(); - for (int i=0; i line = new LinkedList<>(); + for (int i = 0; i < nbOfColumns; i++) { line.add(""); } return new CSVRow(line, listener); @@ -89,14 +94,14 @@ public static CSVRow createEmptyLine (int nbOfColumns, IRowChangesListener liste /** * @return */ - public ArrayList getEntries () { + public ArrayList getEntries() { return entries; } /** * @return */ - public String[] getEntriesAsArray () { + public String[] getEntriesAsArray() { return entries.toArray(new String[entries.size()]); } @@ -104,22 +109,22 @@ public String[] getEntriesAsArray () { * @param elementIndex * @param elementString */ - public void setRowEntry (int elementIndex, String elementString) { - if (entries.get(elementIndex).compareTo(elementString) != 0) { + public void setRowEntry(final int elementIndex, final String elementString) { + String entry = entries.get(elementIndex); + if (entry != null && entry.compareTo(elementString) != 0) { entries.set(elementIndex, elementString); listener.rowChanged(this, elementIndex); } } /** - * return the element at a given index. - * This method makes sure that if the current line does not have as many - * elements as the header, it will not break and return an empty string + * return the element at a given index. This method makes sure that if the current line does not + * have as many elements as the header, it will not break and return an empty string * * @param index * @return the element at a given index */ - public String getElementAt (int index) { + public String getElementAt(final int index) { if (index >= entries.size()) { return ""; } @@ -128,16 +133,17 @@ public String getElementAt (int index) { /** * Return the number of elements in this row + * * @return number of elements in this row */ - public int getNumberOfElements () { + public int getNumberOfElements() { return entries.size(); } /** * @param element */ - public void addElement(String element) { + public void addElement(final String element) { entries.add(element); } @@ -146,27 +152,27 @@ public void addElement(String element) { * * @param index */ - public void removeElementAt (int index) { + public void removeElementAt(final int index) { entries.remove(index); } - public void setCommentLine (boolean comment) { + public void setCommentLine(final boolean comment) { isCommentLine = comment; } - public boolean isCommentLine () { + public boolean isCommentLine() { return isCommentLine; } - public void setHeader (boolean header) { + public void setHeader(final boolean header) { isHeader = header; } - public boolean isHeader () { + public boolean isHeader() { return isHeader; } - public String getComment () { + public String getComment() { return entries.get(0).substring(1); } @@ -175,9 +181,10 @@ public String getComment () { * * @see java.lang.Object#toString() */ - public String toString () { + @Override + public String toString() { String result = ""; - for (String s:entries) { + for (final String s : entries) { // FIXME get preferences here result = result.concat(s).concat(","); } @@ -189,10 +196,7 @@ public String toString () { */ @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((entries == null) ? 0 : entries.hashCode()); - return result; + return Objects.hash(entries); } /** @@ -200,26 +204,24 @@ public int hashCode() { * * @see java.lang.Object#equals(java.lang.Object) */ - @Override - public boolean equals(Object anObject) { - - // The commented lines implies that if two rows have the same content, - // the cell editor will modify - // the first one found instead of the focused one - // each row should be considered as unique even if they have the same content - - /* - * AttributeRow thisRow = (AttributeRow) anObject; for (int i=0; - * i selectedColumn; + private final String[] columnTitle; + private final ArrayList selectedColumn; /** * @param parentShell * @param columns */ - public DeleteColumnPage ( - Shell parentShell, - String[] columns) { + public DeleteColumnPage(final Shell parentShell, final String[] columns) { super(parentShell); - this.columnTitle = columns; - this.selectedColumn = new ArrayList(columnTitle.length); + columnTitle = columns; + selectedColumn = new ArrayList<>(columnTitle.length); } - /** * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ - protected Control createDialogArea (Composite parent) { - Composite container = (Composite) super.createDialogArea(parent); + @Override + protected Control createDialogArea(final Composite parent) { + final Composite container = (Composite) super.createDialogArea(parent); final GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; container.setLayout(gridLayout); final Label filterLabel = new Label(container, SWT.NONE); - filterLabel.setLayoutData(new GridData(GridData.BEGINNING, - GridData.BEGINNING, false, false, 2, 1)); + filterLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false, 2, 1)); filterLabel.setText("Select the column that you want to delete:"); final Label nameLabel = new Label(container, SWT.NONE); - nameLabel.setLayoutData(new GridData(GridData.END, - GridData.CENTER, false, false)); + nameLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); nameLabel.setText("Column:"); final List columnList = new List(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); columnList.setBounds(40, 20, 220, 100); columnList.setItems(columnTitle); - columnList.addSelectionListener( - new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - selectedColumn.clear(); - selectedColumn.addAll(Arrays.asList(columnList.getSelection())); - }}); + columnList.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + selectedColumn.clear(); + selectedColumn.addAll(Arrays.asList(columnList.getSelection())); + } + }); return container; } @@ -87,14 +84,15 @@ public void widgetSelected (SelectionEvent e) { /** * @return */ - public String[] getColumnSelected () { + public String[] getColumnSelected() { return selectedColumn.toArray(new String[selectedColumn.size()]); } /** * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ - protected void configureShell (Shell newShell) { + @Override + protected void configureShell(final Shell newShell) { super.configureShell(newShell); newShell.setText("Delete Column"); } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/page/InsertColumnPage.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/page/InsertColumnPage.java similarity index 55% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/page/InsertColumnPage.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/page/InsertColumnPage.java index 0ef6c95..0cbe68b 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/page/InsertColumnPage.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/page/InsertColumnPage.java @@ -12,14 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.page; +package me.glindholm.plugin.csvedit2.page; import java.util.ArrayList; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -35,61 +33,50 @@ */ public class InsertColumnPage extends Dialog { - private String[] columnTitle; + private final String[] columnTitle; private String newColumnName; - private ArrayList selectedColumn; + private final ArrayList selectedColumn; /** * @param parentShell * @param columns */ - public InsertColumnPage ( - Shell parentShell, - String[] columns) { + public InsertColumnPage(final Shell parentShell, final String[] columns) { super(parentShell); - this.columnTitle = columns; - this.newColumnName = ""; - this.selectedColumn = new ArrayList(columnTitle.length); + columnTitle = columns; + newColumnName = ""; + selectedColumn = new ArrayList<>(columnTitle.length); } - - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) */ - protected Control createDialogArea (Composite parent) { - Composite container = (Composite) super.createDialogArea(parent); + @Override + protected Control createDialogArea(final Composite parent) { + final Composite container = (Composite) super.createDialogArea(parent); final GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; container.setLayout(gridLayout); /* - final Label nameLabel = new Label(container, SWT.NONE); - nameLabel.setLayoutData(new GridData(GridData.END, - GridData.CENTER, false, false)); - nameLabel.setText("Column:"); - - final List columnList = new List(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); - columnList.setBounds(40, 20, 220, 100); - columnList.setItems(columnTitle); - - columnList.addSelectionListener( - new SelectionAdapter() { - public void widgetSelected (SelectionEvent e) { - selectedColumn.clear(); - selectedColumn.addAll(Arrays.asList(columnList.getSelection())); - }}); - */ + * final Label nameLabel = new Label(container, SWT.NONE); nameLabel.setLayoutData(new + * GridData(GridData.END, GridData.CENTER, false, false)); nameLabel.setText("Column:"); + * + * final List columnList = new List(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | + * SWT.MULTI); columnList.setBounds(40, 20, 220, 100); columnList.setItems(columnTitle); + * + * columnList.addSelectionListener( new SelectionAdapter() { public void widgetSelected + * (SelectionEvent e) { selectedColumn.clear(); + * selectedColumn.addAll(Arrays.asList(columnList.getSelection())); }}); + */ final Label filterLabel = new Label(container, SWT.NONE); - filterLabel.setLayoutData(new GridData(GridData.BEGINNING, - GridData.BEGINNING, false, false, 2, 1)); + filterLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false, 2, 1)); filterLabel.setText("Please Give the name of the new column to be created"); final Text newColumnNameField = new Text(container, SWT.BORDER); newColumnNameField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - newColumnNameField.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - newColumnName = newColumnNameField.getText(); - } - }); + newColumnNameField.addModifyListener(e -> newColumnName = newColumnNameField.getText()); return container; } @@ -97,21 +84,24 @@ public void modifyText(ModifyEvent e) { /** * @return */ - public String getColumnNewName () { + public String getColumnNewName() { return newColumnName; } /** * @return */ - public String[] getColumnSelected () { + public String[] getColumnSelected() { return selectedColumn.toArray(new String[selectedColumn.size()]); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) */ - protected void configureShell (Shell newShell) { + @Override + protected void configureShell(final Shell newShell) { super.configureShell(newShell); newShell.setText("Insert Column"); } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/providers/CSVContentProvider.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/providers/CSVContentProvider.java similarity index 72% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/providers/CSVContentProvider.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/providers/CSVContentProvider.java index b4653a8..1339654 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/providers/CSVContentProvider.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/providers/CSVContentProvider.java @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.providers; +package me.glindholm.plugin.csvedit2.providers; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; -import org.fhsolution.eclipse.plugins.csvedit.model.AbstractCSVFile; + +import me.glindholm.plugin.csvedit2.model.AbstractCSVFile; /** * @@ -30,10 +31,10 @@ public class CSVContentProvider implements IStructuredContentProvider { * * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) */ - public Object[] getElements(Object element) { + @Override + public Object[] getElements(final Object element) { - if(element instanceof AbstractCSVFile) { - AbstractCSVFile model = (AbstractCSVFile) element; + if (element instanceof final AbstractCSVFile model) { return model.getArrayRows(false); } return null; @@ -42,15 +43,18 @@ public Object[] getElements(Object element) { /** * @see org.eclipse.jface.viewers.IContentProvider#dispose() */ + @Override public void dispose() { } /** - * Notifies this content provider that the given viewer's input - * has been switched to a different element. + * Notifies this content provider that the given viewer's input has been switched to a different + * element. * - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, + * java.lang.Object, java.lang.Object) */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + @Override + public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { } } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/providers/CSVLabelProvider.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/providers/CSVLabelProvider.java similarity index 63% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/providers/CSVLabelProvider.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/providers/CSVLabelProvider.java index e85b72a..4c3f967 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/providers/CSVLabelProvider.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/providers/CSVLabelProvider.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.providers; +package me.glindholm.plugin.csvedit2.providers; import java.util.ArrayList; import java.util.List; @@ -25,8 +25,9 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; -import org.fhsolution.eclipse.plugins.csvedit.model.CSVRow; -import org.fhsolution.eclipse.plugins.csvedit.style.SearchResultStyle; + +import me.glindholm.plugin.csvedit2.model.CSVRow; +import me.glindholm.plugin.csvedit2.style.SearchResultStyle; /** * @@ -34,15 +35,15 @@ * */ public class CSVLabelProvider extends StyledCellLabelProvider { -//implements ITableLabelProvider + //implements ITableLabelProvider private String searchText; - private Color searchColor; + private final Color searchColor; /** * */ - public CSVLabelProvider () { + public CSVLabelProvider() { searchColor = Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW); } @@ -51,7 +52,7 @@ public CSVLabelProvider () { * @param columnIndex * @return */ - public Image getColumnImage(Object element, int columnIndex) { + public Image getColumnImage(final Object element, final int columnIndex) { return null; } @@ -60,11 +61,12 @@ public Image getColumnImage(Object element, int columnIndex) { * @param columnIndex * @return */ - public String getColumnText(Object element, int columnIndex) { - CSVRow row = (CSVRow) element; + public String getColumnText(final Object element, final int columnIndex) { + final CSVRow row = (CSVRow) element; - if(row.getEntries().size() > columnIndex) { - return row.getEntries().get(columnIndex).toString(); + if (row.getEntries().size() > columnIndex) { + final String entry = row.getEntries().get(columnIndex); + return entry != null ? entry.toString() : ""; } return ""; @@ -73,57 +75,61 @@ public String getColumnText(Object element, int columnIndex) { /** * @see org.eclipse.jface.viewers.BaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) */ - public void addListener(ILabelProviderListener listener) { + @Override + public void addListener(final ILabelProviderListener listener) { } /** - * @see org.eclipse.jface.viewers.BaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) + * @see org.eclipse.jface.viewers.BaseLabelProvider#isLabelProperty(java.lang.Object, + * java.lang.String) */ - public boolean isLabelProperty(Object element, String property) { + @Override + public boolean isLabelProperty(final Object element, final String property) { return true; } /** * @see org.eclipse.jface.viewers.BaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) */ - public void removeListener(ILabelProviderListener listener) { + @Override + public void removeListener(final ILabelProviderListener listener) { } /** * @param searchText */ - public void setSearchText(String searchText) { + public void setSearchText(final String searchText) { this.searchText = searchText; } /** * @see org.eclipse.jface.viewers.StyledCellLabelProvider#dispose() */ + @Override public void dispose() { + super.dispose(); } /** * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell) */ @Override - public void update(ViewerCell cell) { - CSVRow element = (CSVRow) cell.getElement(); - int index = cell.getColumnIndex(); - String columnText = getColumnText(element, index); + public void update(final ViewerCell cell) { + final CSVRow element = (CSVRow) cell.getElement(); + final int index = cell.getColumnIndex(); + final String columnText = getColumnText(element, index); cell.setText(columnText); cell.setImage(getColumnImage(element, index)); if (searchText != null && searchText.length() > 0) { - int intRangesCorrectSize[] = - SearchResultStyle.getSearchTermOccurrences(searchText, columnText); - List styleRange = new ArrayList(); + final int intRangesCorrectSize[] = SearchResultStyle.getSearchTermOccurrences(searchText, columnText); + final List styleRange = new ArrayList<>(); for (int i = 0; i < intRangesCorrectSize.length / 2; i++) { - StyleRange myStyleRange = new StyleRange(0, 0, null, searchColor); + final StyleRange myStyleRange = new StyleRange(0, 0, null, searchColor); myStyleRange.start = intRangesCorrectSize[i]; myStyleRange.length = intRangesCorrectSize[++i]; styleRange.add(myStyleRange); } - cell.setStyleRanges(styleRange.toArray(new StyleRange[styleRange - .size()])); + cell.setStyleRanges(styleRange.toArray(new StyleRange[styleRange.size()])); } else { cell.setStyleRanges(null); } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/sorter/CSVTableSorter.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/sorter/CSVTableSorter.java similarity index 64% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/sorter/CSVTableSorter.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/sorter/CSVTableSorter.java index 0287481..e9f8e92 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/sorter/CSVTableSorter.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/sorter/CSVTableSorter.java @@ -12,19 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.sorter; +package me.glindholm.plugin.csvedit2.sorter; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.swt.SWT; -import org.fhsolution.eclipse.plugins.csvedit.model.CSVRow; + +import me.glindholm.plugin.csvedit2.model.CSVRow; /** * * @author fhenri * */ -public class CSVTableSorter extends ViewerSorter { +public class CSVTableSorter extends ViewerComparator { private int propertyIndex; private static final int DESCENDING = 1; @@ -38,7 +39,7 @@ public class CSVTableSorter extends ViewerSorter { * Public Constructor */ public CSVTableSorter() { - this.propertyIndex = -1; + propertyIndex = -1; direction = DESCENDING; } @@ -47,29 +48,32 @@ public CSVTableSorter() { * * @param column columnId selected by the user. */ - public void setColumn(int column, int dir) { + public void setColumn(final int column, final int dir) { if (dir == SWT.NONE) { noSort = true; return; } noSort = false; - if (column != this.propertyIndex) { + if (column != propertyIndex) { // New column; do an ascending sort - this.propertyIndex = column; + propertyIndex = column; } - this.direction = dir == SWT.UP ? ASCENDING : DESCENDING; + direction = dir == SWT.UP ? ASCENDING : DESCENDING; } /** - * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, + * java.lang.Object, java.lang.Object) */ @Override - public int compare(Viewer viewer, Object e1, Object e2) { + public int compare(final Viewer viewer, final Object e1, final Object e2) { // this is necessary at opening of csv file so column are not sorted. - if (propertyIndex == -1 || noSort) return 0; + if (propertyIndex == -1 || noSort) { + return 0; + } - String row1 = ((CSVRow) e1).getElementAt(propertyIndex); - String row2 = ((CSVRow) e2).getElementAt(propertyIndex); + final String row1 = nvl(((CSVRow) e1).getElementAt(propertyIndex)); + final String row2 = nvl(((CSVRow) e2).getElementAt(propertyIndex)); int rc = row1.compareTo(row2); @@ -79,4 +83,8 @@ public int compare(Viewer viewer, Object e1, Object e2) { } return rc; } + + private static final String nvl(final String string) { + return string != null ? string : ""; + } } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/style/SearchResultStyle.java b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/style/SearchResultStyle.java similarity index 59% rename from csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/style/SearchResultStyle.java rename to csvedit.plugin/src/me/glindholm/plugin/csvedit2/style/SearchResultStyle.java index e8b4a3a..e972bac 100644 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/style/SearchResultStyle.java +++ b/csvedit.plugin/src/me/glindholm/plugin/csvedit2/style/SearchResultStyle.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.fhsolution.eclipse.plugins.csvedit.style; +package me.glindholm.plugin.csvedit2.style; import java.util.ArrayList; import java.util.List; @@ -33,19 +33,15 @@ public class SearchResultStyle { * @param content * @return */ - public static int[] getSearchTermOccurrences( - String searchTerm, - String content) - { + public static int[] getSearchTermOccurrences(final String searchTerm, final String content) { List styleRange; List ranges; - Display disp = Display.getCurrent(); - StyleRange myStyleRange = - new StyleRange(0, 0, null, disp.getSystemColor(SWT.COLOR_YELLOW)); + final Display disp = Display.getCurrent(); + final StyleRange myStyleRange = new StyleRange(0, 0, null, disp.getSystemColor(SWT.COLOR_YELLOW)); // reset the StyleRange-Array for each new field - styleRange = new ArrayList(); - ranges = new ArrayList(); // reset the ranges-array + styleRange = new ArrayList<>(); + ranges = new ArrayList<>(); // reset the ranges-array if (searchTerm.equals("")) { return new int[] {}; } @@ -53,9 +49,7 @@ public static int[] getSearchTermOccurrences( // determine all occurrences of the searchText and write the beginning // and length of each occurrence into an array for (int i = 0; i < content.length(); i++) { - if (i + searchTerm.length() <= content.length() - && content.substring(i, i + searchTerm.length()) - .equalsIgnoreCase(searchTerm)) { + if (i + searchTerm.length() <= content.length() && content.substring(i, i + searchTerm.length()).equalsIgnoreCase(searchTerm)) { // ranges format: n->start of the range, n+1->length of the // range ranges.add(i); @@ -64,22 +58,15 @@ public static int[] getSearchTermOccurrences( } // convert the list into an int[] and make sure that overlapping // search term occurrences are are merged - int[] intRanges = new int[ranges.size()]; + final int[] intRanges = new int[ranges.size()]; int arrayIndexCounter = 0; for (int listIndexCounter = 0; listIndexCounter < ranges.size(); listIndexCounter++) { if (listIndexCounter % 2 == 0) { - if (searchTerm.length() > 1 - && listIndexCounter != 0 - && ranges.get(listIndexCounter - 2) - + ranges.get(listIndexCounter - 1) >= ranges - .get(listIndexCounter)) { - intRanges[arrayIndexCounter - 1] = 0 - - ranges.get(listIndexCounter - 2) - + ranges.get(listIndexCounter) - + ranges.get(++listIndexCounter); + if (searchTerm.length() > 1 && listIndexCounter != 0 + && ranges.get(listIndexCounter - 2) + ranges.get(listIndexCounter - 1) >= ranges.get(listIndexCounter)) { + intRanges[arrayIndexCounter - 1] = 0 - ranges.get(listIndexCounter - 2) + ranges.get(listIndexCounter) + ranges.get(++listIndexCounter); } else { - intRanges[arrayIndexCounter++] = ranges - .get(listIndexCounter); + intRanges[arrayIndexCounter++] = ranges.get(listIndexCounter); } } else { intRanges[arrayIndexCounter++] = ranges.get(listIndexCounter); @@ -88,9 +75,8 @@ public static int[] getSearchTermOccurrences( } // if there have been any overlappings we need to reduce the size of // the array to avoid conflicts in the setStyleRanges method - int[] intRangesCorrectSize = new int[arrayIndexCounter]; - System.arraycopy(intRanges, 0, intRangesCorrectSize, 0, - arrayIndexCounter); + final int[] intRangesCorrectSize = new int[arrayIndexCounter]; + System.arraycopy(intRanges, 0, intRangesCorrectSize, 0, arrayIndexCounter); return intRangesCorrectSize; } diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/AttributeRow.java b/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/AttributeRow.java deleted file mode 100644 index c569832..0000000 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/AttributeRow.java +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright 2011 csvedit - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.fhsolution.eclipse.plugins.csvedit.detailededitor; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -/** - * Represents a row made of String elements for the detailed view - * @author fhenri - * @author msavy - * - */ -public class AttributeRow { - - /** Splitted line */ - private final ArrayList entries; - - /** Row changes listener */ - private final IAttributeChangesListener listener; - - /** - * Constructor - * - * @param line - * @param listener - */ - public AttributeRow(List line, IAttributeChangesListener listener) { - entries = new ArrayList(line); - this.listener = listener; - } - - /** - * Constructor - * - * @param lineElements - * @param listener - */ - public AttributeRow(String[] lineElements, - IAttributeChangesListener listener) { - this(Arrays.asList(lineElements), listener); - } - - /** - * Create an empty row - * - * @param nbOfColumns - * @param delimiter - * @param listener - * @return - */ - public static AttributeRow createEmptyLine(int nbOfColumns, - IAttributeChangesListener listener) { - List line = new LinkedList(); - for (int i = 0; i < nbOfColumns; i++) { - line.add(""); - } - return new AttributeRow(line, listener); - } - - /** - * @return - */ - public ArrayList getEntries() { - return entries; - } - - /** - * @return - */ - public String[] getEntriesAsArray() { - return entries.toArray(new String[entries.size()]); - } - - /** - * @param elementIndex - * @param elementString - */ - public void setRowEntry(int elementIndex, String elementString) { - if (entries.get(elementIndex).compareTo(elementString) != 0) { - entries.set(elementIndex, elementString); - listener.rowChanged(this, elementIndex); - } - } - - /** - * return the element at a given index. This method makes sure that if the - * current line does not have as many elements as the header, it will not - * break and return an empty string - * - * @param index - * @return the element at a given index - */ - public String getElementAt(int index) { - if (index >= entries.size()) { - return ""; - } - return entries.get(index); - } - - /** - * Return the number of elements in this row - * - * @return number of elements in this row - */ - public int getNumberOfElements() { - return entries.size(); - } - - /** - * @param element - */ - public void addElement(String element) { - entries.add(element); - } - - /** - * Remove an element of the row represented by its index - * - * @param index - */ - public void removeElementAt(int index) { - entries.remove(index); - } - - /** - * Give the String representation of a CSVRow object. - * - * @see java.lang.Object#toString() - */ - public String toString() { - String result = ""; - for (String s : entries) { - // FIXME get preferences here - result = result.concat(s).concat(","); - } - return result; - } - - /** - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((entries == null) ? 0 : entries.hashCode()); - return result; - } - - @Override - public boolean equals(Object anObject) { - // The commented lines implies that if two rows have the same content, - // the cell editor will modify - // the first one found instead of the focused one - // each row is unique - - /* - * //System.out.println("compare:\n[" + this + "] and\n[" + anObject + - * "]"); if (!(anObject instanceof AttributeRow)) { return false; } - * - * AttributeRow thisRow = (AttributeRow) anObject; for (int i=0; - * i model = new ArrayList(); - - IAttributeChangesListener listener = new IAttributeChangesListener() { - public void rowChanged(AttributeRow row, int index) { - tableViewer.refresh(); - } - }; - - /** - * Default constructor - * Add an empty TableViewer to a Composite view - */ - public DetailedAttributeTableViewer(Composite composite) { - - tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI); - Table table = tableViewer.getTable(); - table.setLinesVisible(true); - table.setHeaderVisible(true); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); - gd.minimumHeight = 100; - table.setLayoutData(gd); - } - - /** - * Fill the table - * @param headers - * @param content a List where each String[] is a column of the table - */ - public void fillTable(List headers, List content){ - - for (int i = 0; i < headers.size(); i++) { - final TableViewerColumn column = new TableViewerColumn(tableViewer, - SWT.LEFT); - - column.getColumn().setText(headers.get(i)); - column.getColumn().setWidth(200); - column.getColumn().setResizable(true); - column.getColumn().setMoveable(true); - - final int index = i; - - column.setLabelProvider(new ColumnLabelProvider() { - @Override - public String getText(Object element) { - return ((AttributeRow)element).getElementAt(index); - } - }); - } - - model = new ArrayList(); - - if(content.size() > 0){ - //We first look for the biggest column, it will be the reference to generate all AttributeRow - int biggestColumn = 0; - - for(int i = 0; i < content.size(); i++){ - if(content.get(biggestColumn).length < content.get(i).length){ - biggestColumn = i; - } - } - - //For each row of the biggest column (String[]), we look for the rows - //at the same level in other columns and we build a AttributeRow with those data - for(int i = 0; i < content.get(biggestColumn).length; i++){ - List attributes = new ArrayList(); - for(int j = 0; j < content.size(); j++){ - if(i < content.get(j).length){ - attributes.add(content.get(j)[i]); - } else { - attributes.add(""); - } - } - model.add(new AttributeRow(attributes, listener)); - } - } - - tableViewer.setContentProvider(new ArrayContentProvider()); - tableViewer.setInput(model); - - defineCellEditing(tableViewer, headers.size()); - addRightClickItems(tableViewer); - } - - /** - * Make cells of the tableViewer editable - */ - private void defineCellEditing(TableViewer tableViewer, int numberOfColumns) { - String[] columnProperties = new String[numberOfColumns]; - CellEditor[] cellEditors = new CellEditor[numberOfColumns]; - - for (int i = 0; i < numberOfColumns; i++) { - columnProperties[i] = Integer.toString(i); - cellEditors[i] = new TextCellEditor(tableViewer.getTable()); - } - - tableViewer.setColumnProperties(columnProperties); - - tableViewer.setCellEditors(cellEditors); - tableViewer.setCellModifier(new AttributeEditorCellModifier()); - - } - - /** - * Describe the behavior of right click on the tableViewer - */ - private void addRightClickItems(final TableViewer tableViewer){ - - // create menu item to delete column - final Menu tableHeaderMenu = new Menu(tableViewer.getTable()); - - // create menu item to insert column - final MenuItem insertColumnItem = new MenuItem(tableHeaderMenu, - SWT.PUSH); - insertColumnItem.setText("Add row"); - insertColumnItem.setSelection(false); - insertColumnItem.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - // call insert/add column page - AttributeRow row = (AttributeRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); - - IAttributeChangesListener listener = new IAttributeChangesListener() { - public void rowChanged(AttributeRow row, int index) { - // TODO Auto-generated method stub - tableViewer.refresh(); - } - }; - - List emptyAttributes = new ArrayList(); - for(int i = 0; i < tableViewer.getTable().getColumnCount(); i++){ - emptyAttributes.add("#TO_FILL#"); - } - - AttributeRow emptyRow = new AttributeRow(emptyAttributes, listener); - - if (row != null) { - model.add(model.indexOf(row) + 1, emptyRow); - } else { - model.add(emptyRow); - } - - tableViewer.refresh(); - } - }); - - final MenuItem deleteColumnItem = new MenuItem(tableHeaderMenu, - SWT.PUSH); - deleteColumnItem.setText("Delete Row"); - deleteColumnItem.setSelection(false); - deleteColumnItem.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - - AttributeRow row = (AttributeRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); - - while(row != null){ - row = (AttributeRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); - if (row != null) { - model.remove(model.indexOf(row)); - tableViewer.refresh(); - } - } - } - }); - - //Link to the tableViewer - tableViewer.getTable().addListener(SWT.MenuDetect, new Listener() { - public void handleEvent(Event event) { - tableViewer.getTable().setMenu(tableHeaderMenu); - tableViewer.refresh(); - } - }); - } - - public TableViewer getTableViewer() { - return tableViewer; - } - - public void setTableViewer(TableViewer tableViewer) { - this.tableViewer = tableViewer; - } - - public List getModel() { - return model; - } - - public void setModele(List model) { - this.model = model; - } -} diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/DetailedEditor.java b/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/DetailedEditor.java deleted file mode 100644 index 515a38f..0000000 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/detailededitor/DetailedEditor.java +++ /dev/null @@ -1,253 +0,0 @@ -/* Copyright 2011 csvedit - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.fhsolution.eclipse.plugins.csvedit.detailededitor; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.fhsolution.eclipse.plugins.csvedit.model.CSVRow; - -/** - * Class providing methods to add a custom tableViewer to a Composite - * @author msavy - * - */ -public class DetailedEditor { - - Shell shell; - protected List componentList = new ArrayList(); - - protected CSVRow row; // The row to modify - protected List headerList; // A list of the headers for each column - // of the row - - protected String inCellDelimiter; - protected String regexTableMarker; - - final static String UNKNOWN_URL_FORMAT = "_UNKNOWN_URL_FORMAT:"; - - public Shell getShell() { - return shell; - } - - public void setShell(Shell shell) { - this.shell = shell; - } - - /** - * Default constructor, open a new window - * - */ - public DetailedEditor(final Display display, final List headerList, - final CSVRow row, String inCellDelimiter, String regexTableMarker) { - - shell = new Shell(display); - shell.setLayout(new FillLayout()); - shell.setText("Detailed CSV edition"); - - shell.setSize(800, 600); - - // If there is more columns for the header than there is for the column, - // we had empty columns in the row - // It happen when the row's last columns are empty and separators are - // forgotten. - // The CSV reader can't guess there is a column to create - if (row.getNumberOfElements() > 0 - && headerList.size() > row.getNumberOfElements()) { - for (int i = row.getNumberOfElements() - 1; i < headerList.size(); i++) { - row.addElement(""); - } - } - - this.headerList = headerList; - this.row = row; - - this.inCellDelimiter = inCellDelimiter; - this.regexTableMarker = regexTableMarker; - - ScrolledComposite scrolledComposite = new ScrolledComposite(shell, - SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); - scrolledComposite.setExpandHorizontal(true); - scrolledComposite.setExpandVertical(true); - - Composite composite = new Composite(scrolledComposite, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - - generateComponents(composite); - new Label(composite, SWT.NONE); - - Composite compositeBtn = new Composite(composite, SWT.NONE); - GridData gd_compositeBtn = new GridData(SWT.LEFT, SWT.CENTER, false, - false, 1, 1); - gd_compositeBtn.heightHint = 55; - gd_compositeBtn.widthHint = 220; - compositeBtn.setLayoutData(gd_compositeBtn); - - Button btnApply = new Button(compositeBtn, SWT.NONE); - btnApply.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - } - }); - btnApply.setBounds(19, 14, 75, 30); - btnApply.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - switch (e.type) { - case SWT.Selection: - updateRow(); - shell.dispose(); - break; - } - } - }); - btnApply.setText("Apply"); - - Button btnCancel = new Button(compositeBtn, SWT.NONE); - btnCancel.setBounds(141, 14, 75, 30); - btnCancel.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { - switch (e.type) { - case SWT.Selection: - shell.dispose(); - break; - } - } - }); - btnCancel.setText("Cancel"); - - shell.setMinimumSize(400, 200); - - scrolledComposite.setContent(composite); - scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT, - SWT.DEFAULT)); - - // The components must be filled only after the scrolled composite size - // has been set - // Otherwise the size of the scrolled composite would adapt its size to - // the content of its components - fillComponents(); - } - - /** - * Generates components of the DetailedView depending of their type - * - */ - private void generateComponents(Composite composite) { - - for (int i = 0; i < headerList.size() && !headerList.get(i).equals(""); i++) { - - Label label = new Label(composite, SWT.NONE); - label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - - if (headerList.get(i).matches(regexTableMarker)) { - DetailedAttributeTableViewer tableViewer = new DetailedAttributeTableViewer(composite); - componentList.add(tableViewer); - - } else { - label.setText(headerList.get(i)); - - Text text = new Text(composite, SWT.BORDER); - text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - componentList.add(text); - } - } - } - - /** - * Fills components according to data provided by the field attribute "row" - * - */ - private void fillComponents() { - - for (int i = 0; i < componentList.size(); i++) { - - // Fill text components - if (componentList.get(i) instanceof Text) { - ((Text) componentList.get(i)).setText(row.getElementAt(i)); - - // Fill table viewer components - } else if (componentList.get(i) instanceof DetailedAttributeTableViewer) { - - List headers = new ArrayList(); - headers.add(headerList.get(i)); - - String column1[] = row.getElementAt(i).split("[^|]\\|[^|]"); - for (int j = 0; j < column1.length; j++) { - column1[j] = column1[j].trim(); - } - - List content = new ArrayList(); - if (!(column1.length == 1 && column1[0].equals(""))) - content.add(column1); - ((DetailedAttributeTableViewer) componentList.get(i)).fillTable(headers, content); - } - } - } - - private void updateRow() { - - for (int i = 0; i < headerList.size() && !headerList.get(i).equals(""); i++) { - - if (componentList.get(i) instanceof Text) { - row.setRowEntry(i, ((Text) componentList.get(i)).getText()); - - // if update source is a table viewer - } else if (componentList.get(i) instanceof DetailedAttributeTableViewer) { - - List model = ((DetailedAttributeTableViewer) componentList - .get(i)).getModel(); - StringBuilder updatedStr = new StringBuilder(); - - for (AttributeRow atts : model) { - - if (atts.getElementAt(0).equals("")) { - continue; - } - - updatedStr.append(atts.getElementAt(0).trim()); - updatedStr.append(" | "); - } - - String finalStr = updatedStr.toString(); - if (finalStr.length() > 0 - && (finalStr.substring(finalStr.length() - 3, finalStr.length()).equals(" | "))) { - finalStr = finalStr.substring(0, finalStr.length() - 3); - } - - row.setRowEntry(i, finalStr); - } - } - } - - public void open() { - shell.open(); - } -} \ No newline at end of file diff --git a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/MultiPageCSVEditor.java b/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/MultiPageCSVEditor.java deleted file mode 100644 index e233cc1..0000000 --- a/csvedit.plugin/src/org/fhsolution/eclipse/plugins/csvedit/editors/MultiPageCSVEditor.java +++ /dev/null @@ -1,875 +0,0 @@ -/* Copyright 2011 csvedit - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.fhsolution.eclipse.plugins.csvedit.editors; - -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.CellLabelProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.TextCellEditor; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.editors.text.TextEditor; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.part.MultiPageEditorPart; -import org.fhsolution.eclipse.plugins.csvedit.detailededitor.DetailedEditor; -import org.fhsolution.eclipse.plugins.csvedit.editors.text.CSVTextEditor; -import org.fhsolution.eclipse.plugins.csvedit.filter.CSVTableFilter; -import org.fhsolution.eclipse.plugins.csvedit.model.AbstractCSVFile; -import org.fhsolution.eclipse.plugins.csvedit.model.CSVRow; -import org.fhsolution.eclipse.plugins.csvedit.model.ICsvFileModelListener; -import org.fhsolution.eclipse.plugins.csvedit.page.DeleteColumnPage; -import org.fhsolution.eclipse.plugins.csvedit.page.InsertColumnPage; -import org.fhsolution.eclipse.plugins.csvedit.providers.CSVContentProvider; -import org.fhsolution.eclipse.plugins.csvedit.providers.CSVLabelProvider; -import org.fhsolution.eclipse.plugins.csvedit.sorter.CSVTableSorter; - -/** - * - * @author fhenri - * @author msavy - * - */ -public abstract class MultiPageCSVEditor extends MultiPageEditorPart implements - IResourceChangeListener { - - private boolean isPageModified; - - /** index of the source page */ - public static final int indexSRC = 1; - /** index of the table page */ - public static final int indexTBL = 0; - - /** The text editor used in page 0. */ - protected TextEditor editor; - - /** The table viewer used in page 1. */ - protected TableViewer tableViewer; - - private CSVTableSorter tableSorter; - - private Menu tableHeaderMenu; - - private AbstractCSVFile model; - - /** - * - */ - private final ICsvFileModelListener csvFileListener = new ICsvFileModelListener() { - public void entryChanged(CSVRow row, int rowIndex) { - // tableViewer.update(row, new String[] { Integer.toString(rowIndex) - // }); - tableModified(); - } - }; - - /** - * Creates a multi-page editor example. - */ - public MultiPageCSVEditor() { - super(); - ResourcesPlugin.getWorkspace().addResourceChangeListener(this); - model = createCSVFile(); - } - - /** - * Create the CSV file object. Class that extends the MultiPageCSVEditor - * must implement this class. - * - * @return an {@link AbstractCSVFile} object which provides the contents as - * well as some formatting information such as the delimiter and - * extra meta information - */ - protected abstract AbstractCSVFile createCSVFile(); - - /** - * Creates the pages of the multi-page editor. - * - * @see org.eclipse.ui.part.MultiPageEditorPart#createPages() - */ - protected void createPages() { - try { - createTablePage(); - createSourcePage(); - updateTitle(); - populateTablePage(); - } catch (Exception e) { - System.err.println(e); - e.printStackTrace(); - } - } - - /** - * Creates page 0 of the multi-page editor, which contains a text editor. - */ - private void createSourcePage() { - try { - editor = new CSVTextEditor(model.getCustomDelimiter()); - addPage(editor, getEditorInput()); - setPageText(indexSRC, "CSV Source"); - } catch (PartInitException e) { - ErrorDialog.openError(getSite().getShell(), - "Error creating nested text editor", null, e.getStatus()); - } - } - - /** - * - */ - private void createTablePage() { - Composite parent = getContainer(); - - // XXX move all the creation into its own component - Canvas canvas = new Canvas(parent, SWT.None); - - GridLayout layout = new GridLayout(6, false); - canvas.setLayout(layout); - - // create the header part with the search function and Add/Delete rows - Label searchLabel = new Label(canvas, SWT.NONE); - searchLabel.setText("Filter: "); - final Text searchText = new Text(canvas, SWT.BORDER | SWT.SEARCH); - searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL - | GridData.HORIZONTAL_ALIGN_FILL)); - - // Create and configure the buttons - Button duplicate = new Button(canvas, SWT.PUSH | SWT.CENTER); - duplicate.setText("Duplicate"); - duplicate.setToolTipText("Duplicate the current row"); - GridData buttonDuplicateGridData = new GridData( - GridData.HORIZONTAL_ALIGN_BEGINNING); - buttonDuplicateGridData.widthHint = 80; - duplicate.setLayoutData(buttonDuplicateGridData); - duplicate.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - if (row != null) { - model.duplicateRow(row); - tableModified(); - } - } - }); - - Button insert = new Button(canvas, SWT.PUSH | SWT.CENTER); - insert.setText("Insert Row"); - insert.setToolTipText("Insert a new row before the current one"); - GridData buttonInsertGridData = new GridData( - GridData.HORIZONTAL_ALIGN_BEGINNING); - buttonInsertGridData.widthHint = 80; - insert.setLayoutData(buttonInsertGridData); - insert.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - if (row != null) { - model.addRowAfterElement(row); - tableModified(); - } - } - }); - /* - * insert.addKeyListener(new KeyAdapter() { public void - * keyPressed(KeyEvent e) { //if(((e.stateMask & SWT.CTRL) != 0) & - * (e.keyCode == 'd')) { //if (e.stateMask == SWT.CTRL && e.keyCode == - * 'd') { if (e.character == SWT.DEL) { CSVRow row = (CSVRow) - * ((IStructuredSelection) - * tableViewer.getSelection()).getFirstElement(); if (row != null) { - * model.addLineAfterElement(row); tableViewer.refresh(); - * tableModified(); } } } }); - */ - - Button add = new Button(canvas, SWT.PUSH | SWT.CENTER); - add.setText("Add Row"); - add.setToolTipText("Add a new row at the end of the file"); - GridData buttonAddGridData = new GridData( - GridData.HORIZONTAL_ALIGN_BEGINNING); - buttonAddGridData.widthHint = 80; - add.setLayoutData(buttonAddGridData); - add.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - model.addRow(); - tableModified(); - } - }); - - Button delete = new Button(canvas, SWT.PUSH | SWT.CENTER); - delete.setText("Delete Row"); - delete.setToolTipText("Delete the current row"); - GridData buttonDelGridData = new GridData( - GridData.HORIZONTAL_ALIGN_BEGINNING); - buttonDelGridData.widthHint = 80; - delete.setLayoutData(buttonDelGridData); - delete.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer - .getSelection()).getFirstElement(); - - while(row != null){ - row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); - if (row != null) { - model.removeRow(row); - tableModified(); - } - } - } - }); - /* - * insert.addKeyListener(new KeyAdapter() { public void - * keyPressed(KeyEvent e) { if (e.stateMask == SWT.CTRL && e.keyCode == - * 'd') { CSVRow row = (CSVRow) ((IStructuredSelection) - * tableViewer.getSelection()).getFirstElement(); if (row != null) { - * model.removeLine(row); tableViewer.refresh(); tableModified(); } } } - * }); - */ - /* - * - * // manage 1st line - should only be visible if global option is set - * if (pref.getUseFirstLineAsHeader()) { Label encodingLineLabel = new - * Label(canvas, SWT.NONE); - * encodingLineLabel.setText("Display 1st line"); final Button - * encodingLineBtn = new Button(canvas, SWT.CHECK); - * encodingLineBtn.setLayoutData(new - * GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); - * encodingLineBtn.setSelection(true); - * encodingLineBtn.addSelectionListener(new SelectionAdapter() { public - * void widgetSelected(SelectionEvent e) { - * model.displayFirstLine(encodingLineBtn.getSelection()); - * updateTableFromTextEditor(); } }); } - * sensitiveBtn.addSelectionListener(new SelectionAdapter() { public - * void widgetSelected(SelectionEvent e) { - * tableFilter.setSearchText(searchText.getText(), - * sensitiveBtn.getSelection()); - * labelProvider.setSearchText(searchText.getText()); - * tableViewer.refresh(); } }); - */ - tableViewer = new TableViewer(canvas, SWT.MULTI | SWT.H_SCROLL - | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); - tableViewer.setUseHashlookup(true); - final Table table = tableViewer.getTable(); - table.setHeaderVisible(true); - table.setLinesVisible(true); - - // set the sorter for the table - tableSorter = new CSVTableSorter(); - tableViewer.setSorter(tableSorter); - - // set a table filter - final CSVTableFilter tableFilter = new CSVTableFilter(); - tableViewer.addFilter(tableFilter); - - // add the filtering and coloring when searching specific elements. - searchText.addKeyListener(new KeyAdapter() { - public void keyReleased(KeyEvent ke) { - tableFilter.setSearchText(searchText.getText(), - model.getSensitiveSearch()); - String filterText = searchText.getText(); - for (int i = 0; i < tableViewer.getColumnProperties().length; i++) { - CellLabelProvider labelProvider = tableViewer - .getLabelProvider(i); - if(labelProvider != null){ - ((CSVLabelProvider) labelProvider) - .setSearchText(filterText); - } - } - tableViewer.refresh(); - } - }); - - /* - * // create a TableCursor to navigate around the table final - * TableCursor cursor = new TableCursor(table, SWT.NONE); // create an - * editor to edit the cell when the user hits "ENTER" // while over a - * cell in the table final ControlEditor editor = new - * ControlEditor(cursor); editor.grabHorizontal = true; - * editor.grabVertical = true; - * - * cursor.addSelectionListener(new SelectionAdapter() { // This is - * called as the user navigates around the table public void - * widgetSelected(SelectionEvent e) { // Select the row in the table - * where the TableCursor is table.setSelection(new TableItem[] - * {cursor.getRow()}); } - * - * // when the user hits "ENTER" in the TableCursor, // pop up a text - * editor so that user can change the text of the cell public void - * widgetDefaultSelected(SelectionEvent e) { // Begin an editing session - * final Text text = new Text(cursor, SWT.NONE); - * - * // Copy the text from the cell to the Text int column = - * cursor.getColumn(); text.setText(cursor.getRow().getText(column)); - * - * // Add a handler to detect key presses text.addKeyListener(new - * KeyAdapter() { public void keyPressed(KeyEvent e) { // tab will save - * & move to the next column if (e.character == SWT.TAB) { TableItem row - * = cursor.getRow(); int column = cursor.getColumn(); - * row.setText(column, text.getText()); text.dispose(); - * cursor.setSelection(row, column+1); tableModified(); } // close the - * text editor and copy the data over // when the user hits "ENTER" if - * (e.character == SWT.CR) { TableItem row = cursor.getRow(); - * row.setText(cursor.getColumn(), text.getText()); tableModified(); - * text.dispose(); } // close the text editor when the user hits "ESC" - * if (e.character == SWT.ESC) { text.dispose(); } } }); // close the - * text editor when the user tabs away text.addFocusListener(new - * FocusAdapter() { public void focusLost(FocusEvent e) { - * text.dispose(); } }); editor.setEditor(text); text.setFocus(); } }); - * - * /* // Hide the TableCursor when the user hits the "CTRL" or "SHIFT" - * key. // This allows the user to select multiple items in the table. - * cursor.addKeyListener(new KeyAdapter() { public void - * keyPressed(KeyEvent e) { - * - * // delete line if (e.character == SWT.DEL) { TableItem row = - * cursor.getRow(); tableModified(); row.dispose(); - * //table.showItem(row); //cursor.setSelection(row, 0); } - * - * // insert line if (e.character == (char) SWT.F8) { TableItem row = - * cursor.getRow(); row.dispose(); } - * - * // add line - * - * cursor.setVisible(true); cursor.setFocus(); - * - * if (e.keyCode == SWT.CTRL || e.keyCode == SWT.SHIFT || (e.stateMask & - * SWT.CONTROL) != 0 || (e.stateMask & SWT.SHIFT) != 0) { - * cursor.setVisible(false); return; } } }); - * - * // When the user double clicks in the TableCursor, pop up a text - * editor so that // they can change the text of the cell. - * cursor.addMouseListener(new MouseAdapter() { public void - * mouseDown(MouseEvent e) { final Text text = new Text(cursor, - * SWT.NONE); TableItem row = cursor.getRow(); int column = - * cursor.getColumn(); text.setText(row.getText(column)); - * text.addKeyListener(new KeyAdapter() { public void - * keyPressed(KeyEvent e) { // close the text editor and copy the data - * over // when the user hits "ENTER" if (e.character == SWT.CR) { - * TableItem row = cursor.getRow(); int column = cursor.getColumn(); - * row.setText(column, text.getText()); tableModified(); text.dispose(); - * } // close the text editor when the user hits "ESC" if (e.character - * == SWT.ESC) { text.dispose(); } } }); // close the text editor when - * the user clicks away text.addFocusListener(new FocusAdapter() { - * public void focusLost(FocusEvent e) { text.dispose(); } }); - * editor.setEditor(text); text.setFocus(); } }); - * - * // Show the TableCursor when the user releases the "SHIFT" or "CTRL" - * key. // This signals the end of the multiple selection task. - * table.addKeyListener(new KeyAdapter() { public void - * keyReleased(KeyEvent e) { - * - * if (e.keyCode == SWT.CONTROL && (e.stateMask & SWT.SHIFT) != 0) - * return; if (e.keyCode == SWT.SHIFT && (e.stateMask & SWT.CONTROL) != - * 0) return; if (e.keyCode != SWT.CONTROL && (e.stateMask & - * SWT.CONTROL) != 0) return; if (e.keyCode != SWT.SHIFT && (e.stateMask - * & SWT.SHIFT) != 0) return; - * - * TableItem[] selection = table.getSelection(); TableItem row = - * (selection.length == 0) ? table.getItem(table.getTopIndex()) : - * selection[0]; table.showItem(row); cursor.setSelection(row, 0); - * cursor.setVisible(true); cursor.setFocus(); } }); - */ - -/* tableViewer.addDoubleClickListener(new IDoubleClickListener() { - - public void doubleClick(DoubleClickEvent event) { - - CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); - DetailedView input = new DetailedView(Display.getDefault(), model.getHeader(), row); - - input.open(); - - } - });*/ - - // Layout the viewer - GridData gridData = new GridData(); - gridData.verticalAlignment = GridData.FILL; - gridData.horizontalSpan = 6; - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = GridData.FILL; - tableViewer.getControl().setLayoutData(gridData); - - addPage(canvas); - setPageText(indexTBL, "CSV Table"); - } - - /** - * Set Name of the file to the tab - */ - private void updateTitle() { - IEditorInput input = getEditorInput(); - setPartName(input.getName()); - setTitleToolTip(input.getToolTipText()); - } - - /** - * @throws Exception - */ - private void populateTablePage() throws Exception { - tableViewer.setContentProvider(new CSVContentProvider()); - - // make the selection available - getSite().setSelectionProvider(tableViewer); - - tableViewer.getTable().getDisplay().asyncExec(new Runnable() { - public void run() { - updateTableFromTextEditor(); - } - }); - } - - /** - * - */ - public void tableModified() { - tableViewer.refresh(); - boolean wasPageModified = isPageModified; - isPageModified = true; - if (!wasPageModified) { - firePropertyChange(IEditorPart.PROP_DIRTY); - editor.validateEditorInputState(); // will invoke: - // FileModificationValidator.validateEdit() - // (expected by some repository - // providers) - } - } - - /** - * - */ - private void updateTableFromTextEditor() { - - tableHeaderMenu = new Menu(tableViewer.getTable()); - - // PropertyFile propertyFile = (PropertyFile) treeViewer.getInput(); - model.removeModelListener(csvFileListener); - - model.setInput(editor.getDocumentProvider() - .getDocument(editor.getEditorInput()).get()); - - final MenuItem detailedEditItem = new MenuItem(tableHeaderMenu, - SWT.PUSH, 0); - detailedEditItem.setText("Edit"); - detailedEditItem.setSelection(false); - detailedEditItem.addListener(SWT.Selection, new Listener() { - - public void handleEvent(Event event) { - - CSVRow row = (CSVRow) ((IStructuredSelection) tableViewer.getSelection()).getFirstElement(); - - if(row != null){ - DetailedEditor input = new DetailedEditor(Display.getDefault(), model.getHeader(), - row, model.getInCellDelimiter(), model.getRegexTableMarker()); - input.open(); - } - } - }); - - new MenuItem(tableHeaderMenu, SWT.SEPARATOR, 1); - - TableColumn[] columns = tableViewer.getTable().getColumns(); - if (columns.length > 0) { // if table header columns already created - // update column header text - for (int i = 0; i < model.getHeader().size(); i++){ - if(i < columns.length){ - columns[i].setText(model.getHeader().get(i)); - final int index = i; - addMenuItemToColumn(columns[i], index+2); - } - } - } else { - // create columns - for (int i = 0; i < model.getHeader().size(); i++) { - final TableViewerColumn column = new TableViewerColumn( - tableViewer, SWT.LEFT); - final int index = i; - column.getColumn().setText(model.getHeader().get(i)); - column.getColumn().setWidth(100); - column.getColumn().setResizable(true); - column.getColumn().setMoveable(true); - column.setLabelProvider(new CSVLabelProvider()); - //+2 because the first two items are Edit and a separator - addMenuItemToColumn(column.getColumn(), index+2); - } - } - - if (model.isFirstLineHeader()) { - new MenuItem(tableHeaderMenu, SWT.SEPARATOR); - - // create menu item to delete column - final MenuItem deleteColumnItem = new MenuItem(tableHeaderMenu, - SWT.PUSH); - deleteColumnItem.setText("Delete Column"); - deleteColumnItem.setSelection(false); - deleteColumnItem.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - // call delete column page - DeleteColumnPage dcPage = new DeleteColumnPage(getSite() - .getShell(), model.getArrayHeader()); - if (dcPage.open() == InputDialog.OK) { - String[] colToDelete = dcPage.getColumnSelected(); - for (String column : colToDelete) { - int colIndex = findColumnForName(column); - tableViewer.getTable().getColumn(colIndex) - .dispose(); - //+2 because the first two items are Edit and a separator - tableHeaderMenu.getItem(colIndex+2).dispose(); - model.removeColumn(column); - } - tableModified(); - } - } - }); - - // create menu item to insert column - final MenuItem insertColumnItem = new MenuItem(tableHeaderMenu, - SWT.PUSH); - insertColumnItem.setText("Add Column"); - insertColumnItem.setSelection(false); - insertColumnItem.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - // call insert/add column page - InsertColumnPage acPage = new InsertColumnPage(getSite() - .getShell(), model.getArrayHeader()); - if (acPage.open() == InputDialog.OK) { - String colToInsert = acPage.getColumnNewName(); - model.addColumn(colToInsert); - - tableViewer.setInput(model); - final TableColumn column = new TableColumn(tableViewer - .getTable(), SWT.LEFT); - column.setText(colToInsert); - column.setWidth(100); - column.setResizable(true); - column.setMoveable(true); - - addMenuItemToColumn(column, model.getColumnCount() - 1); - defineCellEditing(); - - tableModified(); - } - } - }); - } - - tableViewer.setInput(model); - model.addModelListener(csvFileListener); - - tableViewer.getTable().addListener(SWT.MenuDetect, new Listener() { - public void handleEvent(Event event) { - tableViewer.getTable().setMenu(tableHeaderMenu); - } - }); - - defineCellEditing(); - } - - /** - * - */ - private void defineCellEditing() { - String[] columnProperties = new String[model.getColumnCount()]; - CellEditor[] cellEditors = new CellEditor[model.getColumnCount()]; - - for (int i = 0; i < model.getColumnCount(); i++) { - columnProperties[i] = Integer.toString(i); - cellEditors[i] = new TextCellEditor(tableViewer.getTable()); - } - - tableViewer.setColumnProperties(columnProperties); - - // XXX can be replaced by tableViewer.setEditingSupport() - tableViewer.setCellEditors(cellEditors); - tableViewer.setCellModifier(new CSVEditorCellModifier()); - - } - - /** - * Find a column in the Table by its name - * - * @param columnName - * @return the index of the Column indicated by its name - */ - private int findColumnForName(String columnName) { - int index = -1; - TableColumn[] tableColumns = tableViewer.getTable().getColumns(); - for (int i = 0; i < tableColumns.length; i++) { - TableColumn column = tableColumns[i]; - if (columnName.equalsIgnoreCase(column.getText())) - return i; - } - return index; - } - - /** - * @param column - * @param index - */ - private void addMenuItemToColumn(final TableColumn column, final int index) { - - // create menu item - final MenuItem itemName = new MenuItem(tableHeaderMenu, SWT.CHECK, - index); - itemName.setText(column.getText()); - itemName.setSelection(column.getResizable()); - itemName.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - if (itemName.getSelection()) { - column.setWidth(100); - column.setResizable(true); - } else { - column.setWidth(0); - column.setResizable(false); - } - } - }); - - // Setting the right sorter - column.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - int dir = tableViewer.getTable().getSortDirection(); - switch (dir) { - case SWT.UP: - dir = SWT.DOWN; - break; - case SWT.DOWN: - dir = SWT.NONE; - break; - case SWT.NONE: - dir = SWT.UP; - break; - } - tableSorter.setColumn(index, dir); - tableViewer.getTable().setSortDirection(dir); - if (dir == SWT.NONE) { - tableViewer.getTable().setSortColumn(null); - } else { - tableViewer.getTable().setSortColumn(column); - } - tableViewer.refresh(); - } - }); - - } - - /** - * The MultiPageEditorPart implementation of this - * IWorkbenchPart method disposes all nested editors. This - * method is automatically called when the editor is closed and marks the - * end of the editor's life cycle. It cleans up any platform resources, such - * as images, clipboard, and so on, which were created by this class. - * - * @see org.eclipse.ui.part.MultiPageEditorPart#dispose() - */ - public void dispose() { - ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); - super.dispose(); - } - - /** - * Saves the multi-page editor's document. If the save is successful, the - * part should fire a property changed event (PROP_DIRTY property), - * reflecting the new dirty state. If the save is canceled via user action, - * or for any other reason, the part should invoke setCanceled on the - * IProgressMonitor to inform the caller - * - * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor) - */ - public void doSave(IProgressMonitor monitor) { - if (getActivePage() == indexTBL && isPageModified) { - updateTextEditorFromTable(); - } else { - updateTableFromTextEditor(); - } - - isPageModified = false; - editor.doSave(monitor); - } - - /** - * Returns whether the "Save As" operation is supported by this part. - * - * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed() - */ - public boolean isSaveAsAllowed() { - return true; - } - - /** - * Saves the multi-page editor's document as another file. Also updates the - * text for page 0's tab, and updates this multi-page editor's input to - * correspond to the nested editor's. - * - * @see org.eclipse.ui.part.EditorPart#doSaveAs() - */ - public void doSaveAs() { - if (getActivePage() == indexTBL && isPageModified) { - updateTextEditorFromTable(); - } else { - updateTableFromTextEditor(); - } - - isPageModified = false; - - editor.doSaveAs(); - setInput(editor.getEditorInput()); - updateTitle(); - } - - /** - * Initializes this editor with the given editor site and input. This method - * is automatically called shortly after editor construction; it marks the - * start of the editor's lifecycle. - * - * The MultiPageEditorExample implementation of this method - * checks that the input is an instance of IFileEditorInput. - * - * @see org.eclipse.ui.part.MultiPageEditorPart#init(org.eclipse.ui.IEditorSite, - * org.eclipse.ui.IEditorInput) - */ - public void init(IEditorSite site, IEditorInput editorInput) - throws PartInitException { - /* - * String message = "Input is " + editorInput + " of instance " + - * editorInput.getClass().getName(); IStatus status = new - * Status(IStatus.ERROR, "csvedit", IStatus.ERROR, message, null); - * Activator.getDefault().getLog().log(status); - */ - - /* - * if (!(editorInput instanceof IFileEditorInput)) throw new - * PartInitException("Invalid Input: Must be IFileEditorInput"); - */ - super.init(site, editorInput); - } - - /** - * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int) - */ - protected void handlePropertyChange(int propertyId) { - if (propertyId == IEditorPart.PROP_DIRTY) - isPageModified = isDirty(); - super.handlePropertyChange(propertyId); - } - - /** - * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty() - */ - public boolean isDirty() { - return isPageModified || super.isDirty(); - } - - /** - * Calculates the contents of page 2 when the it is activated. - * - * @see org.eclipse.ui.part.MultiPageEditorPart#pageChange(int) - */ - protected void pageChange(int newPageIndex) { - switch (newPageIndex) { - case indexSRC: - if (isDirty()) - updateTextEditorFromTable(); - break; - case indexTBL: - if (isDirty()) - updateTableFromTextEditor(); - break; - } - isPageModified = false; - super.pageChange(newPageIndex); - } - - /** - * - */ - private void updateTextEditorFromTable() { - editor.getDocumentProvider() - .getDocument(editor.getEditorInput()) - .set(((AbstractCSVFile) tableViewer.getInput()) - .getTextRepresentation()); - } - - /** - * When the focus shifts to the editor, this method is called; it must then - * redirect focus to the appropriate editor based on which page is currently - * selected. - * - * @see org.eclipse.ui.part.MultiPageEditorPart#setFocus() - */ - public void setFocus() { - switch (getActivePage()) { - case indexSRC: - editor.setFocus(); - break; - case indexTBL: - tableViewer.getTable().setFocus(); - break; - } - } - - /** - * Closes all project files on project close. - * - * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) - */ - public void resourceChanged(final IResourceChangeEvent event) { - if (event.getType() == IResourceChangeEvent.PRE_CLOSE) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - IWorkbenchPage[] pages = getSite().getWorkbenchWindow() - .getPages(); - for (int i = 0; i < pages.length; i++) { - if (((FileEditorInput) editor.getEditorInput()) - .getFile().getProject() - .equals(event.getResource())) { - IEditorPart editorPart = pages[i].findEditor(editor - .getEditorInput()); - pages[i].closeEditor(editorPart, true); - } - } - } - }); - } - } -} diff --git a/csvedit.site/category.xml b/csvedit.site/category.xml index 15828c1..2e74223 100644 --- a/csvedit.site/category.xml +++ b/csvedit.site/category.xml @@ -1,8 +1,7 @@ - - + + - + diff --git a/csvedit.site/packaging-p2composite.ant b/csvedit.site/packaging-p2composite.ant new file mode 100644 index 0000000..6606791 --- /dev/null +++ b/csvedit.site/packaging-p2composite.ant @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + version=1 +metadata.repository.factory.order=compositeContent.xml,\! +artifact.repository.factory.order=compositeArtifacts.xml,\! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csvedit.site/pom.xml b/csvedit.site/pom.xml index b0cccc3..e4de24c 100644 --- a/csvedit.site/pom.xml +++ b/csvedit.site/pom.xml @@ -1,12 +1,235 @@ - - 4.0.0 - - csvedit - org.nodeclipse - 1.2.0-SNAPSHOT - - csvedit.site - eclipse-repository - csvedit :: update site + + 4.0.0 + + csvedit2 + me.glindholm.plugin + 2.1.0-SNAPSHOT + + csvedit.site + eclipse-repository + csvedit :: update site + + + + + org.eclipse.tycho + tycho-packaging-plugin + + 'v'yyyyMMdd'-'HHmm + + + + + org.eclipse.tycho + tycho-p2-repository-plugin + + ${project.artifactId}-${qualifiedVersion} + + + + + + + + + release-composite + + false + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + + parse-version + + parse-version + + + + + + org.codehaus.mojo + exec-maven-plugin + + git + + + + git-clone + prepare-package + + exec + + + + clone + --depth=1 + -b + main + ${github-update-repo} + ${github-local-clone} + + + + + git-add + verify + + exec + + + + -C + ${github-local-clone} + add + -A + + + + + git-commit + verify + + exec + + + + -C + ${github-local-clone} + commit + -m + Release ${qualifiedVersion} + + + + + git-push + deploy + + exec + + + + -C + ${github-local-clone} + push + origin + main + + + + + + + maven-resources-plugin + + + copy-repository + package + + copy-resources + + + + ${current-release-directory} + + + + ${project.build.directory}/repository + + + + + + + + org.eclipse.tycho.extras + tycho-eclipserun-plugin + + + + eclipse-version + p2 + + https://download.eclipse.org/releases/2023-06 + + + + + org.eclipse.ant.core + eclipse-plugin + + + org.apache.ant + eclipse-plugin + + + + org.eclipse.equinox.p2.repository.tools + eclipse-plugin + + + + org.eclipse.equinox.p2.core.feature + eclipse-feature + + + + org.eclipse.equinox.p2.extras.feature + eclipse-feature + + + org.eclipse.rcp + eclipse-feature + + + + + + + add-p2-composite-repository + package + + eclipse-run + + + + -application + org.eclipse.ant.core.antRunner + -buildfile + packaging-p2composite.ant + p2.composite.add + -Dsite.label="${site.label}" + + -Dcomposite.base.dir=${github-local-clone} + + -DunqualifiedVersion=${unqualifiedVersion} + -DbuildQualifier=${buildQualifier} + + -DparsedVersion.majorVersion=${parsedVersion.majorVersion} + + -DparsedVersion.minorVersion=${parsedVersion.minorVersion} + + + + + + + + + diff --git a/csvedit.target/csvedit.target b/csvedit.target/csvedit.target new file mode 100644 index 0000000..9d9feae --- /dev/null +++ b/csvedit.target/csvedit.target @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + org.jumpmind.symmetric + symmetric-csv + 3.15.11 + jar + + + + + jumpmind + https://maven.jumpmind.com/repo/ + + + + + \ No newline at end of file diff --git a/csvedit.target/pom.xml b/csvedit.target/pom.xml new file mode 100644 index 0000000..f78770c --- /dev/null +++ b/csvedit.target/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + + me.glindholm.plugin + csvedit2 + 2.1.0-SNAPSHOT + + csvedit.target + eclipse-target-definition + \ No newline at end of file diff --git a/csvedit.update/.gitignore b/csvedit.update/.gitignore deleted file mode 100644 index b71f363..0000000 --- a/csvedit.update/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -*.pydevproject -.metadata -.gradle -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - -# sbteclipse plugin -.target - -# TeXlipse plugin -.texlipse \ No newline at end of file diff --git a/csvedit.update/.project b/csvedit.update/.project deleted file mode 100644 index 4bd93c1..0000000 --- a/csvedit.update/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - csvedit.update - - - - - - org.eclipse.pde.UpdateSiteBuilder - - - - - - org.eclipse.pde.UpdateSiteNature - - diff --git a/csvedit.update/artifacts.jar b/csvedit.update/artifacts.jar deleted file mode 100644 index 7c0df1d..0000000 Binary files a/csvedit.update/artifacts.jar and /dev/null differ diff --git a/csvedit.update/content.jar b/csvedit.update/content.jar deleted file mode 100644 index 7b6b541..0000000 Binary files a/csvedit.update/content.jar and /dev/null differ diff --git a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.1.jar b/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.1.jar deleted file mode 100644 index a74f125..0000000 Binary files a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.1.jar and /dev/null differ diff --git a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.2.jar b/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.2.jar deleted file mode 100644 index 3cdd37c..0000000 Binary files a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.2.jar and /dev/null differ diff --git a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.3.jar b/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.3.jar deleted file mode 100644 index eff2d81..0000000 Binary files a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.0.3.jar and /dev/null differ diff --git a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.0.jar b/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.0.jar deleted file mode 100644 index 10a6336..0000000 Binary files a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.0.jar and /dev/null differ diff --git a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.1.jar b/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.1.jar deleted file mode 100644 index b4c4d75..0000000 Binary files a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.1.jar and /dev/null differ diff --git a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.2.jar b/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.2.jar deleted file mode 100644 index 1f35a1f..0000000 Binary files a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.1.2.jar and /dev/null differ diff --git a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.2.0.jar b/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.2.0.jar deleted file mode 100644 index d0645c3..0000000 Binary files a/csvedit.update/features/org.fhsolution.eclipse.feature.csvedit_1.2.0.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.0.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.0.jar deleted file mode 100644 index 66a9af8..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.0.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.1.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.1.jar deleted file mode 100644 index 68794e5..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.1.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.2.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.2.jar deleted file mode 100644 index c87a303..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.1.2.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.2.0.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.2.0.jar deleted file mode 100644 index 90a1ae6..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit.ui_1.2.0.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.0.2.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.0.2.jar deleted file mode 100644 index 42ca369..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.0.2.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.0.3.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.0.3.jar deleted file mode 100644 index 5d54238..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.0.3.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.0.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.0.jar deleted file mode 100644 index 944a7ee..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.0.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.1.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.1.jar deleted file mode 100644 index 39884f8..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.1.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.2.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.2.jar deleted file mode 100644 index d7d0eae..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.1.2.jar and /dev/null differ diff --git a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.2.0.jar b/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.2.0.jar deleted file mode 100644 index d581b54..0000000 Binary files a/csvedit.update/plugins/org.fhsolution.eclipse.plugins.csvedit_1.2.0.jar and /dev/null differ diff --git a/csvedit.update/site.xml b/csvedit.update/site.xml deleted file mode 100644 index ca85e3a..0000000 --- a/csvedit.update/site.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - Update site for the csvedit eclipse plugin - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 308f723..2ef6ac0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,99 +1,308 @@ - - 4.0.0 - org.nodeclipse - csvedit - 1.2.0-SNAPSHOT - pom - csvedit :: parent - csvedit parent + + 4.0.0 + me.glindholm.plugin + csvedit2 + 2.1.0-SNAPSHOT + pom + csvedit :: parent + csvedit parent - - 3.0 - + + 17 + 4.0.4 + -Xmx512m + UTF-8 - - 1.6 - 3.0 - 1.0.0 - -Xmx512m -XX:MaxPermSize=256m - UTF-8 - + + + git@github.com:gnl42/CsvEdit2-update.git + ${project.build.directory}/checkout + ${github-local-clone}/releases + ${releases-directory}/${qualifiedVersion} + + CsvEdit2-update + - - - luna - p2 - http://download.eclipse.org/releases/luna - - + + scm:git@github.com:gnl42/CsvEdit2.git + scm:git@github.com:gnl42/CsvEdit2.git + https://github.com/gnl42/CsvEdit2 + - - - sonatype-public - http://repository.sonatype.org/content/groups/sonatype-public-grid - - + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.5.0 + + + org.apache.maven.plugins + maven-site-plugin + 3.12.1 + + + org.apache.maven.plugins + maven-deploy-plugin + 3.1.1 + + + org.codehaus.mojo + build-helper-maven-plugin + 3.4.0 + + + org.apache.maven.plugins + maven-surefire-report-plugin + 3.1.2 + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.3.0 + + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + + org.apache.maven.plugins + maven-clean-plugin + 3.3.1 + + + org.apache.maven.plugins + maven-jxr-plugin + 3.3.0 + + + org.eclipse.tycho + tycho-compiler-plugin + ${tycho.version} + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho.version} + true + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho.version} + + + org.eclipse.tycho + tycho-source-plugin + ${tycho.version} + + + org.eclipse.tycho.extras + tycho-source-feature-plugin + ${tycho.version} + + + org.eclipse.tycho + tycho-p2-plugin + ${tycho.version} + + + org.eclipse.tycho + tycho-versions-plugin + ${tycho.version} + + + org.eclipse.tycho + tycho-p2-director-plugin + ${tycho.version} + + + org.eclipse.tycho + tycho-surefire-plugin + ${tycho.version} + + + org.eclipse.tycho + target-platform-configuration + ${tycho.version} + + + org.eclipse.tycho.extras + tycho-eclipserun-plugin + ${tycho.version} + + + org.eclipse.tycho.extras + tycho-pack200a-plugin + ${tycho.version} + + + org.eclipse.tycho.extras + tycho-pack200b-plugin + ${tycho.version} + + + org.eclipse.cbi.maven.plugins + eclipse-jarsigner-plugin + 1.4.2 + + + + + + org.apache.maven.plugins + maven-resources-plugin + + UTF-8 + + + + org.eclipse.tycho + tycho-compiler-plugin + + 17 + true + true + + + + org.eclipse.tycho + tycho-maven-plugin + true + + + org.eclipse.tycho + tycho-p2-repository-plugin + + + org.eclipse.tycho + tycho-packaging-plugin + ${tycho.version} + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 - - - - org.eclipse.tycho - tycho-maven-plugin - ${tycho.version} - true - - - org.eclipse.tycho - target-platform-configuration - ${tycho.version} - - p2 - consider - true - - - + + + org.eclipse.tycho + tycho-p2-plugin + + + attach-p2-metadata + package + + p2-metadata + + + + + + org.eclipse.tycho + tycho-versions-plugin + + + org.eclipse.tycho + tycho-surefire-plugin + + false + true + true + + + ${ui.test.vmargs} + + + org.eclipse.equinox.launcher + 4 + true + + + + + + + + + p2-installable-unit + org.eclipse.equinox.event + + + + + + org.eclipse.tycho + target-platform-configuration + + + + linux + gtk + x86_64 + + + win32 + win32 + x86_64 + + + macosx + cocoa + x86_64 + + + + + me.glindholm.plugin + csvedit.target + 2.1.0-SNAPSHOT + + + + + + - - - - org.eclipse.tycho - tycho-packaging-plugin - ${tycho.version} - - yyyyMMdd-HHmm - - - - org.eclipse.tycho - tycho-surefire-plugin - ${tycho.version} - - true - - **/*Test.java - - ${tycho.test.jvmArgs} - - 60 - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.3 - - - - - - csvedit.plugin - csvedit.plugin.ui - csvedit.feature - - csvedit.site - + + + + release-composite + + + + + maven-install-plugin + + + default-install + none + + + + + maven-deploy-plugin + + true + + + + + + + + + + csvedit.target + csvedit.plugin + csvedit.plugin.ui + csvedit.feature + csvedit.site + \ No newline at end of file