use of org.apache.pivot.collections.HashMap in project pivot by apache.
the class XMLViewer method updateProperties.
public void updateProperties() {
Node node = (Node) treeView.getSelectedNode();
if (node == null) {
// no selection, but it's ok
} else if (node instanceof TextNode) {
TextNode textNode = (TextNode) node;
textArea.setText(textNode.getText());
propertiesCardPane.setSelectedIndex(1);
} else if (node instanceof Element) {
Element element = (Element) node;
// Populate the namespaces table
ArrayList<HashMap<String, String>> namespacesTableData = new ArrayList<>();
String defaultNamespaceURI = element.getDefaultNamespaceURI();
if (defaultNamespaceURI != null) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", "(default)");
row.put("uri", defaultNamespaceURI);
namespacesTableData.add(row);
}
Element.NamespaceDictionary namespaceDictionary = element.getNamespaces();
for (String prefix : namespaceDictionary) {
HashMap<String, String> row = new HashMap<>();
row.put("prefix", prefix);
row.put("uri", namespaceDictionary.get(prefix));
namespacesTableData.add(row);
}
namespacesTableView.setTableData(namespacesTableData);
// Populate the attributes table
ArrayList<HashMap<String, String>> attributesTableData = new ArrayList<>();
for (Element.Attribute attribute : element.getAttributes()) {
HashMap<String, String> row = new HashMap<>();
String attributeName = attribute.getName();
row.put("name", attributeName);
row.put("value", element.getElementDictionary().get(attributeName));
attributesTableData.add(row);
}
attributesTableView.setTableData(attributesTableData);
propertiesCardPane.setSelectedIndex(0);
} else {
throw new IllegalStateException();
}
}
use of org.apache.pivot.collections.HashMap in project pivot by apache.
the class BXMLDictionaryTest method main.
public static void main(String[] args) throws Exception {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
@SuppressWarnings("unchecked") HashMap<String, Object> hashMap = (HashMap<String, Object>) bxmlSerializer.readObject(BXMLDictionaryTest.class.getResource("bxml_dictionary_test.bxml"));
System.out.println(JSONSerializer.toString(hashMap));
}
use of org.apache.pivot.collections.HashMap in project pivot by apache.
the class BuilderExample method buildWindow.
private static MyWindow buildWindow() {
final HashMap<String, Object> namespace = new HashMap<>();
return new MyWindow() {
{
setContent(new TabPane() {
{
namespace.put("tabPane", this);
getTabs().add(new Label() {
{
setText("Label 1");
TabPane.setTabData(this, "Label 1");
}
});
getTabs().add(new Label() {
{
setText("Label 2");
TabPane.setTabData(this, "Label 2");
}
});
getTabs().add(new Label() {
{
setText("Label 3");
TabPane.setTabData(this, "Label 3");
}
});
setSelectedIndex(2);
}
});
setTitle("Builder Example");
setMaximized(true);
initialize(namespace, null, null);
}
};
}
use of org.apache.pivot.collections.HashMap in project pivot by apache.
the class ExpensesWindow method addExpense.
private void addExpense() {
expenseSheet.clear();
expenseSheet.open(this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
// Get the expense data from the sheet
final HashMap<String, Object> expense = new HashMap<>();
expenseSheet.store(expense);
// POST expense to server and then add to table
Expenses expensesApplicationLocal = getExpensesApplication();
PostQuery addExpenseQuery = new PostQuery(expensesApplicationLocal.getHostname(), expensesApplicationLocal.getPort(), "/pivot-tutorials/expenses", expensesApplicationLocal.isSecure());
addExpenseQuery.setValue(expense);
activityIndicatorBoxPane.setVisible(true);
activityIndicator.setActive(true);
addExpenseQuery.execute(new TaskAdapter<>(new TaskListener<URL>() {
@Override
public void taskExecuted(Task<URL> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
URL location = task.getResult();
String file = location.getFile();
int id = Integer.parseInt(file.substring(file.lastIndexOf('/') + 1));
expense.put("id", id);
@SuppressWarnings("unchecked") List<Object> expenses = (List<Object>) expenseTableView.getTableData();
expenses.add(expense);
}
@Override
public void executeFailed(Task<URL> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
Prompt.prompt(MessageType.ERROR, task.getFault().getMessage(), ExpensesWindow.this);
}
}));
}
}
});
}
use of org.apache.pivot.collections.HashMap in project pivot by apache.
the class ExpensesWindow method updateSelectedExpense.
private void updateSelectedExpense() {
Object expense = expenseTableView.getSelectedRow();
final int id = JSON.getInt(expense, "id");
expenseSheet.load(expense);
expenseSheet.open(this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (sheet.getResult()) {
// Get the expense data from the sheet
final HashMap<String, Object> expenseLocal = new HashMap<>();
expenseSheet.store(expenseLocal);
// PUT expense to server and then update table
Expenses expensesApplicationLocal = getExpensesApplication();
PutQuery updateExpenseQuery = new PutQuery(expensesApplicationLocal.getHostname(), expensesApplicationLocal.getPort(), "/pivot-tutorials/expenses/" + JSON.get(expenseLocal, "id"), expensesApplicationLocal.isSecure());
updateExpenseQuery.setValue(expenseLocal);
activityIndicatorBoxPane.setVisible(true);
activityIndicator.setActive(true);
updateExpenseQuery.execute(new TaskAdapter<>(new TaskListener<Boolean>() {
@Override
public void taskExecuted(Task<Boolean> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
// Find matching row and update
@SuppressWarnings("unchecked") List<Object> expenses = (List<Object>) expenseTableView.getTableData();
for (int i = 0, n = expenses.getLength(); i < n; i++) {
if (JSON.get(expenses.get(i), "id").equals(id)) {
expenses.update(i, expenseLocal);
break;
}
}
}
@Override
public void executeFailed(Task<Boolean> task) {
activityIndicatorBoxPane.setVisible(false);
activityIndicator.setActive(false);
Prompt.prompt(MessageType.ERROR, task.getFault().getMessage(), ExpensesWindow.this);
}
}));
}
}
});
}
Aggregations