/*
* Copyright 2013 Serdar.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.fub.maps.project.ui.component;
import de.fub.maps.project.aggregator.pipeline.AbstractAggregationProcess;
import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.text.MessageFormat;
import javax.swing.JButton;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
/**
*
* @author Serdar
*/
public class WidgetPropertySheet extends javax.swing.JPanel implements ExplorerManager.Provider {
private static final long serialVersionUID = 1L;
private final ExplorerManager explorerManager = new ExplorerManager();
private Node node;
/**
* Creates new form WidgetPropertySheet
*/
public WidgetPropertySheet() {
initComponents();
}
public WidgetPropertySheet(Node node) {
this();
this.node = node;
init();
}
private void init() {
if (node != null) {
try {
explorerManager.setRootContext(node);
explorerManager.setSelectedNodes(new Node[]{node});
} catch (PropertyVetoException ex) {
Exceptions.printStackTrace(ex);
}
}
}
public JButton getCancelButton() {
return cancelButton;
}
public JButton getSaveButton() {
return saveButton;
}
public Object[] getButtons() {
return new Object[]{getSaveButton(), getCancelButton()};
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
saveButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
propertySheetView1 = new org.openide.explorer.propertysheet.PropertySheetView();
org.openide.awt.Mnemonics.setLocalizedText(saveButton, org.openide.util.NbBundle.getMessage(WidgetPropertySheet.class, "WidgetPropertySheet.saveButton.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(WidgetPropertySheet.class, "WidgetPropertySheet.cancelButton.text")); // NOI18N
setLayout(new java.awt.BorderLayout());
add(propertySheetView1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private org.openide.explorer.propertysheet.PropertySheetView propertySheetView1;
private javax.swing.JButton saveButton;
// End of variables declaration//GEN-END:variables
@Override
public ExplorerManager getExplorerManager() {
return explorerManager;
}
public static Dialog createWidgetPropertySheet(final AbstractAggregationProcess process) {
final WidgetPropertySheet widgetPropertySheet = new WidgetPropertySheet(new FilterNode(process.getNodeDelegate()));
DialogDescriptor dd = new DialogDescriptor(widgetPropertySheet, MessageFormat.format("{0} Settings", process.getName()), true, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e != null
&& e.getSource().equals(widgetPropertySheet.getSaveButton())
&& process.getAggregator() != null) {
process.getAggregator().updateSource();
}
}
}); // NO18N
dd.setOptions(widgetPropertySheet.getButtons());
dd.setClosingOptions(widgetPropertySheet.getButtons());
return DialogDisplayer.getDefault().createDialog(dd);
}
}