Address Sonar issues in Office handling
This commit addresses several issues in the code for handling
Office and Google documents reported by Sonar. It also fixes a
bug that prevented the "Open File" dialog from showing if no
Office document was previously loaded via drag & drop.
In addition, the menu items in the menu to select a sheet
in an Excel file now behave correctly.
Change-Id: I5169ffbb14101e0082ea380baa72c0b03976b28f
diff --git a/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java b/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
index e8366a5..1712279 100644
--- a/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
+++ b/bundles/org.eclipse.capra.handler.office/src/org/eclipse/capra/handler/office/OfficeHandler.java
@@ -39,9 +39,8 @@
// Returns the EObject corresponding to the input object if the input is
// an EObject, or if it is Adaptable to an EObject
ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get();
- EObject wrapper = adapter.createArtifact(artifactModel, this.getClass().getName(), officeObject.getUri(),
+ return adapter.createArtifact(artifactModel, this.getClass().getName(), officeObject.getUri(),
this.getDisplayName(officeObject), officeObject.getUri());
- return wrapper;
}
@Override
@@ -69,7 +68,7 @@
@Override
public String generateMarkerMessage(org.eclipse.core.resources.IResourceDelta delta, String wrapperUri) {
- // TODO Auto-generated method stub
+ // We do not generate markers for Office documents.
return null;
}
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/exceptions/CapraOfficeFileNotSupportedException.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/exceptions/CapraOfficeFileNotSupportedException.java
index 2805da5..7713ea0 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/exceptions/CapraOfficeFileNotSupportedException.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/exceptions/CapraOfficeFileNotSupportedException.java
@@ -24,14 +24,13 @@
public class CapraOfficeFileNotSupportedException extends Exception {
private static final long serialVersionUID = -7730053652692861930L;
- private static final String EXCEPTION_MESSAGE = "%s file type is not supported.";
+ private static final String EXCEPTION_MESSAGE = "File type %s is not supported.";
/**
* A default constructor.
*
- * @param fileType
- * the type of the non-supported file that was dragged/put into
- * the Office view
+ * @param fileType the type of the non-supported file that was dragged/put into
+ * the Office view
*/
public CapraOfficeFileNotSupportedException(String fileType) {
super(String.format(EXCEPTION_MESSAGE, fileType));
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraExcelRow.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraExcelRow.java
index 0d49c51..4bea427 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraExcelRow.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraExcelRow.java
@@ -26,12 +26,12 @@
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.eclipse.capra.ui.office.exceptions.CapraOfficeObjectNotFound;
import org.eclipse.capra.ui.office.preferences.OfficePreferences;
@@ -56,8 +56,8 @@
private static final Logger LOG = LoggerFactory.getLogger(CapraExcelRow.class);
/**
- * RegEx of characters (tabs, newlines, carriage returns and invisible
- * control characters) to be replaced with white-spaces in the Office View.
+ * RegEx of characters (tabs, newlines, carriage returns and invisible control
+ * characters) to be replaced with white-spaces in the Office View.
*/
private static final String LINE_BREAKS_AND_CONTROL_REQ = "[\r\n\t\\p{C}]+";
@@ -80,24 +80,21 @@
private static final String NO_LAST_CELL_REFERENCE = "-1";
/**
- * The ID of the column that is used to extract the identifier of the row
- * (if value is OfficePreferences.EXCEL_COLUMN_VALUE_DEFAULT, line numbers
- * are used as identifiers). The property is set according to the value in
- * the Capra preference page in Eclipse preferences.
+ * The ID of the column that is used to extract the identifier of the row (if
+ * value is OfficePreferences.EXCEL_COLUMN_VALUE_DEFAULT, line numbers are used
+ * as identifiers). The property is set according to the value in the Capra
+ * preference page in Eclipse preferences.
*/
private String idColumn;
/**
- * A constructor that generates a new instance of CapraExcelRow where the
- * parent properties are extracted from the provided Excel row and File
- * object that contains the row.
+ * A constructor that generates a new instance of CapraExcelRow where the parent
+ * properties are extracted from the provided Excel row and File object that
+ * contains the row.
*
- * @param officeFile
- * a File object representing an Excel file.
- * @param row
- * an Excel row, extracted from the provided Excel file.
- * @param idColumn
- * the excel column that is used to extract the ID of the row
+ * @param officeFile a File object representing an Excel file.
+ * @param row an Excel row, extracted from the provided Excel file.
+ * @param idColumn the excel column that is used to extract the ID of the row
*/
public CapraExcelRow(File officeFile, Row row, String idColumn) {
super();
@@ -230,14 +227,13 @@
Desktop.getDesktop().open(getFile());
} catch (IOException e) {
LOG.debug("Could not open file.", e);
- return;
}
}
/**
- * Extracts the name of the sheet (from the URI of the object) which the
- * object is associated with. The URI of the object should always be in the
- * format fileId + DELIMITER + sheetName + DELIMITER + rowId.
+ * Extracts the name of the sheet (from the URI of the object) which the object
+ * is associated with. The URI of the object should always be in the format
+ * fileId + DELIMITER + sheetName + DELIMITER + rowId.
*
* @return name of the sheet
*/
@@ -248,9 +244,9 @@
}
/**
- * Extracts the ID of the row from the URI of the object. The URI of the
- * object should always be in the format fileId + DELIMITER + sheetName +
- * DELIMITER + rowId.
+ * Extracts the ID of the row from the URI of the object. The URI of the object
+ * should always be in the format fileId + DELIMITER + sheetName + DELIMITER +
+ * rowId.
*
* @return ID of the row
*/
@@ -261,17 +257,16 @@
}
/**
- * Extracts the ID of the Excel row (not CapraExcelRow!) based on the
- * idColumn value. If the value of idColumn is EXCEL_COLUMN_VALUE_DEFAULT,
- * then rowID is the same as row number, otherwise a specific column
- * (defined by idColumn property - such as A1) is used to extract the data
- * that will serve as the ID of the row.
+ * Extracts the ID of the Excel row (not CapraExcelRow!) based on the idColumn
+ * value. If the value of idColumn is EXCEL_COLUMN_VALUE_DEFAULT, then rowID is
+ * the same as row number, otherwise a specific column (defined by idColumn
+ * property - such as A1) is used to extract the data that will serve as the ID
+ * of the row.
*
- * @param row
- * the row to identify
+ * @param row the row to identify
* @return the ID of the row
*/
- final protected String getRowIdFromExcelRow(Row row) {
+ protected final String getRowIdFromExcelRow(Row row) {
String rowId = "";
if (idColumn.equals(OfficePreferences.EXCEL_COLUMN_VALUE_DEFAULT)) {
rowId = Integer.toString(row.getRowNum() + 1);
@@ -305,5 +300,5 @@
return false;
return true;
}
-
+
}
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraOfficeObject.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraOfficeObject.java
index ab09851..71be1ec 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraOfficeObject.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/model/CapraOfficeObject.java
@@ -31,7 +31,7 @@
*
*/
public class CapraOfficeObject {
-
+
private static final Logger LOG = LoggerFactory.getLogger(CapraOfficeObject.class);
/**
@@ -101,17 +101,16 @@
}
/**
- * Returns the ID of the OfficeObject from its URI. The format of the URI
- * should always be fileId + DELIMITER + objectId.
+ * Returns the ID of the OfficeObject from its URI. The format of the URI should
+ * always be fileId + DELIMITER + objectId.
*/
public String getId() {
- int firstDelimiterIndex = uri.indexOf(URI_DELIMITER);
- return uri.substring(firstDelimiterIndex + URI_DELIMITER.length());
+ return getObjectIdFromUri(this.uri);
}
/**
- * Returns the File reference of the file that contains the OfficeObject.
- * The format of the URI should always be fileId + DELIMITER + objectId.
+ * Returns the File reference of the file that contains the OfficeObject. The
+ * format of the URI should always be fileId + DELIMITER + objectId.
*/
public File getFile() throws NoSuchFileException {
String fileId = getFileId();
@@ -124,8 +123,8 @@
}
/**
- * Returns the ID of the file - the first part of the URI. The format of the
- * URI should always be fileId + DELIMITER + objectId.
+ * Returns the ID of the file - the first part of the URI. The format of the URI
+ * should always be fileId + DELIMITER + objectId.
*/
public String getFileId() {
int firstDelimiterIndex = uri.indexOf(URI_DELIMITER);
@@ -133,11 +132,10 @@
}
/**
- * Extracts the objectId from the provided CapraOfficeObject uri. The format
- * of the URI should always be fileId + DELIMITER + objectId.
+ * Extracts the objectId from the provided CapraOfficeObject uri. The format of
+ * the URI should always be fileId + DELIMITER + objectId.
*
- * @param uri
- * uri of the object
+ * @param uri uri of the object
* @return ID of the object
*/
public static String getObjectIdFromUri(String uri) {
@@ -146,11 +144,10 @@
}
/**
- * Extracts the fileId from the provided CapraOfficeObject uri. The format
- * of the URI should always be fileId + DELIMITER + objectId.
+ * Extracts the fileId from the provided CapraOfficeObject uri. The format of
+ * the URI should always be fileId + DELIMITER + objectId.
*
- * @param uri
- * uri of the object
+ * @param uri uri of the object
* @return file-path of the file that contains the object
*/
public static String getFileIdFromUri(String uri) {
@@ -168,19 +165,16 @@
try {
Desktop.getDesktop().open(getFile());
} catch (IOException e) {
- LOG.error("Could not oben office file.", e);
throw new CapraOfficeObjectNotFound(getId(), e);
}
}
/**
- * Generates a uri given the fileId of the file that contains the object and
- * an objectId.
+ * Generates a uri given the fileId of the file that contains the object and an
+ * objectId.
*
- * @param fileId
- * ID of the file that contains the object with objectId
- * @param objectID
- * ID of the object
+ * @param fileId ID of the file that contains the object with objectId
+ * @param objectID ID of the object
* @return a uri of the object in the form of filePath/objectID
*/
public static String createUri(String fileId, String objectId) {
@@ -198,6 +192,7 @@
/**
* Provides the hash code of the OfficeObject.
*/
+ @Override
public int hashCode() {
final int prime = 31;
int result = 1;
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
index 8f2493c..8b35d55 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/OfficePreferences.java
@@ -201,6 +201,7 @@
@Override
public void widgetDefaultSelected(SelectionEvent e) {
+ // We do not need to respond to this event.
}
});
@@ -214,6 +215,7 @@
@Override
public void widgetDefaultSelected(SelectionEvent e) {
+ // We do not need to respond to this event.
}
});
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
index b726176..8404717 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/preferences/PreferenceInitializer.java
@@ -27,9 +27,6 @@
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
- public PreferenceInitializer() {
- }
-
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/CapraOfficeUtils.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/CapraOfficeUtils.java
index b9c1d0f..0dc32a4 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/CapraOfficeUtils.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/CapraOfficeUtils.java
@@ -54,13 +54,12 @@
/**
* Hide default constructor.
*/
- private CapraOfficeUtils () {
+ private CapraOfficeUtils() {
super();
}
/**
- * Generates a HashMap that contains sheet names and info about their
- * emptiness:
+ * Generates a HashMap that contains sheet names and info about their emptiness:
* <ul>
* <li>keySet (String) - names of all the sheets, contained in the selected
* workbook</li>
@@ -68,14 +67,13 @@
* not</li>
* </ul>
*
- * @param workBook
- * an Excel Workbook object
- * @return a <code>Map</code> that contains the names (<code>String</code>) of all the sheets,
- * contained in the selected workbook and information about whether
- * they are empty or not (<code>Boolean</code>).
+ * @param workBook an Excel Workbook object
+ * @return a <code>Map</code> that contains the names (<code>String</code>) of
+ * all the sheets, contained in the selected workbook and information
+ * about whether they are empty or not (<code>Boolean</code>).
*/
public static Map<String, Boolean> getSheetsEmptinessInfo(Workbook workBook) {
- HashMap<String, Boolean> isSheetEmptyMap = new HashMap<String, Boolean>();
+ HashMap<String, Boolean> isSheetEmptyMap = new HashMap<>();
for (int i = 0; i < workBook.getNumberOfSheets(); i++) {
Sheet s = workBook.getSheetAt(i);
isSheetEmptyMap.put(s.getSheetName(), s.getLastRowNum() < 1);
@@ -87,10 +85,8 @@
* Gets the sheet with the provided sheetName from inside the provided Excel
* Workbook.
*
- * @param workBook
- * an Excel Workbook object
- * @param sheetName
- * the name of the sheet
+ * @param workBook an Excel Workbook object
+ * @param sheetName the name of the sheet
* @return the sheet with the provided sheetName from the provided workBook
* @throws NullPointerException
*/
@@ -122,8 +118,7 @@
/**
* Gets the Excel Workbook from the provided Excel file.
*
- * @param excelFile
- * a MS Excel file.
+ * @param excelFile a MS Excel file.
* @return an Excel Workbook object
* @throws OldExcelFormatException
* @throws IOException
@@ -137,16 +132,15 @@
} else {
workBook = new HSSFWorkbook(new FileInputStream(excelFile));
}
-
+
return workBook;
}
/**
- * Gets a list of paragraph objects that are contained in the provided MS
- * Word file.
+ * Gets a list of paragraph objects that are contained in the provided MS Word
+ * file.
*
- * @param wordFile
- * a MS Word file
+ * @param wordFile a MS Word file
* @return a list of XWPFParagraph objects that describe the paragraphs
* contained by the provided MS Word file.
* @throws SchemaTypeLoaderException
@@ -161,14 +155,16 @@
/**
* Creates a DOM document from the provided xml String.
*
- * @param xml
- * a valid XML String
+ * @param xml a valid XML String
* @return DOM document that describes the XML String
- * @throws ParserConfigurationException if a DocumentBuilder cannot be created which satisfies the configuration requested.
- * @throws IOException if any IO errors occur.
- * @throws SAXException if any parse error occurs
+ * @throws ParserConfigurationException if a DocumentBuilder cannot be created
+ * which satisfies the configuration
+ * requested.
+ * @throws IOException if any IO errors occur.
+ * @throws SAXException if any parse error occurs
*/
- public static Document createDOMDocument(String xml) throws ParserConfigurationException, SAXException, IOException {
+ public static Document createDOMDocument(String xml)
+ throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeSourceProvider.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeSourceProvider.java
index d38cff2..72fba82 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeSourceProvider.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeSourceProvider.java
@@ -34,8 +34,8 @@
public class OfficeSourceProvider extends AbstractSourceProvider {
/**
- * The ID of the variable that corresponds to the one in the plugin.xml and
- * is used to identify the resource that is being held by the class.
+ * The ID of the variable that corresponds to the one in the plugin.xml and is
+ * used to identify the resource that is being held by the class.
*/
public static final String CAPRA_OFFICE_OBJECT = "org.eclipse.capra.ui.office.utils.capraOfficeObject";
@@ -43,6 +43,7 @@
@Override
public void dispose() {
+ // Nothing to explicitly dispose here.
}
/**
@@ -57,7 +58,7 @@
@Override
public Map<String, CapraOfficeObject> getCurrentState() {
- HashMap<String, CapraOfficeObject> map = new HashMap<String, CapraOfficeObject>();
+ HashMap<String, CapraOfficeObject> map = new HashMap<>();
map.put(CAPRA_OFFICE_OBJECT, capraOfficeObject);
return map;
}
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeTransferType.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeTransferType.java
index e9f1745..bddaf87 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeTransferType.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/utils/OfficeTransferType.java
@@ -79,14 +79,9 @@
if (!(objectList.get(0) instanceof CapraOfficeObject)) {
return false;
}
-
ArrayList<CapraOfficeObject> officeObjects = (ArrayList<CapraOfficeObject>) object;
- if (officeObjects.isEmpty()) {
- return false;
- }
-
- return true;
+ return !officeObjects.isEmpty();
}
/** Converts a java byte[] to a platform specific representation. */
@@ -118,13 +113,13 @@
super.javaToNative(bufferOut, transferData);
} catch (IOException e) {
- LOG.warn("IOException occured when trying to convert office object to platform-specific representation: {}", e.getLocalizedMessage());
+ LOG.warn("IOException occured when trying to convert office object to platform-specific representation: {}",
+ e.getLocalizedMessage());
}
}
/**
- * Converts a platform specific representation of a byte array to a java
- * byte[].
+ * Converts a platform specific representation of a byte array to a java byte[].
*/
@Override
public Object nativeToJava(TransferData transferData) {
@@ -135,7 +130,7 @@
return null;
}
- ArrayList<CapraOfficeObject> officeObjects = new ArrayList<CapraOfficeObject>();
+ ArrayList<CapraOfficeObject> officeObjects = new ArrayList<>();
try (ByteArrayInputStream in = new ByteArrayInputStream(buffer);
DataInputStream readIn = new DataInputStream(in)) {
@@ -159,7 +154,9 @@
}
} catch (IOException e) {
- LOG.warn("IOException occured when trying to convert from platform-specific representation to office object: {}", e.getLocalizedMessage());
+ LOG.warn(
+ "IOException occured when trying to convert from platform-specific representation to office object: {}",
+ e.getLocalizedMessage());
return null;
}
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
index 981e7d2..939103b 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/OfficeView.java
@@ -118,7 +118,7 @@
/**
* The collection that contains the Excel/Word contents.
*/
- private List<CapraOfficeObject> selection = new ArrayList<CapraOfficeObject>();
+ private List<CapraOfficeObject> selection = new ArrayList<>();
/**
* The names (String) of all the sheets, contained in the selected workbook and
@@ -154,10 +154,12 @@
class ViewContentProvider implements IStructuredContentProvider {
@Override
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+ // We do not need to react to this event.
}
@Override
public void dispose() {
+ // Nothing to dispose here.
}
@Override
@@ -180,7 +182,7 @@
text = text.substring(0, textLength) + "...";
}
return text;
- };
+ }
@Override
public String getColumnText(Object obj, int index) {
@@ -212,7 +214,7 @@
try {
if (data instanceof String[]) {
File file = new File(((String[]) data)[0]);
- if (file != null && file.exists()) {
+ if (file.exists()) {
parseGenericFile(file);
}
}
@@ -235,19 +237,19 @@
*/
private static class SelectionDragAdapter extends ViewerDragAdapter {
- private TableViewer viewer;
+ private TableViewer tableViewer;
public SelectionDragAdapter(TableViewer viewer) {
super(viewer);
- this.viewer = viewer;
+ this.tableViewer = viewer;
}
@Override
public void dragSetData(DragSourceEvent event) {
if (OfficeTransferType.getInstance().isSupportedType(event.dataType)) {
- TableItem[] items = viewer.getTable().getSelection();
- ArrayList<CapraOfficeObject> officeObjects = new ArrayList<CapraOfficeObject>();
+ TableItem[] items = tableViewer.getTable().getSelection();
+ ArrayList<CapraOfficeObject> officeObjects = new ArrayList<>();
for (int i = 0; i < items.length; i++) {
officeObjects.add((CapraOfficeObject) items[i].getData());
@@ -415,11 +417,7 @@
List<XWPFParagraph> paragraphs;
try {
paragraphs = CapraOfficeUtils.getWordParagraphs(officeFile);
- } catch (IOException e) {
- LOG.debug("Could not read Word file.", e);
- showErrorMessage(ERROR_TITLE, e.getMessage(), null);
- return;
- } catch (SchemaTypeLoaderException e) {
+ } catch (IOException | SchemaTypeLoaderException e) {
LOG.debug("Could not read Word file.", e);
showErrorMessage(ERROR_TITLE, e.getMessage(), null);
return;
@@ -513,13 +511,12 @@
* of type xlsx, xls or docx).
*/
public void openFile() {
-
- FileDialog fd = new FileDialog(viewer.getControl().getShell(), SWT.OK);
+ FileDialog fd = new FileDialog(this.getSite().getShell(), SWT.OK);
String filePath = fd.open();
if (filePath != null && !filePath.isEmpty()) {
File file = new File(filePath);
- if (file != null && file.exists()) {
+ if (file.exists()) {
try {
parseGenericFile(file);
} catch (CapraOfficeFileNotSupportedException e) {
@@ -536,9 +533,7 @@
* @param sheetName the name of the sheet to be displayed in the Office view.
*/
public void displaySheet(String sheetName) {
- if (selection.isEmpty()) {
- return;
- } else if (selection.get(0) instanceof CapraExcelRow) {
+ if (!selection.isEmpty() && selection.get(0) instanceof CapraExcelRow) {
parseExcelDocument(selectedFile, selectedFileId, sheetName);
}
}
@@ -553,7 +548,7 @@
public Map<String, Boolean> getIsSheetEmptyMap() {
// isSheetEmptyMap is used by the SelectSheetDynamicMenu class.
- if (isSheetEmptyMap == null && selection.size() > 0) {
+ if (isSheetEmptyMap == null && !selection.isEmpty()) {
try {
isSheetEmptyMap = CapraOfficeUtils.getSheetsEmptinessInfo(
CapraOfficeUtils.getExcelWorkbook(((CapraExcelRow) (selection.get(0))).getFile()));
@@ -613,6 +608,7 @@
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
+ // Nothing to do for us here.
}
});
Menu menu = menuMgr.createContextMenu(viewer.getControl());
@@ -688,9 +684,9 @@
Desktop.getDesktop().browse(new URI(url));
HyperlinkDialog.this.okPressed();
} catch (IOException e1) {
- LOG.info("No default browser found.", e);
+ LOG.info("No default browser found.", e1);
} catch (URISyntaxException e1) {
- LOG.info("Provided malformed URI.", e);
+ LOG.info("Provided malformed URI.", e1);
}
}
});
diff --git a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/SelectSheetDynamicMenu.java b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/SelectSheetDynamicMenu.java
index e742e32..565a262 100644
--- a/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/SelectSheetDynamicMenu.java
+++ b/bundles/org.eclipse.capra.ui.office/src/org/eclipse/capra/ui/office/views/SelectSheetDynamicMenu.java
@@ -44,8 +44,8 @@
// Add sheetNames to the dynamic context menu and make them
// un-selectable if they are empty
- for (String sheetName : isSheetEmptyMap.keySet()) {
- MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
+ for (Map.Entry<String, Boolean> sheet : isSheetEmptyMap.entrySet()) {
+ MenuItem menuItem = new MenuItem(menu, SWT.RADIO, index);
menuItem.addSelectionListener(new SelectionListener() {
@@ -60,13 +60,13 @@
}
});
- if (OfficeView.getOpenedView().getSelectedSheetName().contentEquals(sheetName)) {
+ if (OfficeView.getOpenedView().getSelectedSheetName().contentEquals(sheet.getKey())) {
menuItem.setSelection(true);
}
- if (!isSheetEmptyMap.get(sheetName)) {
- menuItem.setText(sheetName);
+ if (Boolean.FALSE.equals(sheet.getValue())) {
+ menuItem.setText(sheet.getKey());
} else {
- menuItem.setText(sheetName + " (Empty)");
+ menuItem.setText(sheet.getKey() + " (Empty)");
menuItem.setEnabled(false);
}
}