Omaha #4410 Allow localization perspective to mix files for multiple Localization Types.
Former-commit-id: aca2b3fa1fe242b4fb93f68808be7fa67566c268
This commit is contained in:
parent
c13cb5b0e7
commit
d9d6e7ffbf
8 changed files with 243 additions and 150 deletions
|
@ -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.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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<LocalizationType> types = pd.getTypes();
|
||||
|
||||
IPathManager pathManager = PathManagerFactory.getPathManager();
|
||||
|
||||
boolean success = false;
|
||||
List<LocalizationFile> currentList = new ArrayList<LocalizationFile>();
|
||||
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,18 +1122,21 @@ public class FileTreeView extends ViewPart implements IPartListener2,
|
|||
return success;
|
||||
}
|
||||
|
||||
private LocalizationContext[] getTreeSearchContexts(LocalizationType type) {
|
||||
private LocalizationContext[] getTreeSearchContexts(
|
||||
List<LocalizationType> types) {
|
||||
IPathManager pathManager = PathManagerFactory.getPathManager();
|
||||
// Request for base/site/user
|
||||
|
||||
List<LocalizationContext> searchContexts = new ArrayList<LocalizationContext>();
|
||||
for (LocalizationType type : types) {
|
||||
LocalizationContext[] searchHierarchy = pathManager
|
||||
.getLocalSearchHierarchy(type);
|
||||
List<LocalizationContext> searchContexts = new ArrayList<LocalizationContext>(
|
||||
searchHierarchy.length);
|
||||
for (LocalizationContext ctx : searchHierarchy) {
|
||||
if (showSet.contains(ctx.getLocalizationLevel())) {
|
||||
searchContexts.add(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use of LocalizationLevels.values() in this case should be okay
|
||||
// since we are requesting all possible context names for the level,
|
||||
|
@ -1152,7 +1158,7 @@ public class FileTreeView extends ViewPart implements IPartListener2,
|
|||
|| ((myContext == null) && (context == null))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (LocalizationType type : types) {
|
||||
LocalizationContext ctx = pathManager.getContext(type,
|
||||
level);
|
||||
ctx.setContextName(context);
|
||||
|
@ -1160,6 +1166,7 @@ public class FileTreeView extends ViewPart implements IPartListener2,
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return searchContexts.toArray(new LocalizationContext[searchContexts
|
||||
.size()]);
|
||||
}
|
||||
|
@ -1217,10 +1224,21 @@ public class FileTreeView extends ViewPart implements IPartListener2,
|
|||
fData.clearChildData();
|
||||
fData.setRequestedChildren(true);
|
||||
PathData pd = fData.getPathData();
|
||||
Set<LocalizationLevel> levels = new HashSet<>();
|
||||
Set<LocalizationLevel> 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();
|
||||
StringBuilder nameBuilder = new StringBuilder(level.toString());
|
||||
if (entryData.isMultipleTypes() || level != LocalizationLevel.BASE) {
|
||||
nameBuilder.append(" (");
|
||||
if (level != LocalizationLevel.BASE) {
|
||||
name += " (" + ctx.getContextName() + ")";
|
||||
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<TreeItem> applicableItems = new ArrayList<TreeItem>();
|
||||
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)
|
||||
|
|
|
@ -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;
|
||||
|
@ -64,6 +67,9 @@ import com.raytheon.uf.viz.localization.perspective.view.actions.ImportFileActio
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 1, 2011 mschenke Initial creation
|
||||
* Oct 13, 2015 4410 bsteffen Allow localization perspective to mix
|
||||
* files for multiple Localization Types.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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()) {
|
||||
try (InputStream is = toMove.openInputStream();
|
||||
SaveableOutputStream os = moveTo.openOutputStream()) {
|
||||
FileUtil.copy(is, os);
|
||||
os.save();
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} 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<LocalizationType> types, String dirPath,
|
||||
File[] toCopyFiles) {
|
||||
boolean oneGood = false;
|
||||
List<File> files = new ArrayList<File>(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;
|
||||
|
|
|
@ -47,6 +47,8 @@ import com.raytheon.uf.viz.localization.filetreeview.PathData;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Sep 7, 2012 mschenke Initial creation
|
||||
* Oct 13, 2015 4410 bsteffen Allow localization perspective to mix
|
||||
* files for multiple Localization Types.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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<LocalizationType> 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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -49,6 +55,8 @@ import com.raytheon.uf.viz.localization.service.ILocalizationService;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Nov 3, 2010 mschenke Initial creation
|
||||
* Oct 13, 2015 4410 bsteffen Allow localization perspective to mix
|
||||
* files for multiple Localization Types.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -53,6 +55,8 @@ import com.raytheon.viz.ui.VizWorkbenchManager;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* 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.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -72,19 +76,21 @@ public class ImportFileAction extends Action {
|
|||
|
||||
private final String directoryPath;
|
||||
|
||||
private final LocalizationType contextType;
|
||||
private final List<LocalizationType> contextTypes;
|
||||
|
||||
private String[] fileExtensionFilterArr;
|
||||
|
||||
public ImportFileAction(LocalizationType contextType, String directoryPath) {
|
||||
public ImportFileAction(List<LocalizationType> contextTypes,
|
||||
String directoryPath) {
|
||||
super("Import File...");
|
||||
this.contextType = contextType;
|
||||
this.contextTypes = contextTypes;
|
||||
this.directoryPath = directoryPath;
|
||||
}
|
||||
|
||||
public ImportFileAction(LocalizationType contextType, String directoryPath,
|
||||
public ImportFileAction(List<LocalizationType> 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<LocalizationType> contextTypes,
|
||||
String directoryPath, File[] importFiles) {
|
||||
List<File> applicable = new ArrayList<File>(importFiles.length);
|
||||
for (File importFile : importFiles) {
|
||||
|
@ -127,24 +133,38 @@ public class ImportFileAction extends Action {
|
|||
applicable.add(importFile);
|
||||
}
|
||||
}
|
||||
List<LocalizationFile> localizationFiles = new ArrayList<LocalizationFile>(
|
||||
List<ILocalizationFile> localizationFiles = new ArrayList<ILocalizationFile>(
|
||||
applicable.size());
|
||||
List<LocalizationFile> existing = new ArrayList<LocalizationFile>(
|
||||
List<ILocalizationFile> existing = new ArrayList<ILocalizationFile>(
|
||||
applicable.size());
|
||||
|
||||
for (File importFile : applicable) {
|
||||
String name = importFile.getName();
|
||||
String newFilePath = directoryPath + IPathManager.SEPARATOR + name;
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
LocalizationFile lf = pm.getLocalizationFile(
|
||||
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<LocalizationFile> skip = new ArrayList<LocalizationFile>();
|
||||
List<ILocalizationFile> skip = new ArrayList<ILocalizationFile>();
|
||||
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<LocalizationFile> confirmedFiles;
|
||||
private final List<ILocalizationFile> confirmedFiles;
|
||||
|
||||
private final List<LocalizationFile> existingFiles;
|
||||
private final List<ILocalizationFile> existingFiles;
|
||||
|
||||
private int curIdx = 0;
|
||||
|
||||
|
@ -206,13 +227,13 @@ public class ImportFileAction extends Action {
|
|||
* @param dialogButtonLabels
|
||||
* @param defaultIndex
|
||||
*/
|
||||
public MultiConfirmDialog(List<LocalizationFile> existingFiles) {
|
||||
public MultiConfirmDialog(List<ILocalizationFile> 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<LocalizationFile>(
|
||||
this.confirmedFiles = new ArrayList<ILocalizationFile>(
|
||||
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<LocalizationFile> getConfirmedFiles() {
|
||||
public List<ILocalizationFile> getConfirmedFiles() {
|
||||
return confirmedFiles;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +48,9 @@ import com.raytheon.uf.viz.localization.service.ILocalizationService;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 25, 2011 mschenke Initial creation
|
||||
* Oct 13, 2015 4410 bsteffen Allow localization perspective to mix
|
||||
* files for multiple Localization Types.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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() {
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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<LocalizationType> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -53,6 +55,9 @@ import com.raytheon.viz.ui.VizWorkbenchManager;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 27, 2011 mschenke Initial creation
|
||||
* Oct 13, 2015 4410 bsteffen Allow localization perspective to mix
|
||||
* files for multiple Localization Types.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue