use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class BXMLExplorerDocument method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
treeView.setSelectMode(SelectMode.SINGLE);
treeView.setNodeRenderer(new MyTreeViewNodeRenderer());
treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
private final Decorator focusDecorator = new ShadeDecorator(0.2f, Color.RED);
private Component previousSelectedComponent = null;
@Override
public void selectedNodeChanged(TreeView treeViewArgument, Object previousSelectedNode) {
TreeNode node = (TreeNode) treeViewArgument.getSelectedNode();
if (previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
previousSelectedComponent.getDecorators().remove(focusDecorator);
previousSelectedComponent = null;
}
if (node == null || !(node.getUserData() instanceof Component)) {
// TODO make the inspectors able to deal with things like
// TablePane.Row
componentPropertyInspector.setSource(null);
componentStyleInspector.setSource(null);
return;
}
Component selectedComp = (Component) node.getUserData();
if (selectedComp != null && selectedComp.getDecorators().indexOf(focusDecorator) == -1) {
selectedComp.getDecorators().add(focusDecorator);
previousSelectedComponent = selectedComp;
}
if (selectedComp instanceof FakeWindow) {
selectedComp = ((FakeWindow) selectedComp).window;
}
componentPropertyInspector.setSource(selectedComp);
componentStyleInspector.setSource(selectedComp);
}
@Override
public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
// if the selection becomes empty, remove the decorator
if (treeViewArgument.getSelectedNode() == null && previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
previousSelectedComponent.getDecorators().remove(focusDecorator);
}
}
});
playgroundCardPane.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
@Override
public boolean mouseClick(Component component, Button button, int x, int y, int count) {
if (count == 1) {
Component comp = playgroundCardPane.getDescendantAt(x, y);
if (comp != null) {
TreeNode treeNode = componentToTreeNode.get(comp);
Path path = getPathForNode(treeView, treeNode);
if (path != null) {
treeView.setSelectedPath(path);
return true;
}
}
}
return false;
}
});
reloadButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(org.apache.pivot.wtk.Button button) {
playgroundCardPane.remove(loadedComponent);
widgetToID = null;
componentToTreeNode = null;
loadedComponent = null;
try {
load(file);
} catch (RuntimeException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (IOException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (SerializationException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (ParserConfigurationException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
} catch (SAXException exception) {
exception.printStackTrace();
BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
}
}
});
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class Windows method startup.
@Override
public void startup(Display displayArgument, Map<String, String> properties) throws Exception {
this.display = displayArgument;
int x = 0;
int y = 0;
for (int i = 0; i < 3; i++) {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
bxmlSerializer.getNamespace().put("application", this);
Frame frame;
try {
frame = (Frame) bxmlSerializer.readObject(Windows.class, "frame.bxml");
} catch (SerializationException exception) {
throw new RuntimeException(exception);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
frame.setTitle("Frame " + (i + 1));
frame.setLocation(x, y);
x += 20;
y += 20;
frame.open(displayArgument);
}
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class QueryServlet method doPost.
@Override
protected final void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Path path = getPath(request);
URL location = null;
try {
validate(Query.Method.POST, path);
Object value = null;
if (request.getContentLength() > 0) {
Serializer<?> serializer = createSerializer(Query.Method.POST, path);
value = serializer.readObject(request.getInputStream());
}
location = doPost(path, value);
} catch (SerializationException exception) {
throw new ServletException(exception);
} catch (QueryException exception) {
response.setStatus(exception.getStatus());
response.flushBuffer();
}
if (!response.isCommitted()) {
if (location == null) {
response.setStatus(Query.Status.NO_CONTENT);
} else {
response.setStatus(Query.Status.CREATED);
response.setHeader(LOCATION_HEADER, location.toString());
}
setResponseHeaders(response);
response.setContentLength(0);
}
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class QueryServlet method doGet.
@Override
@SuppressWarnings("unchecked")
protected final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
Path path = getPath(request);
Object result = null;
Serializer<Object> serializer = null;
try {
validate(Query.Method.GET, path);
result = doGet(path);
serializer = (Serializer<Object>) createSerializer(Query.Method.GET, path);
} catch (QueryException exception) {
response.setStatus(exception.getStatus());
response.flushBuffer();
}
if (!response.isCommitted() && serializer != null) {
response.setStatus(Query.Status.OK);
setResponseHeaders(response);
response.setContentType(serializer.getMIMEType(result));
OutputStream responseOutputStream = response.getOutputStream();
if (determineContentLength) {
File tempFile = File.createTempFile(getClass().getName(), null);
// Serialize the result to an intermediary file
try (FileOutputStream fileOutputStream = new FileOutputStream(tempFile)) {
serializer.writeObject(result, fileOutputStream);
} catch (SerializationException exception) {
throw new ServletException(exception);
}
// Set the content length header
response.setHeader(CONTENT_LENGTH_HEADER, String.valueOf(tempFile.length()));
// Write the contents of the file out to the response
try (FileInputStream fileInputStream = new FileInputStream(tempFile)) {
byte[] buffer = new byte[1024];
int nBytes;
do {
nBytes = fileInputStream.read(buffer);
if (nBytes > 0) {
responseOutputStream.write(buffer, 0, nBytes);
}
} while (nBytes != -1);
}
} else {
try {
serializer.writeObject(result, responseOutputStream);
} catch (SerializationException exception) {
throw new ServletException(exception);
}
}
response.flushBuffer();
}
}
Aggregations