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.dbentity;
 
 import java.awt.Font;
 
 
 
 import  com.jgoodies.forms.builder.DefaultFormBuilder;
 import  com.jgoodies.forms.layout.FormLayout;
 
 
     protected TextAdapter customPKName;
     protected TextAdapter customPKSize;
 
     public PKCustomSequenceGeneratorPanel(ProjectController mediator) {
         super(mediator);
         initView();
     }
 
     private void initView() {
 
         JLabel note = new JLabel(
                 "* Custom sequences are supported on Oracle and Postgres");
         note.setFont(note.getFont().deriveFont(.).deriveFont(11f));
 
          = new TextAdapter(new JTextField()) {
 
             protected void updateModel(String textthrows ValidationException {
                 setPKName(text);
             }
         };
          = new TextAdapter(new JTextField()) {
 
             protected void updateModel(String textthrows ValidationException {
                 setPKSize(text);
             }
         };
 
         // assemble
 
         DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(
                 "right:70dlu, 3dlu, 20dlu, 3dlu, fill:177dlu",
                 ""));
 
         builder.setDefaultDialogBorder();
 
         builder.append("Sequence Name:".getComponent(), 3);
         builder.append("Cached PK Size:".getComponent());
         builder.nextLine();
         builder.append(""note, 3);
 
         setLayout(new BorderLayout());
         add(builder.getPanel(), .);
     }
 
     public void onInit(DbEntity entity) {
 
         resetStrategy(entityfalsetrue);
 
         if (entity.getPrimaryKeyGenerator() == null) {
             DbKeyGenerator generator = new DbKeyGenerator();
             generator.setGeneratorType(.);
             entity.setPrimaryKeyGenerator(generator);
         }
     }
 
     public void setDbEntity(DbEntity entity) {
         DbKeyGenerator generator = entity.getPrimaryKeyGenerator();
 
         if (generator != null) {
            .setText(generator.getGeneratorName());
            .setText(generator.getKeyCacheSize() != null ? generator
                    .getKeyCacheSize()
                    .toString() : "0");
        }
        else {
            .setText(null);
            .setText(null);
        }
    }
    protected void setPKSize(String text) {
        if (.getCurrentDbEntity() == null
                || .getCurrentDbEntity().getPrimaryKeyGenerator() == null) {
            return;
        }
        int cacheSize = 0;
        if (text != null && text.trim().length() > 0) {
            try {
                cacheSize = Integer.parseInt(text);
            }
            catch (NumberFormatException nfex) {
                throw new ValidationException("Invalid number");
            }
        }
        if (!Util.nullSafeEquals(generator.getKeyCacheSize(), new Integer(cacheSize))) {
            generator.setKeyCacheSize(new Integer(cacheSize));
            .fireDbEntityEvent(new EntityEvent(thisgenerator.getDbEntity()));
        }
    }
    protected void setPKName(String text) {
        if (.getCurrentDbEntity() == null
                || .getCurrentDbEntity().getPrimaryKeyGenerator() == null) {
            return;
        }
        if (text != null && text.trim().length() == 0) {
            text = null;
        }
        if (!Util.nullSafeEquals(textgenerator.getName())) {
            generator.setGeneratorName(text);
            .fireDbEntityEvent(new EntityEvent(thisgenerator.getDbEntity()));
        }
    }
New to GrepCode? Check out our FAQ X