public PatternPanel(NType p) {
      super();

      addStyleName("detailEditPanelPattern");
      addComponent(new BigLabel(p.getName()));

      VerticalLayout properties = new VerticalLayout();
      properties.setMargin(false, false, false, true);
      addComponent(properties);

      for (final PropertyValue pv : detail.getValues()) {
        //                if (!p.containsKey(pv.getProperty()))
        //                    continue;

        Property r = app.getPropertyByID(pv.getProperty());
        if (r != null) {
          properties.addComponent(
              new ValueEditPanel(r, pv) {

                @Override
                public void removeThis() {
                  removeProperty(pv);
                }
              });
        } else {
          properties.addComponent(new MissingPropertyPanel(pv));
        }
      }

      Button removeButton = new Button("Remove");
      removeButton.addStyleName("SmallLabel");
      addComponent(removeButton);
      setComponentAlignment(removeButton, Alignment.BOTTOM_RIGHT);
    }
  protected void refreshPatternBar() {
    patternBar.removeAllComponents();

    final Collection<NType> allPatterns = app.getTypes(null);

    patternBar.setColumns(patternColumns);
    patternBar.setRows((int) Math.ceil(allPatterns.size() / patternColumns));

    // 1. add all non-present patterns to 'patternMenu'
    for (final NType pattern : allPatterns) {
      String pName = pattern.getName();

      final PushButton pButton =
          new PushButton(pName, detail.getTypes().contains(pattern)) {

            @Override
            public void setPushed(boolean b) {
              super.setPushed(b);
              if (isPushed()) {
                addNewPattern(pattern.getId());
              } else {
                removePattern(pattern.getId());
              }
            }
          };
      pButton.setWidth("100%");
      pButton.setHeight("100%");
      // pButton.setIcon(new ThemeResource(pattern.getIconURL()));

      patternBar.addComponent(pButton);
    }
    //        patternMenu.addSeparator();
    //        patternMenu.addItem("New Pattern...", new Command() {
    //
    //            @Override
    //            public void menuSelected(MenuItem selectedItem) {
    //                createNewPattern();
    //            }
    //        });

    //        //2. add all present patterns to 'patternBar' as menus
    //        for (final String p : presentPatterns) {
    //            Pattern pattern = schema.getPatterns().get(p);
    //            int total = getPropertiesTotal(pattern);
    //            MenuItem i = patternBar.addItem(pattern.getName() + " (" + (total -
    // getPropertiesNotPresent(pattern)) + "/" + total + ")", null, null);
    //
    //            for (String property : pattern.keySet()) {
    //                if (supportsAnotherProperty(property)) {
    //                    final Property pr = schema.getProperty(property);
    //                    i.addItem(pr.getName(), new Command() {
    //
    //                        @Override
    //                        public void menuSelected(MenuItem selectedItem) {
    //                            addProperty(pr.getID());
    //                        }
    //                    });
    //                }
    //            }
    //
    //            i.addSeparator();
    //
    //            //move left (more important)
    //            //move right (less important)
    //
    //            i.addItem("Remove", new Command() {
    //
    //                @Override
    //                public void menuSelected(MenuItem selectedItem) {
    //                    removePattern(p);
    //                }
    //            });
    //        }
  }