org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150407-1430",
org.eclipse.e4.core.di,
org.eclipse.e4.ui.services,
- org.simantics.fileimport;bundle-version="1.0.0"
+ org.simantics.fileimport;bundle-version="1.0.0",
+ org.slf4j.api
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.inject;version="1.0.0"
Bundle-ActivationPolicy: lazy
import java.nio.file.Paths;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Consumer;
import javax.inject.Named;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.simantics.fileimport.FileImportService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ImportFileHandler {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ImportFileHandler.class);
+
@CanExecute
public boolean canExecute() {
return !FileImportService.supportedExtensionsWithFilters().isEmpty();
final String fileName = dialog.open();
if (fileName == null)
return;
- FileImportService.performFileImport(Paths.get(fileName), Optional.empty());
+
+ FileImportService.performFileImport(Paths.get(fileName), Optional.of((Consumer<Throwable>) t -> {
+ LOGGER.error("Could not import file " + fileName, t);
+ }));
}
}
\ No newline at end of file
org.simantics,
org.simantics.graphfile;bundle-version="0.1.0",
org.simantics.graphfile.ontology;bundle-version="0.1.0",
- org.simantics.modeling;bundle-version="1.1.1"
+ org.simantics.modeling;bundle-version="1.1.1",
+ org.slf4j.api
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.simantics.fileimport
getUploadedFiles :: () -> <Proc> MMap.T String Long
removeFileForId :: Long -> <Proc> ()
+
+importJava "org.simantics.fileimport.FileImportService" where
+ performFileImport :: String -> String -> <Proc> String
+
getUploadedDropinFiles :: () -> <Proc> [Long]
getUploadedDropinFiles dummy = do
files = getUploadedFiles ()
public class Activator implements BundleActivator {
- private static BundleContext context;
+ private static BundleContext context;
+ private static Path modelsFolder = null;
private static Path dropinsFolder = null;
static BundleContext getContext() {
return dropinsFolder;
}
+ public static Path getModelsFolder() throws IOException {
+ if (modelsFolder == null) {
+ IPath state = Platform.getStateLocation(context.getBundle());
+ modelsFolder = Paths.get(state.append("models").toOSString());
+ if (!Files.exists(modelsFolder))
+ Files.createDirectories(modelsFolder);
+ }
+ return modelsFolder;
+ }
+
}
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.simantics.databoard.util.Base64;
import org.simantics.fileimport.dropins.FileImportDropins;
+import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility class for Simantics File import functions
*/
public class FileImportService {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FileImportService.class);
+
private FileImportService() {}
public static final String DB_FILE = ".simanticsdb";
serviceReferences = Activator.getContext().getAllServiceReferences(IGenericFileImport.class.getName(),
null);
} catch (InvalidSyntaxException e) {
- e.printStackTrace();
+ LOGGER.error("Could not get service references for IGenericFileImport!", e);
}
if (serviceReferences.length == 0)
return Collections.emptyList();
return extensionsWithFilters;
}
+
+ private static class ConsumerHolder implements Consumer<Throwable> {
+
+ private Throwable throwable;
+
+ @Override
+ public void accept(Throwable t) {
+ throwable = t;
+ }
+
+ public Throwable getThrowable() {
+ return throwable;
+ }
+
+ }
+
+ public static String performFileImport(String base64, String name) throws Throwable {
+ byte[] bytes = Base64.decode(base64);
+ Path file = Activator.getModelsFolder().resolve(name);
+ Files.write(file, bytes);
+
+ ConsumerHolder holder = new ConsumerHolder();
+ String result = performFileImport(file, Optional.of(holder));
+ if (holder.getThrowable() != null)
+ throw holder.getThrowable();
+ return result;
+ }
/**
* Method that performs the import of the given file. This method is called when e.g. {@link FileImportDropins} watcher detects {@link java.nio.file.StandardWatchEventKinds.ENTRY_CREATE} operation
* @param file Path file to be imported
* @param callback Optional callback which can be used to catch Throwables thrown in the import process
*/
- public static void performFileImport(Path file, Optional<Consumer<Throwable>> callback) {
- if (file.getFileName().toString().equals(DB_FILE))
- return;
+ public static String performFileImport(Path file, Optional<Consumer<Throwable>> callback) {
+ if (file.getFileName().toString().equals(DB_FILE)) {
+ return null;
+ }
+ String result = "Import failed";
Optional<IGenericFileImport> serviceOp = findServiceForFileExtension(file);
- serviceOp.ifPresent(service -> {
+ if (serviceOp.isPresent()) {
+ IGenericFileImport service = serviceOp.get();
try {
Optional<String> resource = service.perform(file);
saveResourceForPath(file, resource);
+ result = resource.get();
} catch (Throwable t) {
if (callback.isPresent()) {
callback.get().accept(t);
} else {
- t.printStackTrace();
+ LOGGER.error("Could not import file " + file, t);
}
}
- });
+ } else {
+ LOGGER.warn("Could not find service for importing file " + file);
+ if (callback.isPresent())
+ callback.get().accept(new Exception("Could not find IGenericFileImport service for file " + file));
+ }
+ return result;
}
import java.util.Optional;
import org.simantics.db.Resource;
-import org.simantics.db.exception.DatabaseException;
import org.simantics.graphfile.util.GraphFileUtil;
public class FileReferenceFileImport extends SimanticsResourceFileImport {
- private static final Map<String, String> ALLOWED_EXTENSIONS = Collections.singletonMap("*.asd", "All files");
+ private static final Map<String, String> ALLOWED_EXTENSIONS = Collections.singletonMap("*", "All files");
@Override
- public Optional<Resource> perform(Resource parent, Path file) {
- try {
- return Optional.of(GraphFileUtil.createFileReference(parent, file));
- } catch (DatabaseException e) {
- e.printStackTrace();
- return Optional.empty();
- }
+ public Optional<Resource> perform(Resource parent, Path file) throws Exception {
+ return Optional.of(GraphFileUtil.createFileReference(parent, file));
}
@Override
}
@Override
- public Optional<Resource> perform(Resource parent, Path file) {
+ public Optional<Resource> perform(Resource parent, Path file) throws Exception {
final String name = file.getFileName().toString();
- try {
- return Optional.of(Simantics.getSession().syncRequest(new WriteResultRequest<Resource>() {
+ return Optional.of(Simantics.getSession().syncRequest(new WriteResultRequest<Resource>() {
- @Override
- public Resource perform(WriteGraph graph) throws DatabaseException {
- return ModelingUtils.createLibrary(graph, parent, name);
- }
- }));
- } catch (DatabaseException e) {
- e.printStackTrace();
- return Optional.empty();
- }
+ @Override
+ public Resource perform(WriteGraph graph) throws DatabaseException {
+ return ModelingUtils.createLibrary(graph, parent, name);
+ }
+ }));
}
}
import org.simantics.fileimport.dropins.FileImportDropins;
import org.simantics.layer0.Layer0;
import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* SCL interface for Simantics File Import Functionality
*
*/
public class DropinsSCL {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DropinsSCL.class);
public static void watchDropinsFolder() {
FileImportDropins.watchDropinsFolder();
public static void uploadToDropinsBase64(String base64, String fileName) {
// ensure that watcher is awake
FileImportDropins.watchDropinsFolder();
+ Path rootFolder = null;
try {
- Path rootFolder = Activator.getDropinsFolder();
+ rootFolder = Activator.getDropinsFolder();
Path newFile = rootFolder.resolve(fileName);
if (Files.exists(newFile)) {
newFile = findFreshFileName(rootFolder, fileName);
byte[] bytes = Base64.decode(base64);
FileUtils.writeFile(newFile.toFile(), bytes);
} catch (IOException e) {
- e.printStackTrace();
+ LOGGER.error("Could not upload base64 to file " + (rootFolder != null ? rootFolder.resolve(fileName).toAbsolutePath() : ""), e);
}
}
private transient boolean closed = false;
protected ICanvasContext canvasContext;
+ private boolean useVolatileImage = true;
+
// Marks the content dirty
protected IContentListener contentListener = new IContentListener() {
@Override
public IHintContext getHintContext() {
return hintCtx;
}
+
+ public void setUseVolatileImage(boolean useVolatileImage) {
+ this.useVolatileImage = useVolatileImage;
+ }
+
+ public boolean isUseVolatileImage() {
+ return useVolatileImage;
+ }
private void paintScenegraph(Graphics2D g2d, Rectangle controlBounds) {
Color bg = getBackground();
startmem = Runtime.getRuntime().freeMemory();
start = System.nanoTime();
}
- VolatileImage buffer = paintToVolatileImage(g2d, b);
+ VolatileImage buffer = null;
+ if (useVolatileImage)
+ buffer = paintToVolatileImage(g2d, b);
if (closed)
return;
if (DebugPolicy.PERF_CHASSIS_RENDER_FRAME) {
org.simantics.modeling.ontology;bundle-version="1.2.0",
org.simantics.fastlz;bundle-version="1.2.1",
org.apache.commons.compress;bundle-version="1.7.0",
- org.simantics.lz4;bundle-version="1.3.0"
+ org.simantics.lz4;bundle-version="1.3.0",
+ org.slf4j.api;bundle-version="1.7.0"
Export-Package: org.simantics.simulation,
org.simantics.simulation.data,
org.simantics.simulation.experiment,
import org.simantics.simulation.model.IModel;
import org.simantics.ui.workbench.WorkbenchShutdownService;
import org.simantics.utils.datastructures.ListenerList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Simple local ExperimentManager implementation
*/
public class ExperimentManager implements IExperimentManager {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExperimentManager.class);
+
CopyOnWriteArrayList<IExperimentManagerListener> listeners = new CopyOnWriteArrayList<IExperimentManagerListener>();
ListenerList<IExperiment> experiments = new ListenerList<IExperiment>(IExperiment.class);
IExperiment activeExperiment;
if (!listeners.isEmpty()) {
// Some clients are leaking listeners. Shame on them.
- System.err.println("ExperimentManager still contains the following listeners after disposal:");
+ LOGGER.warn("ExperimentManager still contains the following listeners after disposal:");
for (IExperimentManagerListener listener : listeners)
- System.err.println("\t" + listener);
+ LOGGER.warn("\t" + listener);
}
}
}
}
@Override
- public Optional<Resource> perform(Resource parent, Path file) {
- return Optional.empty();
+ public Optional<Resource> perform(Resource parent, Path file) throws Exception {
+ throw new UnsupportedOperationException("Excel import is not yet supported");
}
@Override
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="org.eclipse.jetty.http"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.jetty.server"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.jetty.servlet"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.jetty.util"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.jetty.io"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.jetty.security"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.ui.cheatsheets"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="javax.servlet"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>