/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.wcs.liquifacemaven.component; /* * #%L * Liquiface - GUI for Liquibase * %% * Copyright (C) 2013 Webstar Csoport Kft. * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ import com.google.common.eventbus.Subscribe; import com.wcs.netbeans.liquiface.eventbus.LiquifaceEventBus; import com.wcs.netbeans.liquiface.eventbus.event.RedrawGlobalSceneEvent; import com.wcs.netbeans.liquiface.eventbus.event.ResetFiltersEvent; import com.wcs.netbeans.liquiface.eventbus.event.SynchronizeFiltersEvent; import com.wcs.netbeans.liquiface.facade.FilterFacade; import com.wcs.netbeans.liquiface.facade.ModelFacade; import com.wcs.netbeans.liquiface.logic.TableNeighborFilter; import com.wcs.netbeans.liquiface.logic.TableNeighborFilter.TableNeighborFilterType; import com.wcs.netbeans.liquiface.model.Table; import java.util.ArrayList; import java.util.List; import javax.swing.ButtonGroup; import javax.swing.DefaultComboBoxModel; /** * * @author botond */ public class TableRelationFilter extends javax.swing.JPanel { private ButtonGroup typeGroup; /** * Creates new form TableRelationFilter */ public TableRelationFilter() { initComponents(); initTableNameComboBox(); typeGroup = new ButtonGroup(); typeGroup.add(outgoingRelationsRadio); typeGroup.add(incomingRelationsRadio); typeGroup.add(bothRelationsRadio); typeGroup.setSelected(bothRelationsRadio.getModel(), true); } @Subscribe public void resetFilter(ResetFiltersEvent event) { resetFilter(); } private void resetFilter() { initTableNameComboBox(); } @Subscribe public void synchronizeFilter(SynchronizeFiltersEvent event) { Object selected = relationFilterTableName.getSelectedItem(); resetFilter(); if (selected != null) { relationFilterTableName.setSelectedItem(selected); } } private void initTableNameComboBox() { List<Table> tables = ModelFacade.getInstance().getTables(); List<String> tableNames = new ArrayList<String>(); for (Table table : tables) { tableNames.add(table.getName()); } relationFilterTableName.setModel(new DefaultComboBoxModel(tableNames.toArray())); } private TableNeighborFilterType getSelectedFilterType() { if (bothRelationsRadio.isSelected()) { return TableNeighborFilterType.BOTH; } if (incomingRelationsRadio.isSelected()) { return TableNeighborFilterType.INCOMING; } if (outgoingRelationsRadio.isSelected()) { return TableNeighborFilterType.OUTGOING; } return null; } /** * 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() { jLabel1 = new javax.swing.JLabel(); relationFilterTableName = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); relationFilterDepth = new javax.swing.JSlider(); relationFilterButton = new javax.swing.JButton(); outgoingRelationsRadio = new javax.swing.JRadioButton(); incomingRelationsRadio = new javax.swing.JRadioButton(); bothRelationsRadio = new javax.swing.JRadioButton(); jLabel3 = new javax.swing.JLabel(); clearButton = new javax.swing.JButton(); org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.jLabel1.text")); // NOI18N relationFilterTableName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { })); org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.jLabel2.text")); // NOI18N relationFilterDepth.setMajorTickSpacing(1); relationFilterDepth.setMaximum(5); relationFilterDepth.setMinorTickSpacing(1); relationFilterDepth.setPaintLabels(true); relationFilterDepth.setPaintTicks(true); relationFilterDepth.setSnapToTicks(true); relationFilterDepth.setValue(1); org.openide.awt.Mnemonics.setLocalizedText(relationFilterButton, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.relationFilterButton.text")); // NOI18N relationFilterButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { relationFilterButtonActionPerformed(evt); } }); org.openide.awt.Mnemonics.setLocalizedText(outgoingRelationsRadio, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.outgoingRelationsRadio.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(incomingRelationsRadio, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.incomingRelationsRadio.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(bothRelationsRadio, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.bothRelationsRadio.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.jLabel3.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(clearButton, org.openide.util.NbBundle.getMessage(TableRelationFilter.class, "TableRelationFilter.clearButton.text")); // NOI18N clearButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clearButtonActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(relationFilterTableName, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(relationFilterDepth, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(incomingRelationsRadio) .addComponent(outgoingRelationsRadio) .addComponent(bothRelationsRadio) .addGroup(layout.createSequentialGroup() .addComponent(relationFilterButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(clearButton))) .addGap(0, 0, Short.MAX_VALUE)))))) .addGroup(layout.createSequentialGroup() .addGap(95, 95, 95) .addComponent(jLabel1) .addGap(0, 89, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(relationFilterTableName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(relationFilterDepth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(outgoingRelationsRadio) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(incomingRelationsRadio) .addComponent(jLabel3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(bothRelationsRadio) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(relationFilterButton) .addComponent(clearButton)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void relationFilterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_relationFilterButtonActionPerformed String tableName = (String) relationFilterTableName.getSelectedItem(); if (tableName != null && !tableName.isEmpty()) { ModelFacade modelFacade = ModelFacade.getInstance(); Table table = modelFacade.getTableByName(tableName); int depth = relationFilterDepth.getValue(); TableNeighborFilterType type = getSelectedFilterType(); FilterFacade.getInstance().setFilteredTables(new TableNeighborFilter(modelFacade.getTables(), table, depth, type).getFilteredTables()); LiquifaceEventBus.getInstance().post(new RedrawGlobalSceneEvent()); } }//GEN-LAST:event_relationFilterButtonActionPerformed private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed FilterFacade.getInstance().setFilteredTables(new ArrayList<Table>()); LiquifaceEventBus.getInstance().post(new RedrawGlobalSceneEvent()); }//GEN-LAST:event_clearButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButton bothRelationsRadio; private javax.swing.JButton clearButton; private javax.swing.JRadioButton incomingRelationsRadio; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JRadioButton outgoingRelationsRadio; private javax.swing.JButton relationFilterButton; private javax.swing.JSlider relationFilterDepth; private javax.swing.JComboBox relationFilterTableName; // End of variables declaration//GEN-END:variables }