Merge "Omaha #4541 - Fixed NPE for protected files." into omaha_16.1.1
Former-commit-id: c6eecf39975fc9500a7fc61e7da6f7784a42861f
This commit is contained in:
commit
741ee5f1e7
1 changed files with 44 additions and 33 deletions
|
@ -51,7 +51,8 @@ import com.raytheon.viz.ui.VizWorkbenchManager;
|
||||||
*
|
*
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
* Nov 1, 2011 mschenke Initial creation
|
* Nov 1, 2011 mschenke Initial creation
|
||||||
|
* Jun 11, 2015 4541 skorolev Added NULL test for lf.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -69,11 +70,11 @@ public class ImportFileAction extends Action {
|
||||||
|
|
||||||
private static final String ASTERISK = "*";
|
private static final String ASTERISK = "*";
|
||||||
|
|
||||||
private String directoryPath;
|
private final String directoryPath;
|
||||||
|
|
||||||
private LocalizationType contextType;
|
private final LocalizationType contextType;
|
||||||
|
|
||||||
private String[] fileExtensionFilterArr;
|
private String[] fileExtensionFilterArr;
|
||||||
|
|
||||||
public ImportFileAction(LocalizationType contextType, String directoryPath) {
|
public ImportFileAction(LocalizationType contextType, String directoryPath) {
|
||||||
super("Import File...");
|
super("Import File...");
|
||||||
|
@ -81,22 +82,23 @@ public class ImportFileAction extends Action {
|
||||||
this.directoryPath = directoryPath;
|
this.directoryPath = directoryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImportFileAction(LocalizationType contextType, String directoryPath, String[] filter) {
|
public ImportFileAction(LocalizationType contextType, String directoryPath,
|
||||||
this(contextType, directoryPath);
|
String[] filter) {
|
||||||
if (filter != null) {
|
this(contextType, directoryPath);
|
||||||
this.fileExtensionFilterArr = new String[filter.length];
|
if (filter != null) {
|
||||||
for (int i = 0; i < filter.length; ++i) {
|
this.fileExtensionFilterArr = new String[filter.length];
|
||||||
if (filter[i] != null && filter[i].startsWith(".")) {
|
for (int i = 0; i < filter.length; ++i) {
|
||||||
// prepend an asterisk as required by FileDialog.
|
if (filter[i] != null && filter[i].startsWith(".")) {
|
||||||
this.fileExtensionFilterArr[i] = ASTERISK + filter[i];
|
// prepend an asterisk as required by FileDialog.
|
||||||
} else {
|
this.fileExtensionFilterArr[i] = ASTERISK + filter[i];
|
||||||
this.fileExtensionFilterArr[i] = filter[i];
|
} else {
|
||||||
}
|
this.fileExtensionFilterArr[i] = filter[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see org.eclipse.jface.action.Action#run()
|
* @see org.eclipse.jface.action.Action#run()
|
||||||
|
@ -107,7 +109,7 @@ public class ImportFileAction extends Action {
|
||||||
.getShell();
|
.getShell();
|
||||||
FileDialog dialog = new FileDialog(parent);
|
FileDialog dialog = new FileDialog(parent);
|
||||||
if (fileExtensionFilterArr != null) {
|
if (fileExtensionFilterArr != null) {
|
||||||
dialog.setFilterExtensions(fileExtensionFilterArr);
|
dialog.setFilterExtensions(fileExtensionFilterArr);
|
||||||
}
|
}
|
||||||
String fileToImport = dialog.open();
|
String fileToImport = dialog.open();
|
||||||
if (fileToImport != null) {
|
if (fileToImport != null) {
|
||||||
|
@ -137,9 +139,16 @@ public class ImportFileAction extends Action {
|
||||||
LocalizationFile lf = pm.getLocalizationFile(
|
LocalizationFile lf = pm.getLocalizationFile(
|
||||||
pm.getContext(contextType, LocalizationLevel.USER),
|
pm.getContext(contextType, LocalizationLevel.USER),
|
||||||
newFilePath);
|
newFilePath);
|
||||||
localizationFiles.add(lf);
|
if ((lf != null) && !lf.isProtected()) {
|
||||||
if (lf.exists()) {
|
localizationFiles.add(lf);
|
||||||
existing.add(lf);
|
if (lf.exists()) {
|
||||||
|
existing.add(lf);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statusHandler
|
||||||
|
.handle(Priority.WARN,
|
||||||
|
newFilePath
|
||||||
|
+ " is protected. A user level version of this file is not allowed to be created.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,14 +173,16 @@ public class ImportFileAction extends Action {
|
||||||
int addCount = 0;
|
int addCount = 0;
|
||||||
for (int i = 0; i < applicable.size(); ++i) {
|
for (int i = 0; i < applicable.size(); ++i) {
|
||||||
File importFile = applicable.get(i);
|
File importFile = applicable.get(i);
|
||||||
LocalizationFile lf = localizationFiles.get(i);
|
if (!localizationFiles.isEmpty()) {
|
||||||
if (skip.contains(lf) == false) {
|
LocalizationFile lf = localizationFiles.get(i);
|
||||||
try {
|
if (skip.contains(lf) == false) {
|
||||||
lf.write(FileUtil.file2bytes(importFile));
|
try {
|
||||||
++addCount;
|
lf.write(FileUtil.file2bytes(importFile));
|
||||||
} catch (Exception e) {
|
++addCount;
|
||||||
statusHandler.handle(Priority.PROBLEM,
|
} catch (Exception e) {
|
||||||
"Error importing file into localization", e);
|
statusHandler.handle(Priority.PROBLEM,
|
||||||
|
"Error importing file into localization", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,9 +191,9 @@ public class ImportFileAction extends Action {
|
||||||
|
|
||||||
private static class MultiConfirmDialog extends MessageDialog {
|
private static class MultiConfirmDialog extends MessageDialog {
|
||||||
|
|
||||||
private List<LocalizationFile> confirmedFiles;
|
private final List<LocalizationFile> confirmedFiles;
|
||||||
|
|
||||||
private List<LocalizationFile> existingFiles;
|
private final List<LocalizationFile> existingFiles;
|
||||||
|
|
||||||
private int curIdx = 0;
|
private int curIdx = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue