Office-support: Added a preference page
(for setting num of displayed chars per line and ID column for excel docs)
Change-Id: I1b4d5cf27d6faf71fcf03f9a4fc61ab41d54aca2
Signed-off-by: Dusan Kalanj <kalanj@chalmers.se>
diff --git a/org.eclipse.capra.ui.office/.classpath b/org.eclipse.capra.ui.office/.classpath
index 3694476..52651cd 100644
--- a/org.eclipse.capra.ui.office/.classpath
+++ b/org.eclipse.capra.ui.office/.classpath
@@ -5,11 +5,7 @@
<classpathentry kind="lib" path="lib/xmlbeans-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/poi-3.10.1-20140818.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-schemas-3.10.1-20140818.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF b/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
index e19cd89..0408a38 100644
--- a/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
+++ b/org.eclipse.capra.ui.office/META-INF/MANIFEST.MF
@@ -17,9 +17,9 @@
org.eclipse.jface,
com.google.guava,
org.dom4j,
+ org.eclipse.core.runtime,
org.eclipse.core.expressions
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.capra.ui.office.objects,
- org.eclipse.capra.ui.office.utils,
- org.eclipse.capra.ui.office.views
+ org.eclipse.capra.ui.office.utils
diff --git a/org.eclipse.capra.ui.office/plugin.xml b/org.eclipse.capra.ui.office/plugin.xml
index 1469be0..ab76405 100644
--- a/org.eclipse.capra.ui.office/plugin.xml
+++ b/org.eclipse.capra.ui.office/plugin.xml
@@ -44,10 +44,6 @@
id="org.eclipse.capra.ui.office.selectsheet"
name="Select Sheet">
</command>
- <command
- id="org.eclipse.capra.ui.office.setcharactercount"
- name="Character Count">
- </command>
</extension>
<extension
point="org.eclipse.ui.handlers">
@@ -112,15 +108,6 @@
</test>
</visibleWhen>
</command>
- <menu
- label="Options">
- <command
- commandId="org.eclipse.capra.ui.office.setcharactercount"
- label="Character Count"
- style="push"
- tooltip="Set number of characters that are shown per line">
- </command>
- </menu>
</menuContribution>
<menuContribution
locationURI="popup:net.sourceforge.plantuml.eclipse.views.PlantUmlView?after=additions">
@@ -147,4 +134,19 @@
class="org.eclipse.capra.ui.office.utils.OfficeTransferType">
</transfer>
</extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.capra.ui.preferences.CapraPreferences"
+ class="org.eclipse.capra.ui.office.preferences.OfficePreferences"
+ id="org.eclipse.capra.ui.office.preferences.OfficePreferences"
+ name="Office">
+ </page>
+ </extension>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.capra.ui.office.preferences.PreferenceInitializer">
+ </initializer>
+ </extension>
</plugin>
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
index eacd6fe..30c1440 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraExcelRow.java
@@ -32,6 +32,7 @@
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.eclipse.capra.ui.office.exceptions.CapraOfficeObjectNotFound;
+import org.eclipse.capra.ui.office.preferences.OfficePreferences;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
@@ -87,10 +88,15 @@
* an Excel row, extracted from an Excel document
*
*/
- public CapraExcelRow(File officeFile, Row row) {
+ public CapraExcelRow(File officeFile, Row row, String idColumn) {
super();
- String rowId = FORMATTER.formatCellValue(row.getCell(0));
+ String rowId;
+ if (idColumn.equals(OfficePreferences.EXCEL_COLUMN_VALUE_DEFAULT))
+ rowId = Integer.toString(row.getRowNum());
+ else
+ rowId = FORMATTER.formatCellValue(row.getCell(CellReference.convertColStringToIndex(idColumn)));
+
StringBuilder rowBuilder = new StringBuilder();
rowBuilder.append("ID " + rowId + ": ");
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraOfficeObject.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraOfficeObject.java
index b7d223f..2575e4e 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraOfficeObject.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/objects/CapraOfficeObject.java
@@ -165,12 +165,7 @@
*/
@Override
public String toString() {
- int minAllowed = 30;
- int dataLength = Math.min(data.length(), minAllowed);
- if (dataLength == minAllowed)
- return this.data.substring(0, dataLength) + "...";
- else
- return this.data;
+ return this.data;
}
/**
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
new file mode 100644
index 0000000..b53821b
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.preferences;
+
+import org.eclipse.capra.ui.office.views.OfficeView;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+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.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * Provides a preference page for Capra-Office, where a user can specify custom
+ * settings for the Office feature.
+ *
+ * Code adapted from:
+ * http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fpreferences_prefs_implement.htm
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class OfficePreferences extends PreferencePage implements IWorkbenchPreferencePage {
+
+ /**
+ * IDs of preferences
+ */
+ public static final String CHAR_COUNT = "org.eclipse.capra.ui.office.preferences.charcount";
+ public static final String EXCEL_COLUMN_RADIO_CHOICE = "org.eclipse.capra.ui.office.preferences.excelcolumnradiochoice";
+ public static final String EXCEL_CUSTOM_COLUMN = "org.eclipse.capra.ui.office.preferences.excelcustomcolumn";
+ public static final String EXCEL_COLUMN_VALUE = "org.eclipse.capra.ui.office.preferences.excelcolumnvalue";
+
+ /**
+ * Default preference values
+ */
+ public static final String CHAR_COUNT_DEFAULT = "30";
+ public static final boolean EXCEL_COLUMN_RADIO_ID_IS_LINE_NUMBER = true;
+ public static final String EXCEL_CUSTOM_COLUMN_DEFAULT = "A";
+ public static final String EXCEL_COLUMN_VALUE_DEFAULT = "0";
+
+ /**
+ * Description of controls
+ */
+ private static final String CHAR_COUNT_DESC = "Number of characters that are shown per line in the Office view:";
+ private static final String EXCEL_COLUMN_RADIO_CHOICE_DESC = "Setting the ID of Excel rows:";
+ private static final String EXCEL_COLUMN_IS_LINE_NUMBER_OPTION_DESC = "Line number is used as ID";
+ private static final String EXCEL_COLUMN_IS_CUSTOM_OPTION_DESC = "Custom ID column: ";
+ private static final String EXCEL_COLUMN_IS_CUSTOM_OPTION_HINT = "(e.g. \"A\", \"BC\"...)";
+
+ private static final int FIXED_TEXT_FIELD_WIDTH = 35;
+
+ /**
+ * Controls
+ */
+ private Button idIsRowNumberRadio;
+ private Button idIsCustomRadio;
+ private Text charCount;
+ private Text customIdColumn;
+
+ private Composite createComposite(Composite parent, int numColumns) {
+ Composite composite = new Composite(parent, SWT.NULL);
+
+ GridLayout layout = new GridLayout();
+ layout.numColumns = numColumns;
+ composite.setLayout(layout);
+
+ GridData data = new GridData();
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalAlignment = GridData.FILL;
+ composite.setLayoutData(data);
+
+ return composite;
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(PreferenceActivator.getDefault().getPreferenceStore());
+ }
+
+ private void storeValues() {
+ IPreferenceStore store = PreferenceActivator.getDefault().getPreferenceStore();
+
+ boolean idIsRowNumber;
+ String idColumn;
+ if (idIsRowNumberRadio.getSelection()) {
+ idColumn = EXCEL_COLUMN_VALUE_DEFAULT;
+ customIdColumn.setText("");
+ idIsRowNumber = true;
+ } else {
+ if (customIdColumn.getText().isEmpty())
+ customIdColumn.setText(EXCEL_CUSTOM_COLUMN_DEFAULT);
+ idColumn = customIdColumn.getText();
+ idIsRowNumber = false;
+ }
+
+ store.setValue(CHAR_COUNT, charCount.getText());
+ store.setValue(EXCEL_COLUMN_RADIO_CHOICE, idIsRowNumber);
+ store.setValue(EXCEL_CUSTOM_COLUMN, customIdColumn.getText());
+ store.setValue(EXCEL_COLUMN_VALUE, idColumn);
+ }
+
+ private void initializeValues() {
+ IPreferenceStore store = PreferenceActivator.getDefault().getPreferenceStore();
+
+ boolean idIsRowNumber = store.getBoolean(EXCEL_COLUMN_RADIO_CHOICE);
+ if (idIsRowNumber) {
+ idIsRowNumberRadio.setSelection(true);
+ customIdColumn.setText("");
+ customIdColumn.setEnabled(false);
+ } else {
+ idIsCustomRadio.setSelection(true);
+ customIdColumn.setText(store.getString(EXCEL_CUSTOM_COLUMN));
+ }
+
+ charCount.setText(store.getString(CHAR_COUNT));
+ }
+
+ private void initializeDefaults() {
+ idIsRowNumberRadio.setSelection(EXCEL_COLUMN_RADIO_ID_IS_LINE_NUMBER);
+ idIsCustomRadio.setSelection(!EXCEL_COLUMN_RADIO_ID_IS_LINE_NUMBER);
+
+ if (idIsRowNumberRadio.getSelection()) {
+ customIdColumn.setText("");
+ customIdColumn.setEnabled(false);
+ }
+ charCount.setText(CHAR_COUNT_DEFAULT);
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+
+ Composite compositeCharCount = createComposite(parent, 2);
+ createLabel(compositeCharCount, CHAR_COUNT_DESC, 1);
+ charCount = createTextField(compositeCharCount, 1, FIXED_TEXT_FIELD_WIDTH);
+
+ Composite compositeExcelIdColumn = createComposite(parent, 2);
+ createLabel(compositeExcelIdColumn, EXCEL_COLUMN_RADIO_CHOICE_DESC, 2);
+
+ Composite compositeRadioButtons = createComposite(compositeExcelIdColumn, 3);
+ idIsRowNumberRadio = createRadioButton(compositeRadioButtons, EXCEL_COLUMN_IS_LINE_NUMBER_OPTION_DESC, 3);
+ idIsCustomRadio = createRadioButton(compositeRadioButtons, EXCEL_COLUMN_IS_CUSTOM_OPTION_DESC, 1);
+ customIdColumn = createTextField(compositeRadioButtons, 1, FIXED_TEXT_FIELD_WIDTH);
+ createLabel(compositeRadioButtons, EXCEL_COLUMN_IS_CUSTOM_OPTION_HINT, 1);
+
+ idIsRowNumberRadio.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ customIdColumn.setText("");
+ customIdColumn.setEnabled(false);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ idIsCustomRadio.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ customIdColumn.setEnabled(true);
+ customIdColumn.setText(EXCEL_CUSTOM_COLUMN_DEFAULT);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ initializeValues();
+
+ return new Composite(parent, SWT.NULL);
+ }
+
+ private Label createLabel(Composite parent, String text, int numOfColumns) {
+ Label label = new Label(parent, SWT.LEFT);
+ label.setText(text);
+ GridData data = new GridData();
+ data.horizontalSpan = numOfColumns;
+ data.horizontalAlignment = GridData.FILL;
+ label.setLayoutData(data);
+ return label;
+ }
+
+ private Text createTextField(Composite parent, int numOfColumns, int minimumWidth) {
+ Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
+ GridData data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.grabExcessHorizontalSpace = true;
+ data.verticalAlignment = GridData.CENTER;
+ data.grabExcessVerticalSpace = false;
+ data.horizontalSpan = numOfColumns;
+ data.minimumWidth = minimumWidth;
+ text.setLayoutData(data);
+ return text;
+ }
+
+ private Button createRadioButton(Composite parent, String label, int numOfColumns) {
+ Button button = new Button(parent, SWT.RADIO | SWT.LEFT);
+ button.setText(label);
+ GridData data = new GridData();
+ data.horizontalSpan = numOfColumns;
+ button.setLayoutData(data);
+ return button;
+ }
+
+ @Override
+ public void performDefaults() {
+ super.performDefaults();
+ initializeDefaults();
+ }
+
+ @Override
+ public void performApply() {
+ super.performApply();
+ storeValues();
+ }
+
+ @Override
+ public boolean performOk() {
+ super.performOk();
+ storeValues();
+ OfficeView.getOpenedView().refreshView();
+ return true;
+ }
+}
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceActivator.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceActivator.java
new file mode 100644
index 0000000..ac609fa
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceActivator.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.preferences;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * An activator class that controls the plugin life-cycle.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class PreferenceActivator extends AbstractUIPlugin {
+
+ private static PreferenceActivator preferenceActivator = new PreferenceActivator();
+
+ /**
+ * Empty constructor
+ */
+ public PreferenceActivator() {
+ }
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ preferenceActivator = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ preferenceActivator = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance of the PreferenceActivator class.
+ *
+ * @return instance of PreferenceActivator class
+ */
+ public static PreferenceActivator getDefault() {
+ return preferenceActivator;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
new file mode 100644
index 0000000..8af4bf0
--- /dev/null
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
+package org.eclipse.capra.ui.office.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * This class is tasked with initializing preference values when the plugin is
+ * started for the first time.
+ *
+ * @author Dusan Kalanj
+ *
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+ public PreferenceInitializer() {
+ }
+
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = PreferenceActivator.getDefault().getPreferenceStore();
+ store.setDefault(OfficePreferences.CHAR_COUNT, OfficePreferences.CHAR_COUNT_DEFAULT);
+ store.setDefault(OfficePreferences.EXCEL_COLUMN_RADIO_CHOICE,
+ OfficePreferences.EXCEL_COLUMN_RADIO_ID_IS_LINE_NUMBER);
+ store.setDefault(OfficePreferences.EXCEL_CUSTOM_COLUMN, OfficePreferences.EXCEL_CUSTOM_COLUMN_DEFAULT);
+ store.setDefault(OfficePreferences.EXCEL_COLUMN_VALUE, OfficePreferences.EXCEL_COLUMN_VALUE_DEFAULT);
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
index d2140cc..1448739 100644
--- a/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
+++ b/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
@@ -31,6 +31,8 @@
import org.eclipse.capra.ui.office.objects.CapraExcelRow;
import org.eclipse.capra.ui.office.objects.CapraOfficeObject;
import org.eclipse.capra.ui.office.objects.CapraWordRequirement;
+import org.eclipse.capra.ui.office.preferences.OfficePreferences;
+import org.eclipse.capra.ui.office.preferences.PreferenceActivator;
import org.eclipse.capra.ui.office.utils.OfficeTransferType;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -136,7 +138,12 @@
@Override
public String getText(Object obj) {
- return obj.toString();
+ int minAllowed = PreferenceActivator.getDefault().getPreferenceStore().getInt(OfficePreferences.CHAR_COUNT);
+ String text = obj.toString();
+ int textLength = Math.min(text.length(), minAllowed);
+ if (textLength == minAllowed)
+ text = text.substring(0, textLength) + "...";
+ return text;
};
@Override
@@ -310,11 +317,21 @@
return;
}
- String selectedSheetName;
- if (!sheetSelect)
+ String selectedSheetName = "";
+ if (!sheetSelect || selection.isEmpty()) {
selectedSheetName = workBook.getSheetName(workBook.getActiveSheetIndex());
- else if (selection.size() > 0) {
- String activeSheetName = ((CapraExcelRow) selection.get(0)).getSheetName();
+ // If sheet is empty, prompt user to select another
+ if (workBook.getSheet(selectedSheetName).getLastRowNum() == 0)
+ sheetSelect = true;
+ }
+
+ if (sheetSelect) {
+ String activeSheetName;
+ if (selectedSheetName.isEmpty())
+ activeSheetName = ((CapraExcelRow) selection.get(0)).getSheetName();
+ else
+ activeSheetName = selectedSheetName;
+
String[] sNames = new String[workBook.getNumberOfSheets()];
// Fill sNames with sheetNames, with the active sheet at index 0
@@ -329,18 +346,21 @@
selectedSheetName = new SelectSheetDialog(viewer.getControl().getShell(),
SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL, sNames).open();
- } else {
- return;
}
+ if (selectedSheetName.isEmpty())
+ return;
+
Sheet sheet = workBook.getSheet(selectedSheetName);
- getOpenedView().clearSelection();
+ clearSelection();
+ String idColumn = PreferenceActivator.getDefault().getPreferenceStore()
+ .getString(OfficePreferences.EXCEL_COLUMN_VALUE);
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
if (row != null) {
- CapraExcelRow cRow = new CapraExcelRow(officeFile, row);
+ CapraExcelRow cRow = new CapraExcelRow(officeFile, row, idColumn);
if (!cRow.getData().isEmpty())
selection.add(cRow);
}
@@ -370,7 +390,7 @@
return;
}
- getOpenedView().clearSelection();
+ clearSelection();
for (int i = 0; i < paragraphs.size(); i++) {
XWPFParagraph paragraph = paragraphs.get(i);
@@ -460,15 +480,12 @@
*/
public void selectSheet() {
- File currentFile = ((CapraExcelRow) selection.get(0)).getFile();
-
- if (!Files.getFileExtension(currentFile.getAbsolutePath()).equals(CapraOfficeObject.XLSX)
- && !Files.getFileExtension(currentFile.getAbsolutePath()).equals(CapraOfficeObject.XLS))
+ if (selection.isEmpty())
return;
-
- parseExcelDocument(currentFile, SHEET_SELECT_REQUIRED);
-
- viewer.refresh();
+ else if (selection.get(0) instanceof CapraExcelRow) {
+ parseExcelDocument(selection.get(0).getFile(), SHEET_SELECT_REQUIRED);
+ viewer.refresh();
+ }
}
/**
@@ -486,6 +503,16 @@
return null;
}
+ public void refreshView() {
+
+ if (selection.isEmpty())
+ return;
+ else if (selection.get(0) instanceof CapraExcelRow)
+ parseExcelDocument(selection.get(0).getFile(), SHEET_SELECT_NOT_REQUIRED);
+
+ viewer.refresh();
+ }
+
private int showMessage(Shell parentShell, int style, String caption, String message) {
MessageBox dialog = new MessageBox(parentShell, style);
dialog.setText(caption);