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

fixed PROBPLUGIN-8

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