package it.unibas.lunatic.gui.window;

import it.unibas.lunatic.gui.ExplorerTopComponent;
import it.unibas.lunatic.gui.R;
import it.unibas.lunatic.gui.node.scenario.OrderingAttributeNode;
import it.unibas.lunatic.gui.table.TablePopupFactory;
import org.netbeans.swing.outline.DefaultOutlineModel;
import org.netbeans.swing.outline.Outline;
import org.openide.nodes.Node;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
 * Top component which displays something.
 */
//@ConvertAsProperties(
//        dtd = "-//it.unibas.lunatic.gui//DbTable//EN",
//        autostore = false)
@TopComponent.Description(
        preferredID = R.Window.ORDERING_ATTRIBUTES_TABLE,
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "properties", openAtStartup = false)
@Messages({
    "COL_Attribute=attribute",
    "CTL_OrderingAttributesAction=Ordering attributes",
    "CTL_OrderingAttributesTopComponent=Ordering attributes"
})
public final class OrderingAttributesTopComponent extends ExplorerTopComponent {

    public OrderingAttributesTopComponent() {
        initComponents();
        initTable();
        setName(Bundle.CTL_OrderingAttributesTopComponent());
        setToolTipText(Bundle.CTL_OrderingAttributesTopComponent());
        associateExplorerLookup();
    }

    /**
     * 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        outlineView1 = new org.openide.explorer.view.OutlineView();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        outlineView1.setDragSource(false);
        outlineView1.setDropTarget(false);
        add(outlineView1);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.openide.explorer.view.OutlineView outlineView1;
    // End of variables declaration//GEN-END:variables
    private OrderingAttributesListener listener = new OrderingAttributesListener();

    @Override
    public void componentOpened() {
        listener.register(this);
    }

    @Override
    public void componentClosed() {
        listener.remove();
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.3");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }

    private void initTable() {
        Outline outline = outlineView1.getOutline();
        outline.setRootVisible(false);
//        outline.setAutoResizeMode(ETable.AUTO_RESIZE_OFF);
//        TableColumnModel columnModel = outline.getColumnModel();
//        ETableColumn column = (ETableColumn) columnModel.getColumn(0);
//        ((ETableColumnModel) columnModel).setColumnHidden(column, true);
        ((DefaultOutlineModel) outline.getOutlineModel()).setNodesColumnLabel(Bundle.COL_Attribute());
        OrderingAttributeNode.createTableColumns(outlineView1);
        outline.setFullyNonEditable(true);
    }

    @Override
    public void setRootContext(Node node) {
        explorer.setRootContext(node);
    }

    @Override
    public void removeRootContext() {
        explorer.setRootContext(Node.EMPTY);
    }
}