From d9d6e7ffbf1b1e581bf6c6fb9404f24d9031e973 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Tue, 13 Oct 2015 16:19:24 -0500 Subject: [PATCH] Omaha #4410 Allow localization perspective to mix files for multiple Localization Types. Former-commit-id: aca2b3fa1fe242b4fb93f68808be7fa67566c268 --- .../perspective/view/FileTreeView.java | 94 +++++++++++++------ .../view/LocalizationFileDragNDropSource.java | 42 +++++---- .../perspective/view/PathDataExtManager.java | 19 ++-- .../view/actions/CopyToAction.java | 85 +++++++++++------ .../view/actions/ImportFileAction.java | 80 +++++++++------- .../view/actions/MoveFileAction.java | 26 +++-- .../view/actions/PasteFileAction.java | 32 +++---- .../view/actions/RenameAction.java | 15 ++- 8 files changed, 243 insertions(+), 150 deletions(-) diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/FileTreeView.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/FileTreeView.java index b904862c98..aa4c178961 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/FileTreeView.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/FileTreeView.java @@ -140,6 +140,9 @@ import com.raytheon.uf.viz.localization.service.ILocalizationService; * Feb 06, 2015 4028 mapeters fixed file selection issue when reopening CAVE with files open * Apr 02, 2015 4288 randerso Fix Widget is disposed error * Aug 24, 2015 4393 njensen Updates for observer changes + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. + * * * * @@ -859,7 +862,6 @@ public class FileTreeView extends ViewPart implements IPartListener2, // Add Copy/Paste/Delete if ((fileList.size() == 1) && (selected.length == 1)) { - LocalizationFile selectedFile = fileList.get(0); mgr.add(new Action("Copy") { @Override public void run() { @@ -867,7 +869,7 @@ public class FileTreeView extends ViewPart implements IPartListener2, } }); - mgr.add(new CopyToAction(selectedFile, this)); + mgr.add(new CopyToAction(fileDataList.get(0), this)); mgr.add(new DeleteAction(getSite().getPage(), fileList .toArray(new LocalizationFile[fileList.size()]))); @@ -919,9 +921,9 @@ public class FileTreeView extends ViewPart implements IPartListener2, } // Add the move to item - if ((selected.length == 1) && (fileList.size() == 1)) { - mgr.add(new MoveFileAction(getSite().getPage(), fileList.get(0), - this)); + if ((selected.length == 1) && (fileDataList.size() == 1)) { + mgr.add(new MoveFileAction(getSite().getPage(), + fileDataList.get(0), this)); mgr.add(new Separator()); } @@ -966,8 +968,9 @@ public class FileTreeView extends ViewPart implements IPartListener2, if (fdata.isDirectory()) { // We can import into true directories, not group datas mgr.add(new Separator()); - mgr.add(new ImportFileAction(fdata.getPathData().getType(), - fdata.getPath(), fdata.getPathData().getFilter())); + mgr.add(new ImportFileAction( + fdata.getPathData().getTypes(), fdata.getPath(), + fdata.getPathData().getFilter())); } } } @@ -1080,14 +1083,14 @@ public class FileTreeView extends ViewPart implements IPartListener2, String path = data.getPath(); String[] filter = pd.getFilter(); boolean recursive = pd.isRecursive(); - LocalizationType type = pd.getType(); + List types = pd.getTypes(); IPathManager pathManager = PathManagerFactory.getPathManager(); boolean success = false; List currentList = new ArrayList(); LocalizationFile[] files = pathManager.listFiles( - getTreeSearchContexts(type), path, filter, false, !recursive); + getTreeSearchContexts(types), path, filter, false, !recursive); if (files == null) { statusHandler.handle(Priority.PROBLEM, "Error getting list of files"); @@ -1119,16 +1122,19 @@ public class FileTreeView extends ViewPart implements IPartListener2, return success; } - private LocalizationContext[] getTreeSearchContexts(LocalizationType type) { + private LocalizationContext[] getTreeSearchContexts( + List types) { IPathManager pathManager = PathManagerFactory.getPathManager(); // Request for base/site/user - LocalizationContext[] searchHierarchy = pathManager - .getLocalSearchHierarchy(type); - List searchContexts = new ArrayList( - searchHierarchy.length); - for (LocalizationContext ctx : searchHierarchy) { - if (showSet.contains(ctx.getLocalizationLevel())) { - searchContexts.add(ctx); + + List searchContexts = new ArrayList(); + for (LocalizationType type : types) { + LocalizationContext[] searchHierarchy = pathManager + .getLocalSearchHierarchy(type); + for (LocalizationContext ctx : searchHierarchy) { + if (showSet.contains(ctx.getLocalizationLevel())) { + searchContexts.add(ctx); + } } } @@ -1152,11 +1158,12 @@ public class FileTreeView extends ViewPart implements IPartListener2, || ((myContext == null) && (context == null))) { continue; } - - LocalizationContext ctx = pathManager.getContext(type, - level); - ctx.setContextName(context); - searchContexts.add(ctx); + for (LocalizationType type : types) { + LocalizationContext ctx = pathManager.getContext(type, + level); + ctx.setContextName(context); + searchContexts.add(ctx); + } } } } @@ -1217,10 +1224,21 @@ public class FileTreeView extends ViewPart implements IPartListener2, fData.clearChildData(); fData.setRequestedChildren(true); PathData pd = fData.getPathData(); + Set levels = new HashSet<>(); + Set redundantLevels = new HashSet<>(); + for (LocalizationFile file : files) { + LocalizationLevel level = file.getContext().getLocalizationLevel(); + if (!levels.add(level)) { + redundantLevels.add(level); + } + } for (LocalizationFile file : files) { FileTreeEntryData treeData = null; if (!file.isDirectory()) { - treeData = new LocalizationFileEntryData(pd, file); + LocalizationLevel level = file.getContext() + .getLocalizationLevel(); + treeData = new LocalizationFileEntryData(pd, file, + redundantLevels.contains(level)); addTreeItem(parentItem, treeData); fData.addChildData((LocalizationFileEntryData) treeData); } @@ -1268,13 +1286,26 @@ public class FileTreeView extends ViewPart implements IPartListener2, LocalizationFile file = null; int idx = parentItem.getItemCount(); if (treeData instanceof LocalizationFileEntryData) { - file = ((LocalizationFileEntryData) treeData).getFile(); + LocalizationFileEntryData entryData = (LocalizationFileEntryData) treeData; + file = entryData.getFile(); LocalizationContext ctx = file.getContext(); LocalizationLevel level = ctx.getLocalizationLevel(); - name = level.toString(); - if (level != LocalizationLevel.BASE) { - name += " (" + ctx.getContextName() + ")"; + StringBuilder nameBuilder = new StringBuilder(level.toString()); + if (entryData.isMultipleTypes() || level != LocalizationLevel.BASE) { + nameBuilder.append(" ("); + if (level != LocalizationLevel.BASE) { + nameBuilder.append(ctx.getContextName()); + } + if (entryData.isMultipleTypes()) { + if (level != LocalizationLevel.BASE) { + nameBuilder.append(" - "); + } + nameBuilder.append(ctx.getLocalizationType().name() + .toLowerCase()); + } + nameBuilder.append(")"); } + name = nameBuilder.toString(); } else { List applicableItems = new ArrayList(); int start = -1; @@ -1318,9 +1349,10 @@ public class FileTreeView extends ViewPart implements IPartListener2, IFolder folder = (IFolder) parentData.getResource(); IResource rsc = null; if (file != null) { - rsc = folder.getFile(file.getContext().getLocalizationLevel() + "_" - + file.getContext().getContextName() + "_" - + parentItem.getText()); + LocalizationContext context = file.getContext(); + rsc = folder.getFile(context.getLocalizationType() + "_" + + context.getLocalizationLevel() + "_" + + context.getContextName() + "_" + parentItem.getText()); } else { rsc = createFolder(folder, fileItem.getText()); } @@ -1465,7 +1497,7 @@ public class FileTreeView extends ViewPart implements IPartListener2, private TreeItem find(TreeItem item, LocalizationContext ctx, java.nio.file.Path path, boolean populateToFind) { FileTreeEntryData data = (FileTreeEntryData) item.getData(); - if (data.getPathData().getType() == ctx.getLocalizationType()) { + if (data.getPathData().getTypes().contains(ctx.getLocalizationType())) { java.nio.file.Path itemPath = Paths.get(data.getPath()); if (path.startsWith(itemPath)) { if (path.equals(itemPath) diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/LocalizationFileDragNDropSource.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/LocalizationFileDragNDropSource.java index ce78272941..2f727920c2 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/LocalizationFileDragNDropSource.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/LocalizationFileDragNDropSource.java @@ -21,6 +21,7 @@ package com.raytheon.uf.viz.localization.perspective.view; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -43,6 +44,8 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationUtil; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; +import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; import com.raytheon.uf.common.localization.msgs.ListResponseEntry; import com.raytheon.uf.common.status.UFStatus; @@ -63,7 +66,10 @@ import com.raytheon.uf.viz.localization.perspective.view.actions.ImportFileActio * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Jul 1, 2011 mschenke Initial creation + * Jul 1, 2011 mschenke Initial creation + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. + * * * * @@ -144,7 +150,7 @@ public class LocalizationFileDragNDropSource extends ViewerDropAdapter for (int i = 0; i < paths.length; ++i) { files[i] = new File(paths[i]); } - boolean rval = dropFile(data.getPathData().getType(), + boolean rval = dropFile(data.getPathData().getTypes(), data.getPath(), files); if (rval) { toDelete = potentialDelete; @@ -152,8 +158,8 @@ public class LocalizationFileDragNDropSource extends ViewerDropAdapter // Dragging from somewhere outside of FileTreeView IPathManager pm = PathManagerFactory.getPathManager(); view.refresh(pm.getLocalizationFile(pm.getContext(data - .getPathData().getType(), LocalizationLevel.BASE), - data.getPath())); + .getPathData().getTypes().get(0), + LocalizationLevel.BASE), data.getPath())); } } return rval; @@ -192,9 +198,12 @@ public class LocalizationFileDragNDropSource extends ViewerDropAdapter toMoveData.getContext(), toMoveData.getFileName()); String fileName = LocalizationUtil.extractName(toMove.getName()); String newName = data.getPath() + File.separator + fileName; + LocalizationType type = toMove.getContext().getLocalizationType(); + if (!data.getPathData().getTypes().contains(type)) { + type = data.getPathData().getTypes().get(0); + } final LocalizationFile moveTo = pm.getLocalizationFile(pm.getContext( - data.getPathData().getType(), toMoveData.getContext() - .getLocalizationLevel()), newName); + type, toMoveData.getContext().getLocalizationLevel()), newName); boolean move = true; if (moveTo.exists()) { move = MessageDialog.openQuestion(view.getSite().getShell(), @@ -227,23 +236,20 @@ public class LocalizationFileDragNDropSource extends ViewerDropAdapter } else { VizApp.runAsync(select); } - try { - FileUtil.copyFile(toMove.getFile(), moveTo.getFile()); - if (moveTo.save()) { - return true; - } - } catch (IOException e) { + try (InputStream is = toMove.openInputStream(); + SaveableOutputStream os = moveTo.openOutputStream()) { + FileUtil.copy(is, os); + os.save(); + return true; + } catch (IOException | LocalizationException e) { UFStatus.getHandler().handle(Priority.PROBLEM, "Error copying file contents", e); - } catch (LocalizationOpFailedException e) { - UFStatus.getHandler().handle(Priority.PROBLEM, - "Error saving file contents", e); } } return false; } - private boolean dropFile(LocalizationType type, String dirPath, + private boolean dropFile(List types, String dirPath, File[] toCopyFiles) { boolean oneGood = false; List files = new ArrayList(toCopyFiles.length); @@ -260,14 +266,14 @@ public class LocalizationFileDragNDropSource extends ViewerDropAdapter } if (files.size() > 0) { - if (ImportFileAction.importFile(type, dirPath, + if (ImportFileAction.importFile(types, dirPath, files.toArray(new File[files.size()]))) { oneGood = true; } } for (File dir : directories) { - if (dropFile(type, + if (dropFile(types, dirPath + IPathManager.SEPARATOR + dir.getName(), dir.listFiles())) { oneGood = true; diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/PathDataExtManager.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/PathDataExtManager.java index 2052f40654..3f047f0f9a 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/PathDataExtManager.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/PathDataExtManager.java @@ -46,7 +46,9 @@ import com.raytheon.uf.viz.localization.filetreeview.PathData; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Sep 7, 2012 mschenke Initial creation + * Sep 7, 2012 mschenke Initial creation + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. * * * @@ -108,14 +110,14 @@ public class PathDataExtManager { statusHandler .handle(Priority.PROBLEM, "Skipping path extension entry with no path set"); + continue; } pd.setFilter(element.getAttribute(FILTER_ATTR)); String recurse = element.getAttribute(RECURSIVE_ATTR); pd.setRecursive(Boolean.parseBoolean(recurse)); - pd.setType(LocalizationType.valueOf(element - .getAttribute(TYPE_ATTR))); - if (pd.getType() == null) { + String typesString = element.getAttribute(TYPE_ATTR); + if (typesString == null) { // Skip if bad localization type specified statusHandler.handle( Priority.PROBLEM, @@ -126,6 +128,11 @@ public class PathDataExtManager { + element.getAttribute(TYPE_ATTR)); continue; } + List types = new ArrayList<>(); + for (String typeString : typesString.split(",")) { + types.add(LocalizationType.valueOf(typeString)); + } + pd.setTypes(types); LocalizationPerspectiveAdapter adapter = DEFAULT_ADAPTER; try { if (element.getAttribute(ADAPTER_ATTR) != null) { @@ -135,11 +142,11 @@ public class PathDataExtManager { } catch (Throwable t) { statusHandler .handle(Priority.PROBLEM, - "Skipping path with name: " + "Error constructing adapter for path with name: " + pd.getName() + " and path: " + pd.getPath() - + " due to error constructing adapter: " + + " the default adapter will be used: " + t.getLocalizedMessage(), t); } pd.setAdapter(adapter); diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/CopyToAction.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/CopyToAction.java index 96c8754f46..05a173c3e5 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/CopyToAction.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/CopyToAction.java @@ -19,23 +19,29 @@ **/ package com.raytheon.uf.viz.localization.perspective.view.actions; -import java.io.File; import java.io.IOException; +import java.io.InputStream; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.Separator; import org.eclipse.swt.widgets.Menu; +import com.raytheon.uf.common.localization.ILocalizationFile; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; +import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.util.FileUtil; +import com.raytheon.uf.viz.localization.filetreeview.LocalizationFileEntryData; +import com.raytheon.uf.viz.localization.filetreeview.PathData; import com.raytheon.uf.viz.localization.service.ILocalizationService; /** @@ -48,7 +54,9 @@ import com.raytheon.uf.viz.localization.service.ILocalizationService; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Nov 3, 2010 mschenke Initial creation + * Nov 3, 2010 mschenke Initial creation + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. * * * @@ -60,11 +68,20 @@ public class CopyToAction extends AbstractToAction { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(CopyToAction.class); - protected ILocalizationService service; + protected final ILocalizationService service; - public CopyToAction(LocalizationFile file, ILocalizationService service) { + protected final PathData pathData; + + public CopyToAction(LocalizationFile file, PathData pathData, + ILocalizationService service) { super("Copy To", file); this.service = service; + this.pathData = pathData; + } + + public CopyToAction(LocalizationFileEntryData data, + ILocalizationService service) { + this(data.getFile(), data.getPathData(), service); } /* @@ -97,44 +114,50 @@ public class CopyToAction extends AbstractToAction { @Override protected void run(LocalizationLevel level) { IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationFile newFile = pm.getLocalizationFile( + ILocalizationFile newFile = pm.getLocalizationFile( pm.getContext(file.getContext().getLocalizationType(), level), file.getName()); + removeAlternateTypeFiles(level); copyFile(newFile); } - protected boolean copyFile(LocalizationFile newFile) { - File copyTo = newFile.getFile(); - File copyFrom = file.getFile(); + /** + * If it is possible for the target to exist for multiple localization types + * then delete any others that exist at the selected level so there are not + * multiple files at the same level after the operation completes. + * + * @param level + */ + protected void removeAlternateTypeFiles(LocalizationLevel level) { + IPathManager pm = PathManagerFactory.getPathManager(); - // Delete local copy of existing contents - copyTo.delete(); - // Make sure parent directories exist - if (copyTo.getParentFile().exists() == false) { - copyTo.getParentFile().mkdirs(); + for (LocalizationType type : pathData.getTypes()) { + if (type != file.getContext().getLocalizationType()) { + LocalizationFile altFile = pm.getLocalizationFile( + pm.getContext(type, level), file.getName()); + if (altFile.exists()) { + try { + altFile.delete(); + } catch (LocalizationOpFailedException e) { + statusHandler.handle(Priority.PROBLEM, + "Unable to delete existing " + type.name() + + " " + level + " file.", e); + } + } + } } + } - try { - // Copy file contents locally - FileUtil.copyFile(copyFrom, copyTo); - } catch (IOException e) { + protected boolean copyFile(ILocalizationFile newFile) { + try (InputStream is = file.openInputStream(); + SaveableOutputStream os = newFile.openOutputStream()) { + FileUtil.copy(is, os); + os.save(); + return true; + } catch (LocalizationException | IOException e) { statusHandler .handle(Priority.PROBLEM, "Error copying file contents of " + file + " to " + newFile, e); - return false; - } - - try { - // Save localization file with new contents - boolean rval = newFile.save(); - if (!rval) { - // If failed, make sure we get the latest file - newFile.getFile(); - } - return rval; - } catch (LocalizationOpFailedException e) { - statusHandler.handle(Priority.PROBLEM, "Error saving " + newFile - + ": " + e.getLocalizedMessage(), e); } return false; } diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/ImportFileAction.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/ImportFileAction.java index 14a5b0fed6..8fe13d2983 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/ImportFileAction.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/ImportFileAction.java @@ -31,11 +31,13 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; +import com.raytheon.uf.common.localization.ILocalizationFile; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -51,8 +53,10 @@ import com.raytheon.viz.ui.VizWorkbenchManager; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Nov 1, 2011 mschenke Initial creation - * Jun 11, 2015 4541 skorolev Added NULL test for lf. + * Nov 1, 2011 mschenke Initial creation + * Jun 11, 2015 4541 skorolev Added NULL test for lf. + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. * * * @@ -72,19 +76,21 @@ public class ImportFileAction extends Action { private final String directoryPath; - private final LocalizationType contextType; + private final List contextTypes; private String[] fileExtensionFilterArr; - public ImportFileAction(LocalizationType contextType, String directoryPath) { + public ImportFileAction(List contextTypes, + String directoryPath) { super("Import File..."); - this.contextType = contextType; + this.contextTypes = contextTypes; this.directoryPath = directoryPath; } - public ImportFileAction(LocalizationType contextType, String directoryPath, + public ImportFileAction(List contextTypes, + String directoryPath, String[] filter) { - this(contextType, directoryPath); + this(contextTypes, directoryPath); if (filter != null) { this.fileExtensionFilterArr = new String[filter.length]; for (int i = 0; i < filter.length; ++i) { @@ -114,11 +120,11 @@ public class ImportFileAction extends Action { String fileToImport = dialog.open(); if (fileToImport != null) { File importFile = new File(fileToImport); - importFile(contextType, directoryPath, new File[] { importFile }); + importFile(contextTypes, directoryPath, new File[] { importFile }); } } - public static boolean importFile(LocalizationType contextType, + public static boolean importFile(List contextTypes, String directoryPath, File[] importFiles) { List applicable = new ArrayList(importFiles.length); for (File importFile : importFiles) { @@ -127,24 +133,38 @@ public class ImportFileAction extends Action { applicable.add(importFile); } } - List localizationFiles = new ArrayList( + List localizationFiles = new ArrayList( applicable.size()); - List existing = new ArrayList( + List existing = new ArrayList( applicable.size()); for (File importFile : applicable) { String name = importFile.getName(); String newFilePath = directoryPath + IPathManager.SEPARATOR + name; IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationFile lf = pm.getLocalizationFile( - pm.getContext(contextType, LocalizationLevel.USER), - newFilePath); + LocalizationFile lf = null; + for (LocalizationType contextType : contextTypes) { + LocalizationFile testFile = pm.getLocalizationFile( + pm.getContext(contextType, LocalizationLevel.USER), + newFilePath); + if (lf == null) { + lf = testFile; + } else if (!lf.exists() + && (testFile.exists() || lf.isProtected())) { + /* + * If a file exists we want to overwrite it to avoid 2 files + * at the same level + */ + lf = testFile; + } + } if ((lf != null) && !lf.isProtected()) { localizationFiles.add(lf); if (lf.exists()) { existing.add(lf); } } else { + localizationFiles.add(null); statusHandler .handle(Priority.WARN, newFilePath @@ -152,14 +172,14 @@ public class ImportFileAction extends Action { } } - List skip = new ArrayList(); + List skip = new ArrayList(); if (existing.size() > 0) { if (existing.size() > 1) { MultiConfirmDialog dialog = new MultiConfirmDialog(existing); dialog.open(); existing.removeAll(dialog.getConfirmedFiles()); } else { - LocalizationFile file = existing.get(0); + ILocalizationFile file = existing.get(0); if (MessageDialog.openConfirm(VizWorkbenchManager.getInstance() .getCurrentWindow().getShell(), "Confirm Overwrite", String.format(FORMAT_STRING, file.getName(), file @@ -174,10 +194,11 @@ public class ImportFileAction extends Action { for (int i = 0; i < applicable.size(); ++i) { File importFile = applicable.get(i); if (!localizationFiles.isEmpty()) { - LocalizationFile lf = localizationFiles.get(i); - if (skip.contains(lf) == false) { - try { - lf.write(FileUtil.file2bytes(importFile)); + ILocalizationFile lf = localizationFiles.get(i); + if (lf != null && skip.contains(lf) == false) { + try (SaveableOutputStream os = lf.openOutputStream()) { + os.write(FileUtil.file2bytes(importFile)); + os.save(); ++addCount; } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, @@ -191,9 +212,9 @@ public class ImportFileAction extends Action { private static class MultiConfirmDialog extends MessageDialog { - private final List confirmedFiles; + private final List confirmedFiles; - private final List existingFiles; + private final List existingFiles; private int curIdx = 0; @@ -206,13 +227,13 @@ public class ImportFileAction extends Action { * @param dialogButtonLabels * @param defaultIndex */ - public MultiConfirmDialog(List existingFiles) { + public MultiConfirmDialog(List existingFiles) { super(VizWorkbenchManager.getInstance().getCurrentWindow() .getShell(), "Confirm Overwrite", null, "", MessageDialog.CONFIRM, new String[] { "Yes To All", "No", "Cancel", "Yes" }, 0); this.existingFiles = existingFiles; - this.confirmedFiles = new ArrayList( + this.confirmedFiles = new ArrayList( existingFiles.size()); setShellStyle(getShellStyle() | SWT.SHEET); } @@ -258,13 +279,6 @@ public class ImportFileAction extends Action { } } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.jface.dialogs.IconAndMessageDialog#createMessageArea( - * org.eclipse.swt.widgets.Composite) - */ @Override protected Control createMessageArea(Composite composite) { Control ctrl = super.createMessageArea(composite); @@ -273,12 +287,12 @@ public class ImportFileAction extends Action { } private void updateText() { - LocalizationFile file = existingFiles.get(curIdx); + ILocalizationFile file = existingFiles.get(curIdx); messageLabel.setText(String.format(FORMAT_STRING, file.getName(), file.getContext().getLocalizationLevel())); } - public List getConfirmedFiles() { + public List getConfirmedFiles() { return confirmedFiles; } } diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/MoveFileAction.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/MoveFileAction.java index 8f35af4284..ea2db1338e 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/MoveFileAction.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/MoveFileAction.java @@ -31,7 +31,10 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationUtil; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.viz.core.VizApp; +import com.raytheon.uf.viz.localization.filetreeview.LocalizationFileEntryData; import com.raytheon.uf.viz.localization.service.ILocalizationService; /** @@ -44,7 +47,10 @@ import com.raytheon.uf.viz.localization.service.ILocalizationService; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Mar 25, 2011 mschenke Initial creation + * Mar 25, 2011 mschenke Initial creation + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. + * * * * @@ -53,20 +59,24 @@ import com.raytheon.uf.viz.localization.service.ILocalizationService; */ public class MoveFileAction extends CopyToAction { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(MoveFileAction.class); - private DeleteAction delete; + private final DeleteAction delete; - private IWorkbenchPage page; + private final IWorkbenchPage page; /** - * @param file + * @param localizationFileEntryData + * .getFile() */ - public MoveFileAction(IWorkbenchPage page, LocalizationFile file, + public MoveFileAction(IWorkbenchPage page, LocalizationFileEntryData data, ILocalizationService service) { - super(file, service); + super(data, service); setText("Move To"); this.page = page; - delete = new DeleteAction(page, new LocalizationFile[] { file }, false); + delete = new DeleteAction(page, + new LocalizationFile[] { data.getFile() }, false); setEnabled(delete.isEnabled()); } @@ -104,7 +114,7 @@ public class MoveFileAction extends CopyToAction { final LocalizationFile newFile = pm.getLocalizationFile( pm.getContext(file.getContext().getLocalizationType(), level), file.getName()); - + removeAlternateTypeFiles(level); // Make sure we select the file after the drop final ILocalizationFileObserver[] observers = new ILocalizationFileObserver[1]; ILocalizationFileObserver observer = new ILocalizationFileObserver() { diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/PasteFileAction.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/PasteFileAction.java index 9a5c674565..b3bbdd5408 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/PasteFileAction.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/PasteFileAction.java @@ -19,6 +19,8 @@ **/ package com.raytheon.uf.viz.localization.perspective.view.actions; +import java.util.List; + import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; @@ -39,6 +41,9 @@ import com.raytheon.uf.viz.localization.service.ILocalizationService; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Dec 3, 2010 6305 mpduff Initial creation + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. + * * * * @@ -54,7 +59,7 @@ public class PasteFileAction extends CopyToAction { public PasteFileAction(ILocalizationService service, LocalizationFile file, LocalizationFileGroupData data) { - super(file, service); + super(file, data.getPathData(), service); setText("Paste To"); this.dataToCopyTo = data; // Grab the level this file is protected at (if any) @@ -64,39 +69,26 @@ public class PasteFileAction extends CopyToAction { } } - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.localization.perspective.view.actions.CopyToAction - * #isLevelEnabled - * (com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel - * ) - */ @Override protected boolean isLevelEnabled(LocalizationLevel level) { return pasteToProtectedLevel == null || level.compareTo(pasteToProtectedLevel) <= 0; } - /* - * (non-Javadoc) - * - * @see - * com.raytheon.uf.viz.localization.filetreeview.actions.AbstractToAction - * #run - * (com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel - * ) - */ @Override protected void run(LocalizationLevel level) { IPathManager pm = PathManagerFactory.getPathManager(); - LocalizationType type = dataToCopyTo.getPathData().getType(); + List types = dataToCopyTo.getPathData().getTypes(); + LocalizationType type = file.getContext().getLocalizationType(); + if(!types.contains(type)){ + type = types.get(0); + } LocalizationContext ctx = pm.getContext(type, level); LocalizationFile newFile = pm.getLocalizationFile(ctx, dataToCopyTo.getPath()); + removeAlternateTypeFiles(level); copyFile(newFile); } } diff --git a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/RenameAction.java b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/RenameAction.java index a492771fd8..92afe7fc3c 100644 --- a/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/RenameAction.java +++ b/cave/com.raytheon.uf.viz.localization.perspective/src/com/raytheon/uf/viz/localization/perspective/view/actions/RenameAction.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.viz.localization.perspective.view.actions; +import java.io.InputStream; import java.util.regex.Pattern; import org.eclipse.jface.action.Action; @@ -36,6 +37,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel import com.raytheon.uf.common.localization.LocalizationFile; import com.raytheon.uf.common.localization.LocalizationUtil; import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.SaveableOutputStream; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.util.FileUtil; @@ -52,7 +54,10 @@ import com.raytheon.viz.ui.VizWorkbenchManager; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Apr 27, 2011 mschenke Initial creation + * Apr 27, 2011 mschenke Initial creation + * Oct 13, 2015 4410 bsteffen Allow localization perspective to mix + * files for multiple Localization Types. + * * * * @@ -186,8 +191,12 @@ public class RenameAction extends Action { } } - FileUtil.copyFile(file.getFile(), newFile.getFile()); - newFile.save(); + try (InputStream is = file.openInputStream(); + SaveableOutputStream os = newFile + .openOutputStream()) { + FileUtil.copy(is, os); + os.save(); + } if (deleteOld) { file.delete(); }