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  org.apache.cayenne.map.Procedure;
 import  org.apache.cayenne.map.event.ProcedureEvent;
 import  org.apache.cayenne.util.Util;
 import  org.apache.cayenne.validation.ValidationException;
 
 import  com.jgoodies.forms.builder.PanelBuilder;
 import  com.jgoodies.forms.layout.CellConstraints;
 import  com.jgoodies.forms.layout.FormLayout;

A panel for editing stored procedure general settings, such as name, schema, etc.
 
 public class ProcedureTab extends JPanel implements ProcedureDisplayListener,
         ExistingSelectionProcessor {
 
     protected ProjectController eventController;
     protected TextAdapter name;
     protected TextAdapter schema;
     protected JCheckBox returnsValue;
     protected boolean ignoreChange;
 
     public ProcedureTab(ProjectController eventController) {
         this. = eventController;
 
         initView();
         initController();
     }
 
     private void initView() {
         // create widgets
 
         this. = new TextAdapter(new JTextField()) {
 
             protected void updateModel(String text) {
                 setProcedureName(text);
             }
         };
 
         this. = new TextAdapter(new JTextField()) {
 
             protected void updateModel(String text) {
                 setSchema(text);
             }
         };
 
         this. = new JCheckBox();
 
         JLabel returnValueHelp = new JLabel("(first parameter will be used as return value)");
         returnValueHelp.setFont(returnValueHelp.getFont().deriveFont(10));
 
         // assemble
         FormLayout layout = new FormLayout(
                 "right:max(50dlu;pref), 3dlu, left:max(20dlu;pref), 3dlu, fill:150dlu",
                 "p, 3dlu, p, 3dlu, p, 3dlu, p");
 
         CellConstraints cc = new CellConstraints();
         PanelBuilder builder = new PanelBuilder(layout);
         builder.setDefaultDialogBorder();
 
         builder.addSeparator("Stored Procedure Configuration"cc.xywh(1, 1, 5, 1));
         builder.addLabel("Procedure Name:"cc.xy(1, 3));
         builder.add(.getComponent(), cc.xywh(3, 3, 3, 1));
        builder.addLabel("Schema:"cc.xy(1, 5));
        builder.add(.getComponent(), cc.xywh(3, 5, 3, 1));
        builder.addLabel("Returns Value:"cc.xy(1, 7));
        builder.add(cc.xy(3, 7));
        builder.add(returnValueHelpcc.xy(5, 7));
        this.setLayout(new BorderLayout());
        this.add(builder.getPanel(), .);
    }
    private void initController() {
        .addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                Procedure procedure = .getCurrentProcedure();
                if (procedure != null && !) {
                    procedure.setReturningValue(.isSelected());
                    .fireProcedureEvent(new ProcedureEvent(
                            ProcedureTab.this,
                            procedure));
                }
            }
        });
    }
    
    public void processExistingSelection(EventObject e) {
        ProcedureDisplayEvent pde = new ProcedureDisplayEvent(
                this,
                .getCurrentProcedure(),
                .getCurrentDataMap(),
                .getCurrentDataDomain());
    }

    
Invoked when currently selected Procedure object is changed.
    public synchronized void currentProcedureChanged(ProcedureDisplayEvent e) {
        Procedure procedure = e.getProcedure();
        if (procedure == null || !e.isProcedureChanged()) {
            return;
        }
        .setText(procedure.getName());
        .setText(procedure.getSchema());
         = true;
        .setSelected(procedure.isReturningValue());
         = false;
    }
    void setProcedureName(String newName) {
        if (newName != null && newName.trim().length() == 0) {
            newName = null;
        }
        Procedure procedure = .getCurrentProcedure();
        if (procedure == null || Util.nullSafeEquals(newNameprocedure.getName())) {
            return;
        }
        if (newName == null) {
            throw new ValidationException("Procedure name is required.");
        }
        else if (procedure.getDataMap().getProcedure(newName) == null) {
            // completely new name, set new name for entity
            ProcedureEvent e = new ProcedureEvent(thisprocedureprocedure.getName());
            ProjectUtil.setProcedureName(procedure.getDataMap(), procedurenewName);
            .fireProcedureEvent(e);
        }
        else {
            // there is an entity with the same name
            throw new ValidationException("There is another procedure with name '"
                    + newName
                    + "'.");
        }
    }
    void setSchema(String text) {
        if (text != null && text.trim().length() == 0) {
            text = null;
        }
        Procedure procedure = .getCurrentProcedure();
        if (procedure != null && !Util.nullSafeEquals(procedure.getSchema(), text)) {
            procedure.setSchema(text);
            .fireProcedureEvent(new ProcedureEvent(thisprocedure));
        }
    }
New to GrepCode? Check out our FAQ X