use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class LayerGroup method actionImportProject.
public void actionImportProject(final String title, final boolean resetProject) {
final Project project = getProject();
if (resetProject) {
if (!project.saveWithPrompt()) {
return;
}
}
final JFileChooser fileChooser = SwingUtil.newFileChooser(title, "com.revolsys.swing.map.project", "templateDirectory");
final FileNameExtensionFilter filter = new FileNameExtensionFilter("Project (*.rgmap)", "rgmap");
fileChooser.setAcceptAllFileFilterUsed(true);
fileChooser.addChoosableFileFilter(filter);
fileChooser.setFileFilter(filter);
if (OS.isMac()) {
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
} else {
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
final Window window = SwingUtil.getActiveWindow();
final int returnVal = fileChooser.showOpenDialog(window);
if (returnVal == JFileChooser.APPROVE_OPTION) {
final File projectDirectory = fileChooser.getSelectedFile();
if (projectDirectory != null) {
PreferencesUtil.setUserString("com.revolsys.swing.map.project", "templateDirectory", projectDirectory.getParent());
final PathResource resource = new PathResource(projectDirectory);
importProject(project, resource, resetProject);
}
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class Project method getSaveAsDirectory.
public Path getSaveAsDirectory() {
File directory = null;
final JFileChooser fileChooser = SwingUtil.newFileChooser("Save Project", "com.revolsys.swing.map.project", "directory");
fileChooser.setFileFilter(new FileNameExtensionFilter("Project", "rgmap"));
fileChooser.setMultiSelectionEnabled(false);
final int returnVal = fileChooser.showSaveDialog(SwingUtil.getActiveWindow());
if (returnVal == JFileChooser.APPROVE_OPTION) {
directory = fileChooser.getSelectedFile();
final String fileExtension = FileUtil.getFileNameExtension(directory);
if (!"rgmap".equals(fileExtension)) {
directory = new File(directory.getParentFile(), directory.getName() + ".rgmap");
}
PreferencesUtil.setUserString("com.revolsys.swing.map.project", "directory", directory.getParent());
if (directory.exists()) {
FileUtil.deleteDirectory(directory);
}
directory.mkdirs();
this.resource = new PathResource(directory);
return directory.toPath();
} else {
return null;
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class FileUtil method getFile.
public static File getFile(final Resource resource) {
if (resource instanceof PathResource) {
final PathResource fileResource = (PathResource) resource;
return fileResource.getFile();
} else {
final String fileName = resource.getFilename();
final String ext = getFileNameExtension(fileName);
final File file = newTempFile(fileName, "." + ext);
copy(resource.getInputStream(), file);
file.deleteOnExit();
return file;
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class AbstractConnectionRegistry method setDirectory.
protected void setDirectory(final Resource directoryResource) {
if (directoryResource instanceof PathResource) {
final PathResource pathResource = (PathResource) directoryResource;
final Path directory = pathResource.getPath();
boolean readOnly = isReadOnly();
if (!readOnly) {
if (directoryResource.exists()) {
readOnly = !Files.isWritable(directory);
} else if (Paths.deleteDirectories(directory)) {
readOnly = false;
} else {
readOnly = true;
}
}
setReadOnly(readOnly);
this.directory = directory;
} else {
setReadOnly(true);
this.directory = null;
}
}
use of com.revolsys.spring.resource.PathResource in project com.revolsys.open by revolsys.
the class MoepDirectoryReader method setDirectory.
@Override
public void setDirectory(final File directory) {
super.setDirectory(directory);
final String name = FileUtil.getFileName(directory);
final File file = new File(directory, name + "s.bin");
final Reader<Record> supDataReader = newReader(new PathResource(file));
for (final Record supData : supDataReader) {
final String featureCode = supData.getValue(MoepConstants.FEATURE_CODE);
if (featureCode.equals("KN00020000")) {
final String text = supData.getValue(MoepConstants.TEXT);
final String[] versionFields = text.split(" ");
final String dateString = versionFields[2];
this.submissionDate = new Date(Dates.getDate("yyyyMMdd", dateString).getTime());
this.revisionKey = versionFields[3];
this.integrationDate = new Date(Dates.getDate("yyyyMMdd", versionFields[4]).getTime());
this.specificationsRelease = versionFields[5];
}
}
}
Aggregations