Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.
  */
 
 package org.drools.guvnor.client.widgets;
 
 
 import java.util.Date;

This displays the metadata for a versionable artifact. It also captures edits, but it does not load or save anything itself.
 
 public class MetaDataWidget extends Composite {
     private ConstantsCore constants = GWT.createConstantsCore.class );
     private static ImagesCore images = GWT.createImagesCore.class );
 
     private final Artifact artifact;
     private final boolean readOnly;
     private final String uuid;
     private VerticalPanel layout = new VerticalPanel();
     private FormStyleLayout currentSection;
     private String currentSectionName;
     private final ClientFactory clientFactory;
     private final EventBus eventBus;
 
     public MetaDataWidget(ClientFactory clientFactory,
                           EventBus eventBus,
                           final Artifact artifact,
                           boolean readOnly,
                           final String uuid) {
         super();
 
         this. = clientFactory;
         this. = eventBus;
         this. = uuid;
         this. = artifact;
         this. = readOnly;
 
         .setWidth"100%" );
         initWidget );
         render();
     }
 
     private void render() {
         .clear();
         //layout.add( new SmallLabel( constants.Title() + ": [<b>" + data.name + "</b>]" ) );
         startSection.Metadata() );
         addHeader.assetVersion(),
                 .getName(),
                 null );
 
         loadData();
     }
 
     private void addHeader(ImageResource img,
                            String name,
                            Image edit) {
 
         HorizontalPanel hp = new HorizontalPanel();
         hp.addnew SmallLabel"<b>" + name + "</b>" ) );
         if ( edit != null ) hp.addedit );
                 hp );
    }
    private void loadData() {
        if (  instanceof Asset ) {
            addAttribute.CategoriesMetaData(),
                    categories() );
        }
                readOnlyDate.getLastModified() ) );
                readOnlyText.getLastContributor() ) );
                readOnlyText.getCheckinComment() ) );
        if ( ! ) {
            addAttribute.CreatedOnMetaData(),
                    readOnlyDate.getDateCreated() ) );
        }
        if (  instanceof Asset ) {
            addAttribute.CreatedByMetaData(),
                    readOnlyText( ((Asset).getMetaData().getCreator() ) );
            addAttribute.PackageMetaData(),
                    packageEditor( ((Asset).getMetaData().getModuleName() ) );
            addAttribute.IsDisabledMetaData(),
                    editableBooleannew FieldBooleanBinding() {
                        public boolean getValue() {
                            return ((Asset).getMetaData().isDisabled();
                        }
                        public void setValue(boolean val) {
                            ((Asset).getMetaData().setDisabledval );
                        }
                    },
                            .DisableTip() ) );
        }
        
                readOnlyText(.getFormat()));
        addAttribute"UUID:",
                readOnlyText ) );
        endSectionfalse );
        if (  instanceof Asset ) {
            final MetaData data = ((Asset).getMetaData();
            startSection.OtherMetaData() );
            addAttribute.SubjectMetaData(),
                    editableTextnew FieldBinding() {
                        public String getValue() {
                            return data.subject;
                        }
                        public void setValue(String val) {
                            data.subject = val;
                        }
                    },
                            .AShortDescriptionOfTheSubjectMatter()));
            addAttribute(.TypeMetaData(),
                    editableText(new FieldBinding() {
                        public String getValue() {
                            return data.type;
                        }
                        public void setValue(String val) {
                            data.type = val;
                        }
                    },
                            .TypeTip()));
                    editableText(new FieldBinding() {
                        public String getValue() {
                            return data.externalRelation;
                        }
                        public void setValue(String val) {
                            data.externalRelation = val;
                        }
                    },
                            .ExternalLinkTip()));
            addAttribute(.SourceMetaData(),
                    editableText(new FieldBinding() {
                        public String getValue() {
                            return data.externalSource;
                        }
                        public void setValue(String val) {
                            data.externalSource = val;
                        }
                    },
                            .SourceMetaDataTip()));
            endSection(true);
        }
        Image image = ..Feed();
        image.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent arg0) {
                Window.open(getVersionFeed(), "_blank"null);
            }
        });
        addAttribute(.VersionFeed(), image);
                getVersionNumberLabel());
        if (!) {
            addRow(new VersionBrowser(,
                    ,
                    this.,
                    !( instanceof Asset)));
        }
        endSection(true);
    }
    private void addRow(Widget widget) {
        this..addRow(widget);
    }
    private void addAttribute(String string,
            Widget widget) {
        this..addAttribute(string,
                widget);
    }
    private void endSection(boolean collapsed) {
        DecoratedDisclosurePanel advancedDisclosure = new DecoratedDisclosurePanel();
        advancedDisclosure.setWidth("100%");
        advancedDisclosure.setOpen(!collapsed);
        advancedDisclosure.setContent(this.);
        .add(advancedDisclosure);
    }
    private void startSection(String name) {
         = new FormStyleLayout();
         = name;
    }
    private Widget packageEditor(final String packageName) {
            return readOnlyText(packageName);
        } else {
            HorizontalPanel horiz = new HorizontalPanel();
            horiz.setStyleName("metadata-Widget"); //NON-NLS
            horiz.add(readOnlyText(packageName));
            Image editPackage = ..Edit();
            editPackage.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent w) {
                    showEditPackage(packageName,
                            w);
                }
            });
            horiz.add(editPackage);
            return horiz;
        }
    }
    private void showEditPackage(final String pkg,
            ClickEvent source) {
        Image image = new Image(.packageLarge());
        image.setAltText(..Package());
        final FormStylePopup pop = new FormStylePopup(image,
                .MoveThisItemToAnotherPackage());
                new Label(pkg));
        final RulePackageSelector sel = new RulePackageSelector();
        pop.addAttribute(.NewPackage(),
                sel);
        Button ok = new Button(.ChangePackage());
        pop.addAttribute("",
                ok);
        ok.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent w) {
                if (sel.getSelectedPackage().equals(pkg)) {
                    Window.alert(.YouNeedToPickADifferentPackageToMoveThisTo());
                    return;
                }
                AssetServiceAsync assetService = GWT.create(AssetService.class);
                assetService.changeAssetPackage(,
                        sel.getSelectedPackage(),
                        .MovedFromPackage(pkg),
                        new GenericCallback<java.lang.Void>() {
                            public void onSuccess(Void v) {
                                .fireEvent(new RefreshAssetEditorEvent(sel.getSelectedPackage(), ));
                                pop.hide();
                            }
                        });
            }
        });
        pop.show();
    }
    private void close() {
    }
    private Widget getVersionNumberLabel() {
        if (.getVersionNumber() == 0) {
            return new SmallLabel(.NotCheckedInYet());
        } else {
            return readOnlyText(Long.toString(.getVersionNumber()));
        }
    }
    private Widget readOnlyDate(Date lastModifiedDate) {
        if (lastModifiedDate == null) {
            return null;
        } else {
            return new SmallLabel(DateTimeFormat.getFormat(..).format(lastModifiedDate));
        }
    }
    private Label readOnlyText(String text) {
        SmallLabel lbl = new SmallLabel(text);
        lbl.setWidth("100%");
        return lbl;
    }
    private Widget categories() {
         = new AssetCategoryEditor(((Assetthis.).getMetaData(),
                this.);
        return ;
    }

    
This binds a field, and returns a check box editor for it.

Parameters:
bind Interface to bind to.
toolTip tool tip.
Returns:
    private Widget editableBoolean(final FieldBooleanBinding bind,
            String toolTip) {
        if (!) {
            final CheckBox box = new CheckBox();
            box.setTitle(toolTip);
            box.setValue(bind.getValue());
            ClickHandler listener = new ClickHandler() {
                public void onClick(ClickEvent w) {
                    boolean b = box.getValue();
                    bind.setValue(b);
                }
            };
            box.addClickHandler(listener);
            return box;
        } else {
            final CheckBox box = new CheckBox();
            box.setValue(bind.getValue());
            box.setEnabled(false);
            return box;
        }
    }

    
This binds a field, and returns a TextBox editor for it.

Parameters:
bind Interface to bind to.
toolTip tool tip.
Returns:
    private Widget editableText(final FieldBinding bind,
                                String toolTip) {
        if ( ! ) {
            final TextBox tbox = new TextBox();
            tbox.setTitletoolTip );
            tbox.setTextbind.getValue() );
            tbox.setVisibleLength( 10 );
            ChangeHandler listener = new ChangeHandler() {
                public void onChange(ChangeEvent event) {
                    String txt = tbox.getText();
                    bind.setValuetxt );
                }
            };
            tbox.addChangeHandlerlistener );
            return tbox;
        } else {
            return new Labelbind.getValue() );
        }
    }

    
used to bind fields in the meta data DTO to the form
    static interface FieldBinding {
        void setValue(String val);
        String getValue();
    }

    
used to bind fields in the meta data DTO to the form
    static interface FieldBooleanBinding {
        void setValue(boolean val);
        boolean getValue();
    }

    
Return the data if it is to be saved.
    public Artifact getData() {
        return ;
    }
    public void refresh() {
        render();
    }
    static String getVersionFeed(Artifact artifact) {
        if ( artifact instanceof Module ) {
            return getRESTBaseURL() + "packages/" + artifact.getName() + "/versions";
        } else {
            return getRESTBaseURL() + "packages/" + ((Assetartifact).getMetaData().getModuleName()
                    + "/assets/" + artifact.getName() + "/versions";
        }
    }
    static String getRESTBaseURL() {
        String url = GWT.getModuleBaseURL();
        return url.replaceFirst"org.drools.guvnor.Guvnor",
                "rest" );
    }
New to GrepCode? Check out our FAQ X