Search in sources :

Example 1 with HashMap

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();
    }
}
Also used : HashMap(org.apache.pivot.collections.HashMap) Node(org.apache.pivot.xml.Node) TextNode(org.apache.pivot.xml.TextNode) Element(org.apache.pivot.xml.Element) ArrayList(org.apache.pivot.collections.ArrayList) TextNode(org.apache.pivot.xml.TextNode)

Example 2 with HashMap

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));
}
Also used : HashMap(org.apache.pivot.collections.HashMap) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 3 with 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);
        }
    };
}
Also used : TabPane(org.apache.pivot.wtk.TabPane) HashMap(org.apache.pivot.collections.HashMap) Label(org.apache.pivot.wtk.Label)

Example 4 with HashMap

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);
                    }
                }));
            }
        }
    });
}
Also used : HashMap(org.apache.pivot.collections.HashMap) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) URL(java.net.URL) TaskAdapter(org.apache.pivot.wtk.TaskAdapter) PostQuery(org.apache.pivot.web.PostQuery) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Sheet(org.apache.pivot.wtk.Sheet)

Example 5 with HashMap

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);
                    }
                }));
            }
        }
    });
}
Also used : HashMap(org.apache.pivot.collections.HashMap) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) PutQuery(org.apache.pivot.web.PutQuery) TaskAdapter(org.apache.pivot.wtk.TaskAdapter) ArrayList(org.apache.pivot.collections.ArrayList) List(org.apache.pivot.collections.List) Sheet(org.apache.pivot.wtk.Sheet)

Aggregations

HashMap (org.apache.pivot.collections.HashMap)11 ArrayList (org.apache.pivot.collections.ArrayList)6 List (org.apache.pivot.collections.List)4 JSONSerializer (org.apache.pivot.json.JSONSerializer)3 Sheet (org.apache.pivot.wtk.Sheet)3 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)3 StringReader (java.io.StringReader)2 Method (java.lang.reflect.Method)2 TaskAdapter (org.apache.pivot.wtk.TaskAdapter)2 Test (org.junit.Test)2 Color (java.awt.Color)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 BeanAdapter (org.apache.pivot.beans.BeanAdapter)1 BeanMonitor (org.apache.pivot.beans.BeanMonitor)1 Map (org.apache.pivot.collections.Map)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 PostQuery (org.apache.pivot.web.PostQuery)1