Search in sources :

Example 1 with ToolBar

use of com.revolsys.swing.toolbar.ToolBar in project com.revolsys.open by revolsys.

the class LayerRecordForm method addToolBar.

protected ToolBar addToolBar(final AbstractRecordLayer layer) {
    this.toolBar = new ToolBar();
    add(this.toolBar, BorderLayout.NORTH);
    final RecordDefinition recordDefinition = getRecordDefinition();
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    final boolean hasGeometry = geometryField != null;
    final EnableCheck editable = new ObjectPropertyEnableCheck(this, "editable");
    if (layer != null) {
        final MenuFactory menuFactory = MenuFactory.findMenu(layer);
        if (menuFactory != null) {
            this.toolBar.addButtonTitleIcon("menu", "Layer Menu", "menu", () -> menuFactory.showMenu(layer, this, 10, 10));
        }
    }
    final EnableCheck deletableEnableCheck = editable.and(new ObjectPropertyEnableCheck(this, "deletable"));
    this.toolBar.addButton("record", "Delete Record", "table_row_delete", deletableEnableCheck, this::deleteRecord);
    // Cut, Copy Paste
    this.toolBar.addButton("dnd", "Copy Record", "page_copy", (EnableCheck) null, this::dataTransferCopy);
    if (hasGeometry) {
        this.toolBar.addButton("dnd", "Copy Geometry", "geometry_copy", (EnableCheck) null, this::copyGeometry);
    }
    this.toolBar.addButton("dnd", "Paste Record", "paste_plain", editable, this::dataTransferPaste);
    if (hasGeometry) {
        this.toolBar.addButton("dnd", "Paste Geometry", "geometry_paste", editable, this::pasteGeometry);
    }
    final EnableCheck canUndo = new ObjectPropertyEnableCheck(this.undoManager, "canUndo");
    final EnableCheck canRedo = new ObjectPropertyEnableCheck(this.undoManager, "canRedo");
    final EnableCheck modifiedOrDeleted = new ObjectPropertyEnableCheck(this, "modifiedOrDeleted");
    this.toolBar.addButton("changes", "Revert Record", "arrow_revert", modifiedOrDeleted, this::revertChanges);
    this.toolBar.addButton("changes", "Revert Empty Fields", "field_empty_revert", new ObjectPropertyEnableCheck(this, "hasModifiedEmptyFields"), this::revertEmptyFields);
    this.toolBar.addButton("changes", "Undo", "arrow_undo", canUndo, this.undoManager::undo);
    this.toolBar.addButton("changes", "Redo", "arrow_redo", canRedo, this.undoManager::redo);
    if (hasGeometry) {
        this.toolBar.addButtonTitleIcon("zoom", "Zoom to Record", "magnifier_zoom_selected", () -> {
            final LayerRecord record = getRecord();
            layer.zoomToRecord(record);
        });
        this.toolBar.addButtonTitleIcon("zoom", "Pan to Record", "pan_selected", () -> {
            final LayerRecord record = getRecord();
            final MapPanel mapPanel = layer.getMapPanel();
            if (mapPanel != null) {
                mapPanel.panToRecord(record);
            }
        });
    }
    // Geometry manipulation
    if (hasGeometry) {
        final DataType geometryDataType = geometryField.getDataType();
        if (geometryDataType == DataTypes.LINE_STRING || geometryDataType == DataTypes.MULTI_LINE_STRING) {
            if (DirectionalFields.getProperty(recordDefinition).hasDirectionalFields()) {
                this.toolBar.addButton("geometry", FLIP_RECORD_NAME, FLIP_RECORD_ICON, editable, this::flipRecordOrientation);
                this.toolBar.addButton("geometry", FLIP_LINE_ORIENTATION_NAME, FLIP_LINE_ORIENTATION_ICON, editable, this::flipLineOrientation);
                this.toolBar.addButton("geometry", FLIP_FIELDS_NAME, FLIP_FIELDS_ICON, editable, this::flipFields);
            } else {
                this.toolBar.addButton("geometry", "Flip Line Orientation", "flip_line", editable, this::flipLineOrientation);
            }
        }
    }
    return this.toolBar;
}
Also used : ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) MapPanel(com.revolsys.swing.map.MapPanel) MenuFactory(com.revolsys.swing.menu.MenuFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ToolBar(com.revolsys.swing.toolbar.ToolBar) DataType(com.revolsys.datatype.DataType) EnableCheck(com.revolsys.swing.action.enablecheck.EnableCheck) ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 2 with ToolBar

use of com.revolsys.swing.toolbar.ToolBar in project com.revolsys.open by revolsys.

the class RecordLayerTablePanel method newToolBar.

protected void newToolBar(final Map<String, Object> pluginConfig) {
    final ToolBar toolBar = getToolBar();
    final RecordDefinition recordDefinition = getRecordDefinition();
    final boolean hasGeometry = recordDefinition.hasGeometryField();
    final MenuFactory layerMenuFactory = MenuFactory.findMenu(this.layer);
    if (layerMenuFactory != null) {
        toolBar.addButtonTitleIcon("menu", "Layer Menu", "menu", () -> layerMenuFactory.showMenu(this.layer, this, 10, 10));
    }
    if (hasGeometry) {
        final EnableCheck hasSelectedRecords = new ObjectPropertyEnableCheck(this.layer, "hasSelectedRecords");
        toolBar.addButton("layer", "Zoom to Selected", "magnifier_zoom_selected", hasSelectedRecords, this.layer::zoomToSelected);
        toolBar.addButton("layer", "Pan to Selected", "pan_selected", hasSelectedRecords, this.layer::panToSelected);
    }
    final RecordLayerTable table = getTable();
    final TableRowCount tableRowCount = new TableRowCount(table);
    toolBar.addComponent("count", tableRowCount);
    toolBar.addButtonTitleIcon("table", "Refresh", "table_refresh", this.layer::refresh);
    toolBar.addButtonTitleIcon("table", "Export Records", "table_save", new ObjectPropertyEnableCheck(tableRowCount, "rowCount", 0, true), () -> actionExportRecords());
    this.fieldSetsButton = toolBar.addButtonTitleIcon("table", "Field Sets", "fields_filter", () -> actionShowFieldSetsMenu());
    this.fieldFilterPanel = new FieldFilterPanel(this, this.tableModel, pluginConfig);
    if (this.fieldFilterPanel.isVisible()) {
        toolBar.addComponent("search", this.fieldFilterPanel);
        toolBar.addButtonTitleIcon("search", "Advanced Search", "filter_edits", this.fieldFilterPanel::showAdvancedFilter);
        final EnableCheck hasFilter = new ObjectPropertyEnableCheck(this.tableModel, "hasFilter");
        toolBar.addButton("search", "Clear Search", "filter_delete", hasFilter, this.fieldFilterPanel::clear);
        final EnableCheck hasFilterHistory = new ObjectPropertyEnableCheck(this.tableModel, "hasFilterHistory");
        toolBar.addButton("search", ConsumerAction.action("Search History", Icons.getIconWithBadge("book", "filter"), hasFilterHistory, (event) -> {
            final Object source = event.getSource();
            Component component = null;
            if (source instanceof Component) {
                component = (Component) source;
            }
            final BaseJPopupMenu menu = new BaseJPopupMenu();
            for (final Condition filter : this.tableModel.getFilterHistory()) {
                menu.addMenuItem(filter.toString(), () -> this.fieldFilterPanel.setFilter(filter));
            }
            menu.showMenu(component, 0, 20);
        }));
    }
    // Filter buttons
    boolean first = true;
    for (final TableRecordsMode fieldFilterMode : this.tableModel.getFieldFilterModes()) {
        final String key = fieldFilterMode.getKey();
        final String title = fieldFilterMode.getTitle();
        final Icon icon = fieldFilterMode.getIcon();
        final EnableCheck enableCheck = fieldFilterMode.getEnableCheck();
        final JToggleButton button = toolBar.addToggleButton(FILTER_FIELD, -1, null, title, icon, enableCheck, () -> {
            if (this.tableModel != null) {
                this.tableModel.setTableRecordsMode(fieldFilterMode);
            }
        });
        this.buttonByMode.put(FILTER_FIELD + "_" + key, button);
        if (first) {
            button.doClick();
            first = false;
        }
    }
    if (hasGeometry) {
        final JToggleButton showAllGeometries = addGeometryFilterToggleButton(toolBar, -1, "Show All Records ", "world_filter", "all", null);
        showAllGeometries.doClick();
        addGeometryFilterToggleButton(toolBar, -1, "Show Records on Map", "map_filter", "boundingBox", new ObjectPropertyEnableCheck(this.tableModel, "filterByBoundingBoxSupported"));
    }
}
Also used : FieldCalculator(com.revolsys.swing.map.layer.record.component.FieldCalculator) Icons(com.revolsys.swing.Icons) EnableCheck(com.revolsys.swing.action.enablecheck.EnableCheck) JToggleButton(javax.swing.JToggleButton) Property(com.revolsys.util.Property) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) RecordLayerTableModel(com.revolsys.swing.map.layer.record.table.model.RecordLayerTableModel) Map(java.util.Map) MenuFactory(com.revolsys.swing.menu.MenuFactory) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) Condition(com.revolsys.record.query.Condition) Font(java.awt.Font) Maps(com.revolsys.collection.map.Maps) BorderFactory(javax.swing.BorderFactory) Icon(javax.swing.Icon) RecordRowTable(com.revolsys.swing.table.record.RecordRowTable) Component(java.awt.Component) FieldNamesSetPanel(com.revolsys.swing.map.form.FieldNamesSetPanel) PropertyChangeListener(java.beans.PropertyChangeListener) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) SetRecordsFieldValue(com.revolsys.swing.map.layer.record.component.SetRecordsFieldValue) JTable(javax.swing.JTable) MapSerializer(com.revolsys.io.map.MapSerializer) FieldFilterPanel(com.revolsys.swing.map.layer.record.component.FieldFilterPanel) TableRecordsMode(com.revolsys.swing.map.layer.record.table.model.TableRecordsMode) JPanel(javax.swing.JPanel) AbstractLayer(com.revolsys.swing.map.layer.AbstractLayer) RecordTableCellEditor(com.revolsys.swing.table.record.editor.RecordTableCellEditor) ToolBar(com.revolsys.swing.toolbar.ToolBar) RecordDefinition(com.revolsys.record.schema.RecordDefinition) LayerRecordMenu(com.revolsys.swing.map.layer.record.LayerRecordMenu) HashMap(java.util.HashMap) BaseJPopupMenu(com.revolsys.swing.menu.BaseJPopupMenu) SwingConstants(javax.swing.SwingConstants) VerticalLayout(org.jdesktop.swingx.VerticalLayout) SwingUtilities(javax.swing.SwingUtilities) TableCellEditor(javax.swing.table.TableCellEditor) JMenuItem(javax.swing.JMenuItem) ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) RunnableAction(com.revolsys.swing.action.RunnableAction) MapEx(com.revolsys.collection.map.MapEx) ConsumerAction(com.revolsys.swing.action.ConsumerAction) PropertyChangeEvent(java.beans.PropertyChangeEvent) MapPanel(com.revolsys.swing.map.MapPanel) JButton(javax.swing.JButton) TablePanel(com.revolsys.swing.table.TablePanel) JPopupMenu(javax.swing.JPopupMenu) TableRowCount(com.revolsys.swing.table.TableRowCount) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) Condition(com.revolsys.record.query.Condition) ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) EnableCheck(com.revolsys.swing.action.enablecheck.EnableCheck) ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) TableRecordsMode(com.revolsys.swing.map.layer.record.table.model.TableRecordsMode) RecordDefinition(com.revolsys.record.schema.RecordDefinition) MenuFactory(com.revolsys.swing.menu.MenuFactory) JToggleButton(javax.swing.JToggleButton) ToolBar(com.revolsys.swing.toolbar.ToolBar) BaseJPopupMenu(com.revolsys.swing.menu.BaseJPopupMenu) Icon(javax.swing.Icon) Component(java.awt.Component) TableRowCount(com.revolsys.swing.table.TableRowCount) FieldFilterPanel(com.revolsys.swing.map.layer.record.component.FieldFilterPanel)

Example 3 with ToolBar

use of com.revolsys.swing.toolbar.ToolBar in project com.revolsys.open by revolsys.

the class FieldCalculator method initFieldPanel.

@Override
protected JPanel initFieldPanel() {
    final FieldDefinition fieldDefinition = this.getFieldDefinition();
    final String fieldName = fieldDefinition.getName();
    final JPanel fieldPanel = new JPanel(new VerticalLayout());
    final ToolBar toolBar = new ToolBar();
    fieldPanel.add(toolBar);
    this.expressionField = new TextArea("script", 8, 1);
    fieldPanel.add(new JScrollPane(this.expressionField));
    this.expressionField.getDocument().addDocumentListener(this);
    final AbstractRecordLayer layer = getLayer();
    final List<String> fieldNames = layer.getFieldNames();
    final ComboBox<String> fieldNamesField = ComboBox.newComboBox("fieldNames", fieldNames, (final Object name) -> {
        return layer.getFieldTitle((String) name);
    });
    toolBar.addComponent("fieldName", fieldNamesField);
    toolBar.add(fieldNamesField);
    fieldNamesField.setMaximumSize(new Dimension(250, 30));
    final Runnable addFieldAction = () -> {
        final String selectedFieldName = fieldNamesField.getFieldValue();
        insertText(selectedFieldName);
    };
    toolBar.addButton("fieldName", "Add field name", "add", addFieldAction);
    for (final String text : Arrays.asList("+", "-", "*", "/")) {
        addTextButton("operators", toolBar, text, text);
    }
    addTextButton("condition", toolBar, "if", "if (expression) {\n  newValue;\n} else {\n  " + fieldName + ";\n}");
    addTextButton("codeTable", toolBar, "Code ID", "codeId('codeFieldName', codeValue)");
    addTextButton("codeTable", toolBar, "Code Value", "codeValue('codeFieldName', codeValue)");
    return fieldPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TextArea(com.revolsys.swing.field.TextArea) JTextArea(javax.swing.JTextArea) FieldDefinition(com.revolsys.record.schema.FieldDefinition) Dimension(java.awt.Dimension) ToolBar(com.revolsys.swing.toolbar.ToolBar) VerticalLayout(org.jdesktop.swingx.VerticalLayout) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Example 4 with ToolBar

use of com.revolsys.swing.toolbar.ToolBar in project com.revolsys.open by revolsys.

the class RecordValidationDialog method showErrorDialog.

private void showErrorDialog(final String title, final Consumer<RecordValidationDialog> successAction, final Consumer<RecordValidationDialog> cancelAction) {
    Invoke.later(() -> {
        final String layerPath = this.layer.getPath();
        final Window window = SwingUtil.getActiveWindow();
        final JDialog dialog = new JDialog(window, "Error " + title + " for " + layerPath, ModalityType.APPLICATION_MODAL);
        dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        dialog.setLayout(new BorderLayout());
        final ToolBar toolBar = new ToolBar();
        toolBar.addButtonTitleIcon("default", "Cancel " + title, "table_cancel", () -> {
            dialog.setVisible(false);
            cancelAction.accept(this);
        });
        toolBar.addButtonTitleIcon("default", "Save valid records", "table_save", () -> {
            dialog.setVisible(false);
            validateRecords(this.invalidRecords, true);
            successAction.accept(this);
        });
        final TablePanel invalidRecordsTablePanel = newInvalidRecordsTablePanel();
        final JLabel message = new JLabel("<html><b style=\"color:red\">Edit the invalid fields (red background) for the invalid records.</b><br />" + " Valid records will have a green background when edited.</html>");
        message.setBorder(BorderFactory.createTitledBorder(layerPath));
        final BasePanel panel = new // 
        BasePanel(// 
        new VerticalLayout(), // 
        toolBar, // 
        message, // 
        invalidRecordsTablePanel);
        panel.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 6));
        if (!this.validRecords.isEmpty()) {
            final TablePanel validRecordsTablePanel = newValidRecordsTablePanel();
            panel.add(validRecordsTablePanel);
        }
        dialog.add(panel, BorderLayout.NORTH);
        final Rectangle screenBounds = SwingUtil.getScreenBounds();
        dialog.pack();
        dialog.setSize(screenBounds.width - 50, dialog.getPreferredSize().height);
        SwingUtil.setLocationCentre(screenBounds, dialog);
        dialog.setVisible(true);
        SwingUtil.dispose(dialog);
    });
}
Also used : Window(java.awt.Window) BasePanel(com.revolsys.swing.component.BasePanel) BorderLayout(java.awt.BorderLayout) ToolBar(com.revolsys.swing.toolbar.ToolBar) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel) VerticalLayout(org.jdesktop.swingx.VerticalLayout) JDialog(javax.swing.JDialog) TablePanel(com.revolsys.swing.table.TablePanel)

Example 5 with ToolBar

use of com.revolsys.swing.toolbar.ToolBar in project com.revolsys.open by revolsys.

the class LayerRecordTableModel method newTablePanel.

public TablePanel newTablePanel() {
    final LayerRecordForm form = this.form.get();
    final BaseJTable table = AbstractSingleRecordTableModel.newTable(this);
    FormAllFieldsModifiedPredicate.add(form, table);
    FormAllFieldsErrorPredicate.add(form, table);
    final TableColumnModel columnModel = table.getColumnModel();
    for (int i = 0; i < columnModel.getColumnCount(); i++) {
        final TableColumn column = columnModel.getColumn(i);
        if (i == 2) {
            final TableCellEditor cellEditor = column.getCellEditor();
            cellEditor.addCellEditorListener(form);
        }
    }
    final TablePanel tablePanel = new TablePanel(table);
    final ToolBar toolBar = tablePanel.getToolBar();
    toolBar.addComponent("default", this.fieldNamesSetNamesField);
    toolBar.addButtonTitleIcon("default", "Edit Field Sets", "fields_filter_edit", () -> {
        final String fieldNamesSetName = FieldNamesSetPanel.showDialog(this.layer);
        if (Property.hasValue(fieldNamesSetName)) {
            this.fieldNamesSetNamesField.setFieldValue(fieldNamesSetName);
        }
    });
    int maxHeight = 500;
    for (final GraphicsDevice device : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        final GraphicsConfiguration graphicsConfiguration = device.getDefaultConfiguration();
        final Rectangle bounds = graphicsConfiguration.getBounds();
        maxHeight = Math.min(bounds.height, maxHeight);
    }
    final int preferredHeight = Math.min(maxHeight, (this.getRowCount() + 1) * 20 + 45);
    tablePanel.setMinimumSize(new Dimension(100, preferredHeight));
    tablePanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, maxHeight));
    tablePanel.setPreferredSize(new Dimension(800, preferredHeight));
    return tablePanel;
}
Also used : LayerRecordForm(com.revolsys.swing.map.form.LayerRecordForm) Rectangle(java.awt.Rectangle) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) GraphicsConfiguration(java.awt.GraphicsConfiguration) GraphicsDevice(java.awt.GraphicsDevice) BaseJTable(com.revolsys.swing.table.BaseJTable) ToolBar(com.revolsys.swing.toolbar.ToolBar) TableCellEditor(javax.swing.table.TableCellEditor) TablePanel(com.revolsys.swing.table.TablePanel)

Aggregations

ToolBar (com.revolsys.swing.toolbar.ToolBar)5 TablePanel (com.revolsys.swing.table.TablePanel)3 VerticalLayout (org.jdesktop.swingx.VerticalLayout)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 EnableCheck (com.revolsys.swing.action.enablecheck.EnableCheck)2 ObjectPropertyEnableCheck (com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck)2 MapPanel (com.revolsys.swing.map.MapPanel)2 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)2 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)2 MenuFactory (com.revolsys.swing.menu.MenuFactory)2 Dimension (java.awt.Dimension)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)1 MapEx (com.revolsys.collection.map.MapEx)1 Maps (com.revolsys.collection.map.Maps)1 DataType (com.revolsys.datatype.DataType)1 MapSerializer (com.revolsys.io.map.MapSerializer)1 Condition (com.revolsys.record.query.Condition)1