Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.guvnor.client.packages;
  /*
   * Copyright 2005 JBoss Inc
   *
   * Licensed 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.
  */
 
 
 
 import  org.drools.guvnor.client.common.FormStyleLayout;
 import  org.drools.guvnor.client.common.GenericCallback;
 import  org.drools.guvnor.client.common.HTMLFileManagerFields;
 import  org.drools.guvnor.client.common.ImageButton;
 import  org.drools.guvnor.client.rpc.RepositoryServiceFactory;
 
 import  com.google.gwt.core.client.GWT;
 import  com.google.gwt.user.client.Command;
 import  com.google.gwt.user.client.Window;
 import  com.google.gwt.user.client.ui.*;
 import  com.gwtext.client.util.Format;

This is the wizard used when creating new packages or importing them.

Author(s):
Michael Neale
 
 public class NewPackageWizard extends FormStylePopup {
 
     private TextBox nameBox;
     private TextBox descBox;
     private final FormStyleLayout importLayout = new FormStyleLayout();
     private final FormStyleLayout newPackageLayout = new FormStyleLayout();
     private static Constants constants = ((Constants) GWT.create(Constants.class));
 
 
     public NewPackageWizard(final Command afterCreatedEvent) {
         super"images/new_wiz.gif".CreateANewPackage());  //NON-NLS
          = new TextBox();
          = new TextBox();
 
         //newPackageLayout.addRow( new HTML(constants.CreateNewPackage()) );
 
 
         .addAttribute(.NameColon(),  );
         .addAttribute(.DescriptionColon(),  );
 
 
 
         .setTitle(.PackageNameTip());
 
         RadioButton newPackage = new RadioButton("action".CreateNewPackageRadio());     //NON-NLS
         RadioButton importPackage = new RadioButton("action".ImportFromDrlRadio());     //NON-NLS
         newPackage.setChecked( true );
         .setVisible( true );
 
         newPackage.addClickListener( new ClickListener() {        
             public void onClick(Widget w) {
                 .setVisible( true );
                 .setVisible( false );
             }
         });
 
         this.setAfterShow(new Command() {
            public void execute() {
             .setFocus(true);
             }
         } );
 
         .setVisible( false );
 
         importPackage.addClickListener( new ClickListener() {
             public void onClick(Widget arg0) {
                 .setVisible( false );
                 .setVisible( true );
             }
         });
         VerticalPanel ab = new VerticalPanel();
         ab.add( newPackage );
         ab.add( importPackage );
         addAttribute("",  ab );
 
         addRow();
         addRow();
 
         .addAttribute(.DRLFileToImport(), newImportWidget(afterCreatedEventthis) );
        .addRow(new HTML("<br/><b>" + .NoteNewPackageDrlImportWarning() + "</b>"));
        .addRow( new HTML(.ImportDRLDesc1()) );
        .addRow( new HTML(.ImportDRLDesc2()) );
        .addRow( new HTML(.ImportDRLDesc3()) );
        Button create = new Button(.CreatePackage());
        create.addClickListener( new ClickListener() {
            public void onClick(Widget w) {
            	if ( PackageNameValidator.validatePackageName(.getText()) ) {
            		createPackageAction(.getText(), .getText(), afterCreatedEvent);
            		hide();
            	} else {
            		.setText("");
            		Window.alert(.PackageNameCorrectHint());
            	}
            }
        });
        .addAttribute( ""create );
    }
    private void createPackageAction(final String namefinal String descrfinal Command refresh) {
        LoadingPopup.showMessage(.CreatingPackagePleaseWait());
        RepositoryServiceFactory.getService().createPackage( namedescrnew GenericCallback() {
            public void onSuccess(Object data) {
                LoadingPopup.close();
                refresh.execute();
            }
        });
    }
    public static Widget newImportWidget(final Command afterCreatedEventfinal FormStylePopup parent) {
        final FormPanel uploadFormPanel = new FormPanel();
        uploadFormPanel.setAction( GWT.getModuleBaseURL() + "package" );
        uploadFormPanel.setEncoding( FormPanel.ENCODING_MULTIPART );
        uploadFormPanel.setMethod( FormPanel.METHOD_POST );
        HorizontalPanel panel = new HorizontalPanel();
        uploadFormPanel.setWidget( panel );
        final FileUpload upload = new FileUpload();
        upload.setName( HTMLFileManagerFields.CLASSIC_DRL_IMPORT );
        panel.add( upload );
        panel.add(new Label(.upload()));
        ImageButton ok = new ImageButton("images/upload.gif".Import()); //NON-NLS
        ok.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                if (Window.confirm(.ImportMergeWarning())) {
                    LoadingPopup.showMessage(.ImportingDRLPleaseWait());
                    uploadFormPanel.submit();
                }
            }
        });
        panel.add( ok );
        uploadFormPanel.addFormHandler( new FormHandler() {
            public void onSubmitComplete(FormSubmitCompleteEvent event) {
                if (event.getResults().indexOf( "OK" ) > -1) {  //NON-NLS
                    Window.alert(.PackageWasImportedSuccessfully());
                    afterCreatedEvent.execute();
                    parent.hide();
                } else {
                    ErrorPopup.showMessage(Format.format(.UnableToImportIntoThePackage0(), event.getResults()));
                }
                LoadingPopup.close();
            }
            public void onSubmit(FormSubmitEvent event) {
                if ( upload.getFilename().length() == 0 ) {
                    Window.alert(.YouDidNotChooseADrlFileToImport());
                    event.setCancelled( true );
                } else if ( !upload.getFilename().endsWith( ".drl" ) ) { //NON-NLS
                    Window.alert(.YouCanOnlyImportDrlFiles());
                    event.setCancelled( true );
                }
            }
        } );
        return uploadFormPanel;
    }
New to GrepCode? Check out our FAQ X