/*
* Copyright (c) 2013-2014. Confluenity
* This content is released under the Apache 2 license:
* http://www.apache.org/licenses/LICENSE-2.0
*/
package com.confluenity.jaylen.actions;
import com.confluenity.jaylen.io.JsrcFile;
import com.confluenity.jaylen.io.BaseFile;
import com.confluenity.jaylen.util.FileAssistant;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.UUID;
public class OpenAction extends Action {
private static final Logger logger = LoggerFactory.getLogger(OpenAction.class);
@Override
public void widgetSelected(SelectionEvent event) {
final String [] filterExtensions = new String[] {".jsrc", ".jxf", ".drg"};
FileAssistant.FileDescriptor selected = springContext.getBean(FileAssistant.class).getOpenFile(filterExtensions, getMessage("dialog.open.source"), FileAssistant.DataKind.SOURCE);
if (selected == null) {
return;
}
UUID uuid = null;
try {
uuid = context.addJsrcFile(new JsrcFile(selected.getFilePath(), "r"));
} catch (IOException e) {
logger.error(e.getLocalizedMessage(), e);
}
JsrcFile jsrc = context.getJsrcFile(uuid);
if(jsrc != null) {
Tree tree = springContext.getBean("objectTree", Tree.class);
TreeItem treeItem = new TreeItem(tree, SWT.NONE);
treeItem.setImage(springContext.getBean("treeItemGlyph", Image.class));
treeItem.setText(new String[] {jsrc.getFileType(), String.valueOf(jsrc.getFrameCount()), String.valueOf(jsrc.getPointCount())});
treeItem.setData(uuid);
}
}
}