/**
   * Handle a drop from another layout
   *
   * @param event The drag and drop event
   */
  @Override
  protected void handleDropFromLayout(DragAndDropEvent event) {
    AbsoluteLayoutTargetDetails details = (AbsoluteLayoutTargetDetails) event.getTargetDetails();
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    Component component = transferable.getComponent();
    Component source = event.getTransferable().getSourceComponent();
    DDAbsoluteLayout layout = (DDAbsoluteLayout) details.getTarget();
    int leftPixelPosition = details.getRelativeLeft();
    int topPixelPosition = details.getRelativeTop();

    // Check that we are not dragging an outer layout into an
    // inner
    // layout
    Component parent = source.getParent();
    while (parent != null) {
      parent = parent.getParent();
    }

    // remove component from source using filter
    if (source instanceof ComponentContainer) {
      ComponentContainer sourceLayout = (ComponentContainer) source;
      sourceLayout.removeComponent(component);
    }

    // Add component to absolute layout
    layout.addComponent(
        component, "left:" + leftPixelPosition + "px;top:" + topPixelPosition + "px");
  }
Esempio n. 2
0
  @Override
  public Component getContent(Project project, ExtensionUtil util) {
    Layout layout = new CssLayout();
    layout.addStyleName(STYLE_TEAM_INFOBOX);
    layout.setSizeFull();
    PeopleExtension ext = project.getExtension(PeopleExtension.class);
    if (ext != null) {
      if (ext.getLeads().size() > 0) {
        Label projectLeadHeaderLabel = new Label("Project Lead");
        projectLeadHeaderLabel.addStyleName(STYLE_TEAMLABEL);
        layout.addComponent(projectLeadHeaderLabel);
        Component peopleComponent = PeopleComponent.getPeopleListComponentForMember(ext.getLeads());
        peopleComponent.addStyleName(InformationBox.STYLE);
        layout.addComponent(peopleComponent);
      }

      if (ext.getMembers().size() > 0) {
        Label projectTeamHeaderLabel = new Label("Project Team/Committers");
        projectTeamHeaderLabel.addStyleName(STYLE_TEAMLABEL);
        layout.addComponent(projectTeamHeaderLabel);

        Component peopleComponent =
            PeopleComponent.getPeopleListComponentForMember(ext.getMembers());
        peopleComponent.addStyleName(InformationBox.STYLE);
        layout.addComponent(peopleComponent);
      }

      String mailToTeamHtml = new MailToTeam(ext).composeMailToTeamLabel();
      createLabel(layout, mailToTeamHtml);
    }
    return layout;
  }
Esempio n. 3
0
  @Test
  public void buttonWithIdIsParsed() {
    Component button = ctx.getComponentByLocalId("firstButton");

    assertThat(ctx.getComponentByCaption("Native click me"), is(button));
    assertThat(button.getCaption(), is("Native click me"));
  }
Esempio n. 4
0
  private void bindEventHandler(
      Component componentRoot, Object controller, Method method, UiHandler eventListener) {
    String componentId = eventListener.value();
    Component component = Clara.findComponentById(componentRoot, componentId);
    if (component == null) {
      throw new BinderException("No component found for id: " + componentId + ".");
    }

    Class<?> eventType =
        (method.getParameterTypes().length > 0 ? method.getParameterTypes()[0] : null);
    if (eventType == null) {
      throw new BinderException("Couldn't figure out event type for method " + method + ".");
    }

    Method addListenerMethod = getAddListenerMethod(component.getClass(), eventType);
    if (addListenerMethod != null) {
      try {
        Object listener =
            createListenerProxy(
                addListenerMethod.getParameterTypes()[0], eventType, method, controller);
        addListenerMethod.invoke(component, listener);
        // TODO exception handling
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 5
0
  /**
   * Loads a design for the given root component.
   *
   * <p>This methods assumes that the component class (or a super class) has been marked with an
   * {@link DesignRoot} annotation and will either use the value from the annotation to locate the
   * design file, or will fall back to using a design with the same same as the annotated class file
   * (with an .html extension)
   *
   * <p>Any {@link Component} type fields in the root component which are not assigned (i.e. are
   * null) are mapped to corresponding components in the design. Matching is done based on field
   * name in the component class and id/local id/caption in the design file.
   *
   * <p>The type of the root component must match the root element in the design
   *
   * @param rootComponent The root component of the layout
   * @return The design context used in the load operation
   * @throws DesignException If the design could not be loaded
   */
  public static DesignContext read(Component rootComponent) throws DesignException {
    // Try to find an @DesignRoot annotation on the class or any parent
    // class
    Class<? extends Component> annotatedClass =
        findClassWithAnnotation(rootComponent.getClass(), DesignRoot.class);
    if (annotatedClass == null) {
      throw new IllegalArgumentException(
          "The class "
              + rootComponent.getClass().getName()
              + " or any of its superclasses do not have an @DesignRoot annotation");
    }

    DesignRoot designAnnotation = annotatedClass.getAnnotation(DesignRoot.class);
    String filename = designAnnotation.value();
    if (filename.equals("")) {
      // No value, assume the html file is named as the class
      filename = annotatedClass.getSimpleName() + ".html";
    }

    InputStream stream = annotatedClass.getResourceAsStream(filename);
    if (stream == null) {
      throw new DesignException(
          "Unable to find design file "
              + filename
              + " in "
              + annotatedClass.getPackage().getName());
    }

    Document doc = parse(stream);
    DesignContext context = designToComponentTree(doc, rootComponent, annotatedClass);

    return context;
  }
 /**
  * Returns visibility state of the filter field for the given column ID
  *
  * @param columnId Column/Property ID of the filter field to query
  * @return true if filter is visible, false if it's hidden
  */
 public boolean isFilterFieldVisible(Object columnId) {
   Component component = columnIdToFilterMap.get(columnId);
   if (component != null) {
     return component.isVisible();
   }
   return false;
 }
Esempio n. 7
0
  @Override
  public void addToContainer(Object c, Object constraints) {

    super.addToContainer(c, constraints);
    Component cc = (Component) c;
    cc.setWidth("100%");
  }
 /**
  * Toggles the visibility of the filter field defined for the give column ID.
  *
  * @param columnId Column/Property ID of the filter to toggle
  * @param visible true to set visible, false to set hidden
  */
 public void setFilterFieldVisible(Object columnId, boolean visible) {
   Component component = columnIdToFilterMap.get(columnId);
   if (component != null) {
     component.setVisible(visible);
     reRenderFilterFields = true;
     markAsDirty();
   }
 }
 public void addOption(Component btn) {
   CssLayout wrap = new CssLayout();
   btn.setWidth("100%");
   btn.setStyleName("action");
   wrap.addStyleName("action-wrap");
   wrap.addComponent(btn);
   ((ComponentContainer) this.getCompositionRoot()).addComponent(wrap);
 }
Esempio n. 10
0
 public void setNavigatorWidth(String width) {
   navigatorContainer.setWidth(width);
   Iterator<Component> i = navigatorContainer.iterator();
   while (i.hasNext()) {
     Component childComponent = i.next();
     childComponent.setWidth(width);
   }
 }
Esempio n. 11
0
  @Test
  public void buttonWithIdAndLocalIdIsParsed() {
    Component button = ctx.getComponentById("secondButton");

    assertThat(ctx.getComponentByCaption("Another button"), is(button));
    assertThat(ctx.getComponentByLocalId("localID"), is(button));
    assertThat(button.getCaption(), is("Another button"));
  }
Esempio n. 12
0
  public Login() {
    lookup();
    setSizeFull();

    Component loginForm = buildLoginForm();
    loginForm.setSizeUndefined();
    addComponent(loginForm);
    setComponentAlignment(loginForm, Alignment.MIDDLE_CENTER);
  }
Esempio n. 13
0
 @Override
 public Set<HasComponents> apply(Set<? extends Component> cs) {
   Set<HasComponents> result = Util.set();
   for (Component c : cs) {
     if (c.getParent() != null) {
       result.add(c.getParent());
     }
   }
   return result;
 }
Esempio n. 14
0
 private Component buildNotes() {
   TextArea notes = new TextArea("Notes");
   notes.setValue(
       "Remember to:\n· Zoom in and out in the Sales view\n· Filter the transactions and drag a set of them to the Reports tab\n· Create a new report\n· Change the schedule of the movie theater");
   notes.setSizeFull();
   notes.addStyleName(ValoTheme.TEXTAREA_BORDERLESS);
   Component panel = createContentWrapper(notes);
   panel.addStyleName("notes");
   return panel;
 }
Esempio n. 15
0
 /**
  * Method used to create cell placeholder. To be overridden if simple reflections with default
  * constructors are not enough.
  *
  * @param column Column index
  * @param cell Cell index
  * @return New instance of placeholder
  */
 protected Component createPlaceholder(int column, int cell) {
   Component placeHolder;
   try {
     placeHolder = placeholderClass.newInstance();
   } catch (Exception e) {
     throw new IllegalStateException("Failed to initialize placeholder class instance", e);
   }
   placeHolder.addStyleName("placeholder");
   placeHolder.addStyleName("placeholder-" + column + "-" + cell);
   return placeHolder;
 }
Esempio n. 16
0
 public void clearMenuSelection(HorizontalLayout menu) {
   for (Iterator<Component> it = menu.getComponentIterator(); it.hasNext(); ) {
     Component next = it.next();
     if (next instanceof NativeButton) {
       next.removeStyleName("selected");
     } else if (next instanceof DragAndDropWrapper) {
       // Wow, this is ugly (even uglier than the rest of the code)
       ((DragAndDropWrapper) next).iterator().next().removeStyleName("selected");
     }
   }
 }
Esempio n. 17
0
 /**
  * The contribution is unregistered.
  *
  * @param factory The component factory.
  */
 protected void unsetContribution(ComponentFactory factory) {
   ComponentInstance ci;
   Component c;
   synchronized (this) {
     ci = mapping.remove(factory);
     c = (Component) ci.getInstance();
     tabs.removeComponent(c);
   }
   c.detach();
   ci.dispose();
 }
Esempio n. 18
0
 @Override
 public Set<HasComponents> apply(Set<? extends Component> cs) {
   Set<HasComponents> result = Util.set();
   for (Component c : cs) {
     HasComponents parent = c.getParent();
     while (parent != null) {
       result.add(parent);
       parent = parent.getParent();
     }
   }
   return result;
 }
Esempio n. 19
0
 /**
  * Loads a design from the given file name using the given root component.
  *
  * <p>Any {@link Component} type fields in the root component which are not assigned (i.e. are
  * null) are mapped to corresponding components in the design. Matching is done based on field
  * name in the component class and id/local id/caption in the design file.
  *
  * <p>The type of the root component must match the root element in the design.
  *
  * @param filename The file name to load. Loaded from the same package as the root component
  * @param rootComponent The root component of the layout
  * @return The design context used in the load operation
  * @throws DesignException If the design could not be loaded
  */
 public static DesignContext read(String filename, Component rootComponent)
     throws DesignException {
   InputStream stream = rootComponent.getClass().getResourceAsStream(filename);
   if (stream == null) {
     throw new DesignException(
         "File "
             + filename
             + " was not found in the package "
             + rootComponent.getClass().getPackage().getName());
   }
   return read(stream, rootComponent);
 }
 /**
  * Resets all filters.
  *
  * <p>Note: Recreates the filter fields also!
  */
 public void resetFilters() {
   if (initDone) {
     disableContentRefreshing();
     for (Component c : columnIdToFilterMap.values()) {
       c.setParent(null);
     }
     collapsedColumnIds.clear();
     columnIdToFilterMap.clear();
     generator.clearFilterData();
     generator.initializeFilterFields();
     reRenderFilterFields = true;
     enableContentRefreshing(true);
   }
 }
Esempio n. 21
0
  private void setLayout(Layout newLayout) {
    if (layout == null) {
      layoutParent.addComponent(newLayout, 0);
    } else {
      layoutParent.replaceComponent(layout, newLayout);
    }
    layout = newLayout;

    for (Component c : components) {
      if (c.getParent() != layout) {
        layout.addComponent(c);
      }
    }
  }
  @Override
  protected void handleHTML5Drop(DragAndDropEvent event) {
    TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails();
    HorizontalDropLocation location = details.getDropLocation();
    DDTabSheet tabSheet = (DDTabSheet) details.getTarget();
    int idx = details.getOverIndex();

    Component c = resolveComponentFromHTML5Drop(event);
    c.setCaption(resolveCaptionFromHTML5Drop(event));

    if (location == HorizontalDropLocation.LEFT) {
      tabSheet.addTab(c, idx);
    } else if (location == HorizontalDropLocation.RIGHT) {
      tabSheet.addTab(c, idx + 1);
    }
  }
 @Override
 public Iterator<Component> iterator() {
   Set<Component> children = new HashSet<Component>();
   if (visibleComponents != null) {
     children.addAll(visibleComponents);
   }
   if (initDone) {
     for (Object key : columnIdToFilterMap.keySet()) {
       Component filter = columnIdToFilterMap.get(key);
       if (equals(filter.getParent())) {
         children.add(filter);
       }
     }
   }
   return children.iterator();
 }
Esempio n. 24
0
  @Override
  public void replaceComponent(Component oldComponent, Component newComponent) {

    // Ignore if component is replaced with itself
    if (oldComponent == newComponent) {
      return;
    }

    // Remove new component from children to allow position calculations
    if (newComponent.getParent() == this) {
      removeComponent(newComponent);
    }

    // Resolve column
    ColumnLayoutState.ColumnState column = findColumn(oldComponent);
    if (column == null) {
      throw new IllegalArgumentException("Old component not found");
    }

    // Resolve position inside column
    int index = column.children.indexOf(oldComponent);

    // Remove old and add new to same position in column
    removeComponent(oldComponent);
    addComponent(newComponent, column, index);
  }
Esempio n. 25
0
 /**
  * Constructs a component hierarchy from the design specified as an html tree.
  *
  * <p>If a component root is given, the component instances created during reading the design are
  * assigned to its member fields based on their id, local id, and caption
  *
  * @param doc the html tree
  * @param componentRoot optional component root instance. The type must match the type of the root
  *     element in the design. Any member fields whose type is assignable from {@link Component}
  *     are bound to fields in the design based on id/local id/caption
  */
 private static DesignContext designToComponentTree(Document doc, Component componentRoot) {
   if (componentRoot == null) {
     return designToComponentTree(doc, null, null);
   } else {
     return designToComponentTree(doc, componentRoot, componentRoot.getClass());
   }
 }
Esempio n. 26
0
 @Override
 protected void setDefaulButtonIcon(Component btn, Boolean selected) {
   ButtonTabImpl btnTabImpl = (ButtonTabImpl) btn;
   String tabId = btnTabImpl.getTabId();
   Resource resource = SettingAssetsManager.getAsset(tabId);
   btn.setIcon(resource);
 }
Esempio n. 27
0
  private void toggleMaximized(final Component panel, final boolean maximized) {
    for (Iterator<Component> it = root.iterator(); it.hasNext(); ) {
      it.next().setVisible(!maximized);
    }
    dashboardPanels.setVisible(true);

    for (Iterator<Component> it = dashboardPanels.iterator(); it.hasNext(); ) {
      Component c = it.next();
      c.setVisible(!maximized);
    }

    if (maximized) {
      panel.setVisible(true);
      panel.addStyleName("max");
    } else {
      panel.removeStyleName("max");
    }
  }
Esempio n. 28
0
 private void showComponent(final Component component, final String name) {
   final VerticalLayout layout = new VerticalLayout();
   layout.setSizeUndefined();
   layout.setMargin(true);
   final Window window = new Window(name, layout);
   window.setSizeUndefined();
   component.setSizeUndefined();
   window.addComponent(component);
   getWindow().addWindow(window);
 }
 @Override
 public void setVisibleColumns(Object... visibleColumns) {
   reRenderFilterFields = true;
   if (visibleColumns != null && columnIdToFilterMap != null) {
     /* First clear all parent references */
     for (Object key : columnIdToFilterMap.keySet()) {
       columnIdToFilterMap.get(key).setParent(null);
     }
     /* Set this as parent to visible columns */
     for (Object key : visibleColumns) {
       Component filter = columnIdToFilterMap.get(key);
       if (filter != null) {
         filter.setParent(this);
       }
     }
   }
   super.setVisibleColumns(visibleColumns);
   resetFilters();
 }
Esempio n. 30
0
  private Component createContentWrapper(final Component content) {
    final CssLayout slot = new CssLayout();
    slot.setWidth("100%");
    slot.addStyleName("dashboard-panel-slot");
    slot.addStyleName("max");

    CssLayout card = new CssLayout();
    card.setWidth("100%");
    card.addStyleName(ValoTheme.LAYOUT_CARD);

    Label caption = new Label(content.getCaption());
    caption.addStyleName(ValoTheme.LABEL_H4);
    caption.addStyleName(ValoTheme.LABEL_COLORED);
    caption.addStyleName(ValoTheme.LABEL_NO_MARGIN);
    content.setCaption(null);

    card.addComponents(content);
    slot.addComponent(card);
    return slot;
  }