Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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 org.apache.cayenne.modeler.editor;
 
 import java.util.List;
 
 
 import  org.apache.cayenne.map.EntityListener;
 import  org.apache.cayenne.map.event.MapEvent;
 
 import  com.jgoodies.forms.builder.DefaultFormBuilder;


Base abstract class for editing callback mapping on listener class Adds entity listener class processing logic

Version:
1.0 Oct 29, 2007
 
 public abstract class AbstractCallbackListenersTab extends AbstractCallbackMethodsTab {

    
listener class seiection combo
 
     protected JComboBox listenerClassCombo;

    
Constructor

Parameters:
mediator mediator instance
 
     protected AbstractCallbackListenersTab(ProjectController mediator) {
         super(mediator);
     }

    

Returns:
returns entity listeners list
 
     protected abstract List<EntityListener> getEntityListeners();

    

Returns:
action for removing entity listeners
 
     protected abstract CayenneAction getRemoveEntityListenerAction();

    

Returns:
action for creating entity listeners
 
     public abstract CayenneAction getCreateEntityListenerAction();

    
performs GUI components initialization
 
     protected void init() {
         super.init();
 
         .addSeparator();
     }
 
     protected abstract EntityListener getEntityListener(String listenerClass);
 
     private void processEditedListenerClassValue(String newValue) {
         String prevName = .getCurrentListenerClass();
         if (getEntityListener(newValue) == null) {
             EntityListener listener = getEntityListener(prevName);
             if (listener != null) {
                 listener.setClassName(newValue);
                 .fireEntityListenerEvent(new EntityListenerEvent(
                         this,
                        prevName,
                        newValue,
                        MapEvent.CHANGE));
            }
        }
    }


    
init listeners
    protected void initController() {
        super.initController();
        addComponentListener(
                new ComponentAdapter() {
                    public void componentShown(ComponentEvent e) {
                        rebuildListenerClassCombo(null);
                        .setCurrentCallbackType((CallbackType).getSelectedItem());
                        updateCallbackTypeCounters();
                        rebuildTable();
                    }
                }
        );
                new ItemListener() {
                    public void itemStateChanged(ItemEvent e) {
                        if (e.getStateChange() == . && isVisible()) {
                            //detect editing
                            if (.getSelectedIndex() == -1 &&
                                .getSelectedItem() != null) {
                                processEditedListenerClassValue((String).getSelectedItem());
                            }
                            else {
                                //just celeection changed
                                .setCurrentListenerClass((String).getSelectedItem());
                                updateCallbackTypeCounters();
                                rebuildTable();
                            }
                        }
                    }
                }
        );
                new EntityListenerListener() {
                    public void entityListenerAdded(EntityListenerEvent e) {
                        if (isVisible() && getCreateEntityListenerAction() == e.getSource()) {
                            rebuildListenerClassCombo(e.getNewName());
                            rebuildTable();
                        }
                    }
                    public void entityListenerChanged(EntityListenerEvent e) {
                        if (isVisible() && e.getSource() == AbstractCallbackListenersTab.this) {
                            rebuildListenerClassCombo(e.getNewName());
                            rebuildTable();
                        }
                    }
                    public void entityListenerRemoved(EntityListenerEvent e) {
                        if (isVisible() && getRemoveEntityListenerAction() == e.getSource()) {
                            rebuildListenerClassCombo(null);
                            rebuildTable();
                        }
                    }
                }
        );
    }

    
rebuils listener class selection dropdown content and fires selection event

Parameters:
selectedListener listener to be selected after rebuild
    protected void rebuildListenerClassCombo(String selectedListener) {
        List entityListeners = getEntityListeners();
        List listenerClasses = new ArrayList();
        if (entityListeners !=  null) {
            for (EntityListener entityListener : getEntityListeners()) {
                listenerClasses.add(entityListener.getClassName());
            }
        }
                new DefaultComboBoxModel(listenerClasses.toArray())
        );
        getCreateCallbackMethodAction().setEnabled(listenerClasses.size() > 0);
        if (selectedListener == null) {
            if (listenerClasses.size() > 0) {
                .setSelectedIndex(0);
            }
        }
        else {
            .setSelectedItem(selectedListener);
        }
        getRemoveEntityListenerAction().setEnabled(listenerClasses.size() > 0);
        .setEnabled(listenerClasses.size() > 0);
    }


    
adds listener class dropdown to filter bar

Parameters:
builder filter forms builder
    protected void buildFilter(DefaultFormBuilder builder) {
         = CayenneWidgetFactory.createComboBox();
        .setEditable(true);
        builder.append(new JLabel("Listener class:"), );
        builder.nextLine();
        super.buildFilter(builder);
    }
New to GrepCode? Check out our FAQ X