Skip to content
Snippets Groups Projects
Commit 0c5abded authored by Lukas Ladenberger's avatar Lukas Ladenberger
Browse files

fixed PROBPLUGIN-8

parent baec5bd7
Branches
Tags
No related merge requests found
......@@ -7,16 +7,20 @@
package de.bmotionstudio.gef.editor.library;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.MessageBox;
import de.bmotionstudio.gef.editor.BMotionStudioImage;
import de.bmotionstudio.gef.editor.util.FileUtil;
public class ImportImagesAction extends AbstractLibraryAction {
......@@ -49,52 +53,45 @@ public class ImportImagesAction extends AbstractLibraryAction {
// The project file
IFile pFile = getPage().getEditor().getVisualization().getProjectFile();
String imagePath = (pFile.getProject().getLocationURI() + "/images")
.replace("file:", "");
File imageFilePath = new File(imagePath);
try {
// Check if images folder exists!
// If no such folder exists -> create
if (!imageFilePath.exists()) {
Boolean check = imageFilePath.mkdir();
if (check) {
// TODO: Do something with return value
}
}
IProject project = pFile.getProject();
IFolder folder = project.getFolder("images");
NullProgressMonitor monitor = new NullProgressMonitor();
if (!folder.exists())
folder.create(true, true, monitor);
// Iterate the selected files
for (String fileName : selectedFiles) {
String filePath = (pFile.getProject().getLocation() + "/images/" + fileName)
.replace("file:", "");
// Copy files into project sub folder project/images
File inputFile = new File(folderPath + File.separator + fileName);
File outputFile = new File(filePath);
boolean ok = false;
File inputFile = new File(folderPath + File.separator
+ fileName);
IFile newFile = folder.getFile(fileName);
FileInputStream fileInputStream = new FileInputStream(inputFile);
if (outputFile.exists()) {
if (!newFile.exists()) {
newFile.create(fileInputStream, true,
monitor);
} else {
// The file already exists; asks for confirmation
MessageBox mb = new MessageBox(fd.getParent(), SWT.ICON_WARNING
| SWT.YES | SWT.NO);
MessageBox mb = new MessageBox(fd.getParent(),
SWT.ICON_WARNING | SWT.YES | SWT.NO);
mb.setMessage(fileName
+ " already exists. Do you want to replace it?");
// If they click Yes, we're done and we drop out. If
// they click No, we redisplay the File Dialog
ok = mb.open() == SWT.YES;
} else {
ok = true;
if (mb.open() == SWT.YES)
newFile.setContents(fileInputStream, true, false,
monitor);
}
if (ok) {
try {
FileUtil.copyFile(inputFile, outputFile);
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (CoreException e1) {
e1.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
getPage().refresh();
......
......@@ -6,14 +6,13 @@
package de.bmotionstudio.gef.editor.library;
import java.io.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import de.bmotionstudio.gef.editor.util.FileUtil;
public class LibraryImageObject extends LibraryObject {
public LibraryImageObject(String name, String type, Image typeImage) {
......@@ -22,10 +21,19 @@ public class LibraryImageObject extends LibraryObject {
@Override
public void delete(LibraryPage page) {
String myPath = (page.getEditor().getVisualization().getProjectFile()
.getProject().getLocation()
+ "/images/" + getName()).replace("file:", "");
FileUtil.deleteFile(new File(myPath));
try {
IFolder imageFolder = page.getEditor().getVisualization()
.getProjectFile().getProject().getFolder("images");
if (imageFolder.exists()) {
IFile file = imageFolder.getFile(getName());
if (file.exists())
file.delete(true, new NullProgressMonitor());
}
} catch (CoreException e) {
e.printStackTrace();
}
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment