Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 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.
  */
 
 package org.drools.guvnor.client.explorer.navigation.admin.widget;
 
 
 public class ArchivedAssetManager extends Composite {
 
     private AssetServiceAsync assetService = GWT.create(AssetService.class);
     private ModuleServiceAsync moduleService = GWT.create(ModuleService.class);
 
     private static ImagesCore images = (ImagesCore) GWT.create(ImagesCore.class);
 
     private AdminArchivedPagedTable table;
     private ListBox packages = new ListBox(true);
     private ConstantsCore constants = GWT.create(ConstantsCore.class);
     private Button btnRestorePackage;
     private Button btnDeletePackage;
     private EventBus eventBus;
 
     public ArchivedAssetManager(ClientFactory clientFactory,
                                 EventBus eventBus) {
 
         this. = eventBus;
 
         PrettyFormLayout pf = new PrettyFormLayout();
 
         VerticalPanel header = new VerticalPanel();
         header.add(new HTML(.ArchivedItems()));
 
         pf.addHeader(..Backup(),
                 header);
 
         loadPackages();
 
         Command restoreSelectedAssetCommand = new Command() {
 
             public void execute() {
                 if (.getSelectedRowUUIDs() == null) {
                     Window.alert(.PleaseSelectAnItemToRestore());
                     return;
                 }
                 .archiveAssets(.getSelectedRowUUIDs(),
                         false,
                         new GenericCallback<java.lang.Void>() {
                             public void onSuccess(Void arg0) {
                                 Window.alert(.ItemRestored());
                                 .refresh();
                             }
                         });
             }
 
         };
 
         Command deleteSelectedAssetCommand = new Command() {
 
             public void execute() {
                 if (.getSelectedRowUUIDs() == null) {
                     Window.alert(.PleaseSelectAnItemToPermanentlyDelete());
                     return;
                 }
                 if (!Window.confirm(.AreYouSureDeletingAsset())) {
                     return;
                 }
                 .removeAssets(.getSelectedRowUUIDs(),
                         new GenericCallback<java.lang.Void>() {
                             public void onSuccess(Void arg0) {
                                 Window.alert(.ItemDeleted());
                                 .refresh();
                             }
                        });
            }
        };
         = new AdminArchivedPagedTable(
                restoreSelectedAssetCommand,
                deleteSelectedAssetCommand,
                clientFactory);
        HorizontalPanel packagesToolbar = new HorizontalPanel();
            public void onClick(ClickEvent event) {
                if (.getSelectedIndex() == -1) {
                    Window.alert(.PleaseSelectAnItemToRestore());
                    return;
                }
                restorePackage(.getValue(.getSelectedIndex()));
            }
        });
        packagesToolbar.add();
            public void onClick(ClickEvent event) {
                if (.getSelectedIndex() == -1) {
                    Window.alert(.PleaseSelectAnItemToPermanentlyDelete());
                    return;
                }
                if (Window.confirm(.AreYouSurePackageDelete())) {
                    deletePackage(.getValue(.getSelectedIndex()));
                }
            }
        });
        packagesToolbar.add();
        pf.addRow(packagesToolbar);
        pf.addRow();
        pf.endSection();
        pf.addRow();
        pf.endSection();
        initWidget(pf);
    }
    private void deletePackage(final String uuid) {
        .removeModule(uuid,
                new GenericCallback<java.lang.Void>() {
                    public void onSuccess(Void data) {
                        Window.alert(.PackageDeleted());
                        .clear();
                        loadPackages();
                    }
                });
    }
    private void restorePackage(String uuid) {
        .loadModule(uuid,
                new GenericCallback<Module>() {
                    public void onSuccess(Module cf) {
                        cf.setArchived(false);
                        .saveModule(cf,
                                new GenericCallback<ValidatedResponse>() {
                                    public void onSuccess(ValidatedResponse data) {
                                        Window.alert(.PackageRestored());
                                        .clear();
                                        loadPackages();
                                        .refresh();
                                        .fireEvent(new RefreshModuleListEvent());
                                    }
                                });
                    }
                });
    }
    private ListBox loadPackages() {
            public void onSuccess(Module[] configs) {
                for (Module config : configs) {
                    .addItem(config.getName(),
                            config.getUuid());
                }
                if (configs.length == 0) {
                    .addItem(.noArchivedPackages());
                }
                boolean enabled = (configs.length != 0);
                .setEnabled(enabled);
                .setEnabled(enabled);
                .setEnabled(enabled);
            }
        });
        return ;
    }
New to GrepCode? Check out our FAQ X