Java Code Examples for org.apache.wicket.Component

The following examples show how to use org.apache.wicket.Component. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: webanno   Source File: ProjectSelectionPanel.java    License: Apache License 2.0 7 votes vote down vote up
public ProjectSelectionPanel(String id, IModel<Project> aModel)
{
    super(id);

    overviewList = new OverviewListChoice<>("project");
    overviewList.setChoiceRenderer(new ChoiceRenderer<>("name"));
    overviewList.setModel(aModel);
    overviewList.setChoices(LambdaModel.of(this::listProjects));
    overviewList.add(new LambdaAjaxFormComponentUpdatingBehavior("change", this::onChange));
    add(overviewList);

    add(createLink = new LambdaAjaxLink("create", this::actionCreate));
    MetaDataRoleAuthorizationStrategy.authorize(createLink, Component.RENDER, StringUtils.join(
            new String[] { Role.ROLE_ADMIN.name(), Role.ROLE_PROJECT_CREATOR.name() }, ","));
    
    importProjectPanel = new ProjectImportPanel("importPanel", aModel);
    add(importProjectPanel);
    authorize(importProjectPanel, Component.RENDER,
            String.join(",", ROLE_ADMIN.name(), ROLE_PROJECT_CREATOR.name()));
}
 
Example 2
Source Project: onedev   Source File: AjaxActionTab.java    License: MIT License 6 votes vote down vote up
@Override
public Component render(String componentId) {
	return new ActionTabLink(componentId, this) {

		@Override
		protected WebMarkupContainer newLink(String id, ActionTab tab) {
			return new AjaxLink<Void>("link") {

				@Override
				protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
					super.updateAjaxAttributes(attributes);
					AjaxActionTab.this.updateAjaxAttributes(attributes);
				}

				@Override
				public void onClick(AjaxRequestTarget target) {
					selectTab(this);
				}
				
			};
		}
		
	};
}
 
Example 3
private Behavior getScrollBehaviour(){
	return new AttributeModifier("scroll", Model.of(this.getMarkupId())){
		private static final long serialVersionUID = 3523727356782417598L;

		@Override
		public void renderHead(Component component, IHeaderResponse response) {
			super.renderHead(component, response);

			response.render(OnDomReadyHeaderItem.forScript("InfiniteScroll.getFromContainer('"+getMarkupId()+"').setUrls('"+upBehavior.getCallbackUrl()+"', '"+downBehavior.getCallbackUrl()+"')"));
		}
		
		@Override
		protected String newValue(String currentValue, String replacementValue) {
			return "InfiniteScroll.handleScroll('"+InfiniteScrollListView.this.getMarkupId()+"')"; 
		}
	};
}
 
Example 4
Source Project: ontopia   Source File: URIValidator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onValidate(IValidatable<String> validatable) {
  final String value = validatable.getValue();
  if (value == null) return;
  try {
    new URILocator(value);
  } catch (Exception e) {
    String message = Application.get().getResourceSettings().getLocalizer().getString(resourceKey(), (Component)null, 
        new Model<Serializable>(new Serializable() {
          @SuppressWarnings("unused")
          public String getValue() {
            return value;
          }
        }));
    component.error(AbstractFieldInstancePanel.createErrorMessage(fieldInstanceModel, new Model<String>(message)));
  }
}
 
Example 5
Source Project: the-app   Source File: OrderItemListPanel.java    License: Apache License 2.0 6 votes vote down vote up
private Component orderItemList() {
    return new ListView<OrderItemInfo>("orderItems", new PropertyModel<List<OrderItemInfo>>(getDefaultModel(), "orderItems")) {

        private int orderItemCounter = 1;

        @Override
        protected void populateItem(ListItem<OrderItemInfo> orderItem) {
            orderItem.add(new Label("orderItemCounter", Model.of(orderItemCounter++)));
            orderItem.add(new Label("product", new PropertyModel<String>(orderItem.getModel(), "product.name")));
            orderItem.add(new Label("description", new PropertyModel<String>(orderItem.getModel(), "product.description")));
            orderItem.add(new Label("totalSum", new PriceModel(new PropertyModel<>(orderItem.getModel(), "totalSum"))));
        }

        @Override
        protected void onDetach() {
            orderItemCounter = 1;
            super.onDetach();
        }
    };
}
 
Example 6
Source Project: syncope   Source File: RelationshipTypesITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void read() {
    browsingToRelationshipType();

    Component result = findComponentByProp(KEY, DATATABLE_PATH, "inclusion");

    TESTER.assertComponent(
            result.getPageRelativePath() + ":cells:1:cell", Label.class);

    TESTER.executeAjaxEvent(result.getPageRelativePath(), Constants.ON_CLICK);
    TESTER.clickLink(
            "body:content:tabbedPanel:panel:outerObjectsRepeater:1:outer:container:content:"
            + "togglePanelContainer:container:actions:actions:actionRepeater:0:action:action");

    TESTER.assertComponent(
            "body:content:tabbedPanel:panel:outerObjectsRepeater:0:outer", BaseModal.class);
}
 
Example 7
Source Project: onedev   Source File: ImageRendererProvider.java    License: MIT License 6 votes vote down vote up
@Override
public PrioritizedComponentRenderer getRenderer(BlobRenderContext context) {
	if (context.getMode() == Mode.VIEW && context.getBlobIdent().isFile()) {
		if (context.getProject().getBlob(context.getBlobIdent(), true).getMediaType().getType().equalsIgnoreCase("image")) {
			return new PrioritizedComponentRenderer() {

				private static final long serialVersionUID = 1L;

				@Override
				public Component render(String componentId) {
					return new ImageViewPanel(componentId, context);
				}

				@Override
				public int getPriority() {
					return 0;
				}
				
			};
		}
	} 
	return null;
}
 
Example 8
Source Project: onedev   Source File: NoNameRendererProvider.java    License: MIT License 6 votes vote down vote up
@Override
public PrioritizedComponentRenderer getRenderer(BlobRenderContext context) {
	if (context.getMode() == Mode.ADD && context.getNewPath() == null) {
		return new PrioritizedComponentRenderer() {
			
			private static final long serialVersionUID = 1L;

			@Override
			public Component render(String componentId) {
				return new NoNameEditPanel(componentId, context);
			}
			
			@Override
			public int getPriority() {
				return 0;
			}
		};
	} else {
		return null;
	}		
}
 
Example 9
@Override
protected Iterator<? extends Component> renderIterator() {
	return IteratorUtils.transformedIterator(getList().iterator(), new Transformer<T, ListSetItem<?>>() {

		@Override
		public ListSetItem<?> transform(T el) {
			ListSetItem<?> component = elementToComponent.get(el);
			if(component==null) throw new IllegalStateException("could not find element '"+el+"' on computed map");
			return component;
		}
	});
}
 
Example 10
Source Project: the-app   Source File: ProductCatalogPage.java    License: Apache License 2.0 5 votes vote down vote up
private Component rowView() {
    return new ListView<List<ProductInfo>>("row", productListModel) {
        @Override
        protected void populateItem(ListItem<List<ProductInfo>> item) {
            item.add(productView(item.getModel()));
        }
    };
}
 
Example 11
Source Project: sakai   Source File: AjaxLazyLoadImage.java    License: Educational Community License v2.0 5 votes vote down vote up
/**
 * @param markupId
 *            The components markupid.
 * @return The component to show while the real component is being created.
 */
public Component getLoadingComponent(String markupId) {
	Label indicator = new Label(markupId, "<img src=\"" + RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null) + "\"/>");
	indicator.setEscapeModelStrings(false);
	indicator.add(new AttributeModifier("title", new Model("...")));
	return indicator;
}
 
Example 12
Source Project: onedev   Source File: PullRequestChangeActivity.java    License: MIT License 5 votes vote down vote up
@Override
public Component render(String panelId, DeleteCallback callback) {
	return new PullRequestChangePanel(panelId, new LoadableDetachableModel<PullRequestChange>() {

		@Override
		protected PullRequestChange load() {
			return getChange();
		}
		
	});
}
 
Example 13
Source Project: inception   Source File: QualifierEditor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new fragement for editing a qualifier.<br>
 * The editor has two slightly different behaviors, depending on the value of
 * {@code isNewQualifier}:
 * <ul>
 * <li>{@code !isNewQualifier}: Save button commits changes, cancel button discards unsaved
 * changes, delete button removes the qualifier from the statement.</li>
 * <li>{@code isNewQualifier}: Save button commits changes (creates a new qualifier in the
 * statement), cancel button removes the qualifier from the UI, delete button is not visible
 * .</li>
 * </ul>
 *
 * @param aId
 *            markup ID
 * @param aQualifier
 *            qualifier model
 * @param isNewQualifier
 *            whether the qualifier being edited is new, meaning it has no corresponding
 *            qualifier in the KB backend
 */
public EditMode(String aId, IModel<KBQualifier> aQualifier, boolean isNewQualifier)
{
    super(aId, "editMode", QualifierEditor.this, aQualifier);

    IModel<KBQualifier> compoundModel = CompoundPropertyModel.of(aQualifier);

    Form<KBQualifier> form = new Form<>("form", compoundModel);
    DropDownChoice<KBProperty> type = new BootstrapSelect<>("property");
    type.setChoiceRenderer(new ChoiceRenderer<>("uiLabel"));
    type.setChoices(kbService.listProperties(kbModel.getObject(), false));
    type.setRequired(true);
    type.setOutputMarkupId(true);
    form.add(type);
    initialFocusComponent = type;

    form.add(new TextField<>("language"));

    Component valueTextArea = new TextArea<String>("value");
    form.add(valueTextArea);

    form.add(new LambdaAjaxButton<>("create", QualifierEditor.this::actionSave));
    form.add(new LambdaAjaxLink("cancel", t -> {
        if (isNewQualifier) {
            QualifierEditor.this.actionCancelNewQualifier(t);
        } else {
            QualifierEditor.this.actionCancelExistingQualifier(t);
        }
    }));
    form.add(new LambdaAjaxLink("delete", QualifierEditor.this::actionDelete)
        .setVisibilityAllowed(!isNewQualifier));

    add(form);
}
 
Example 14
Source Project: onedev   Source File: ParamListEditPanel.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected List<Serializable> convertInputToValue() throws ConversionException {
	List<Serializable> value = new ArrayList<>();
	for (Component paramContainer: (WebMarkupContainer)get("params")) {
		Label label = (Label) paramContainer.get("name");
		ParamSupply param = new ParamSupply();
		param.setName((String) label.getDefaultModelObject());
		ParamSpec paramSpec = Preconditions.checkNotNull(getParamSpecs().get(param.getName()));
		param.setSecret(paramSpec instanceof SecretParam);
		Class<?> valuesProviderClass = (Class<?>) paramContainer.getDefaultModelObject();
		Component valuesEditor = paramContainer.get("values");
		if (valuesProviderClass == ScriptingValues.class) {
			ScriptingValues scriptingValues = new ScriptingValues();
			scriptingValues.setScriptName((String) ((PropertyEditor<Serializable>) valuesEditor).getConvertedInput()); 
			param.setValuesProvider(scriptingValues);
		} else if (valuesProviderClass == SpecifiedValues.class) {
			SpecifiedValues specifiedValues = new SpecifiedValues();
			for (Component valueContainer: (WebMarkupContainer)valuesEditor.get("values")) {
				Object propertyValue = ((PropertyEditor<Serializable>) valueContainer.get("value")).getConvertedInput();
				specifiedValues.getValues().add(paramSpec.convertToStrings(propertyValue));
			}
			param.setValuesProvider(specifiedValues);
		} else {
			param.setValuesProvider(new Ignore());
		}
		value.add(param);
	}
	return value;
}
 
Example 15
/**
 * @param parent Used for localization.
 * @see Component#getString(String)
 * @see Component#getLocale()
 */
public MyFullCalendarConfig(final Component parent)
{
  this.parent = parent;
  setIgnoreTimezone(true);
  setSlotMinutes(15);
  setFirstHour(8);
  setHeight("get_calendar_height()");
  getHeader().setLeft("prev,next today");
  getHeader().setCenter("title");
  getHeader().setRight("month,agendaWeek,agendaDay");

  getButtonText().setToday(getString("calendar.today"));
  getButtonText().setWeek(getString("calendar.week"));
  getButtonText().setMonth(getString("calendar.month"));
  getButtonText().setDay(getString("calendar.day"));
  setAllDayText(getString("calendar.allday"));
  I18nCore.setFullCalendarDateFormats(PFUserContext.getUser(), this);
  final DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(parent.getLocale());
  setDayNames(convert(dateFormatSymbols.getWeekdays()));
  setDayNamesShort(convert(dateFormatSymbols.getShortWeekdays()));
  setMonthNames(dateFormatSymbols.getMonths());
  setMonthNamesShort(dateFormatSymbols.getShortMonths());
  setWeekMode("variable");
  setEnableContextMenu(true);
  setEventRenderModel(Model.of("function(event, element) {" +
              "if (event.tooltipTitle) {" +
                  "element.popover({" +
                      "container: document.body, " +
                      "title: event.tooltipTitle, " +
                      "content: event.tooltipContent, " +
                      "html: true, " +
                      "placement: 'mouse'," +
                      "trigger: 'hover'" +
                  "});" +
              "}" +
          "}"));
}
 
Example 16
Source Project: ontopia   Source File: ModalGeoPickerPage.java    License: Apache License 2.0 5 votes vote down vote up
private void findFields() {
  MarkupContainer container = this;
  while (!(container instanceof FieldInstancesPanel))
    container = container.getParent();

  FieldInstancesPanel parent = (FieldInstancesPanel) container;
  ListView<FieldInstanceModel> listView = parent.getFieldList();
  Iterator<? extends ListItem<FieldInstanceModel>> itfim = listView.iterator();
  while (itfim.hasNext()) {
    ListItem<FieldInstanceModel> li = itfim.next();
    FieldInstance fi = li.getModelObject().getFieldInstance();
    FieldAssignment fa = fi.getFieldAssignment();
    FieldDefinition fd = fa.getFieldDefinition();
    if (fd.getFieldType() != FieldDefinition.FIELD_TYPE_OCCURRENCE)
      continue;
    OccurrenceField of = (OccurrenceField)fd;
    OccurrenceType ot = of.getOccurrenceType();
    if (ot == null)
      continue;
    Collection<LocatorIF> psis = ot.getTopicIF().getSubjectIdentifiers();

    if (psis.contains(PSI.ON_LATITUDE) ||
        psis.contains(PSI.ON_LONGITUDE)) {
      Iterator<? extends Component> it = li.iterator();
      while (it.hasNext()) {
        Object component = it.next();
        if (component instanceof FieldInstanceOccurrencePanel) {
          FieldInstanceOccurrencePanel fiop = (FieldInstanceOccurrencePanel) component;
          if (psis.contains(PSI.ON_LONGITUDE))
            lngpan = fiop;
          else
            latpan = fiop;
        }
      }
    }
  }
}
 
Example 17
Source Project: AppStash   Source File: TopSellerRecommendationPanel.java    License: Apache License 2.0 5 votes vote down vote up
public TopSellerRecommendationPanel(String id, Component feedback, IModel<ProductType> productTypeModel) {
    super(id);
    this.feedback = feedback;

    this.productTypeModel = productTypeModel;

    productInfoModel = productInfoModel();
    add(recommendationItemPanel());
    setOutputMarkupId(true);
    setOutputMarkupPlaceholderTag(true);
    add(new HighLightBehavior());
}
 
Example 18
Source Project: onedev   Source File: ConfirmLeaveListener.java    License: MIT License 5 votes vote down vote up
@Override
public CharSequence getPrecondition(Component component) {
	if (dirtyContainer != null)
		return String.format("return onedev.server.form.confirmLeave('%s');", dirtyContainer.getMarkupId(true));
	else
		return "return onedev.server.form.confirmLeave();";
}
 
Example 19
/**
 * @param markupId The components markupid.
 * @return The component to show while the real component is being created.
 */
public Component getLoadingComponent(String markupId) {
	Label indicator = new Label(markupId, "<img src=\"" + RequestCycle.get().urlFor(AbstractDefaultAjaxBehavior.INDICATOR, null) + "\"/>");
	indicator.setEscapeModelStrings(false);
	indicator.add(new AttributeModifier("title", new Model("...")));
	return indicator;
}
 
Example 20
Source Project: Orienteer   Source File: SimpleVisualizer.java    License: Apache License 2.0 5 votes vote down vote up
public <T> Component createComponent(String id, DisplayMode mode,
		IModel<T> model) {
	Class<? extends Component> componentClass = DisplayMode.EDIT.equals(mode)?editComponentClass:viewComponentClass;
	try
	{
		return componentClass.getConstructor(String.class, IModel.class).newInstance(id, model);
	} catch (Exception e)
	{
		throw new WicketRuntimeException("Can't create component", e);
	} 
}
 
Example 21
Source Project: openmeetings   Source File: RoomFilePanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Component getUpload() {
	return super.getUpload()
			.setVisible(true)
			.add(new AjaxEventBehavior(EVT_CLICK) {
				private static final long serialVersionUID = 1L;

				@Override
				protected void onEvent(AjaxRequestTarget target) {
					room.getSidebar().showUpload(target);
				}
			});
}
 
Example 22
Source Project: onedev   Source File: ProjectIssuesPage.java    License: MIT License 5 votes vote down vote up
@Override
public Component render(String componentId) {
	return new PageTabLink(componentId, this) {

		@Override
		protected Link<?> newLink(String linkId, Class<? extends Page> pageClass) {
			return new ViewStateAwarePageLink<Void>(linkId, pageClass, paramsOf(getProject()));
		}
		
	};
}
 
Example 23
Source Project: onedev   Source File: IssueTitleChangeData.java    License: MIT License 5 votes vote down vote up
@Override
public Component render(String componentId, IssueChange change) {
	return new PropertyChangePanel(componentId, 
			CollectionUtils.newHashMap("Title", oldTitle), 
			CollectionUtils.newHashMap("Title", newTitle), 
			true);
}
 
Example 24
Source Project: ontopia   Source File: LinkFunctionBoxPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected List<List<Component>> getFunctionBoxComponentList(String id) {
  List<Component> heading = Arrays.asList(new Component[] { getLabel(id) }); 
  List<Component> box = Arrays.asList(new Component[] {
      new Label(id, new ResourceModel("arrow.right")), getLink(id) });
  
  List<List<Component>> result = new ArrayList<List<Component>>(2);
  result.add(heading);
  result.add(box);
  return result;
}
 
Example 25
/**
 * @see org.apache.wicket.MarkupContainer#remove(org.apache.wicket.Component)
 */
@Override
public MarkupContainer remove(final Component component)
{
  if (repeater == null) {
    div.remove(component);
    return this;
  } else {
    repeater.remove(component);
    return this;
  }
}
 
Example 26
Source Project: onedev   Source File: PropertyContext.java    License: MIT License 5 votes vote down vote up
public static Component viewModel(String componentId, IModel<Serializable> beanModel, String propertyName) {
	PropertyContext<Serializable> editContext = of(HibernateProxyHelper.getClassWithoutInitializingProxy(beanModel.getObject()), propertyName);
	return editContext.renderForView(componentId, new LoadableDetachableModel<Serializable>() {

		@Override
		protected Serializable load() {
			return (Serializable) editContext.getDescriptor().getPropertyValue(beanModel.getObject());
		}
		
	});
}
 
Example 27
Source Project: sakai   Source File: MyStatusPanel.java    License: Educational Community License v2.0 5 votes vote down vote up
public void renderHead(Component component, IHeaderResponse response) {
 	response.render(StringHeaderItem.forString("<script type=\"text/javascript\">" +
	"$(document).ready( function(){" +
	"autoFill('#" + component.getMarkupId() + "', '" + defaultStatus + "');" +
	"countChars('#" + component.getMarkupId() + "');" +
	"});" +
"</script>"));
 }
 
Example 28
Source Project: Orienteer   Source File: MarkDownVisualizer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <V> Component createComponent(String id, DisplayMode mode, IModel<ODocument> documentModel,
                                     IModel<OProperty> propertyModel, IModel<V> valueModel) {
    switch (mode) {
        case VIEW:
            return new Label(id, new MarkDownModel((IModel<String>) valueModel)).setEscapeModelStrings(false);
        case EDIT:
            return new TextArea<String>(id, (IModel<String>) valueModel).setType(String.class);
        default:
            return null;
    }
}
 
Example 29
Source Project: AppStash   Source File: HomePage.java    License: Apache License 2.0 5 votes vote down vote up
private Component topSellerPanel() {
    boolean userAuthorized = isUserAuthorized();
    String ressourceKey = userAuthorized ? "your.favorite.products.topic" : "category.top.seller.topic";
    String recommenderType = userAuthorized ? "FAVORITE_PRODUCTS" : "STARTPAGE_TOPSELLER";

    return new RecommendationItemListPanel("topSellerProductsContainer", feedback,recommenderType, new ResourceModel(ressourceKey),
            new LoadableDetachableModel<List<ProductInfo>>() {
                @Override
                protected List<ProductInfo> load() {
                    return recommendationService.getTopsellerRecommendations(4);
                }
            }) {
    };
}
 
Example 30
Source Project: onedev   Source File: JobTrigger.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
private static List<ParamSpec> getParamSpecs() {
	Component component = ComponentContext.get().getComponent();
	JobAware jobAware = WicketUtils.findInnermost(component, JobAware.class);
	if (jobAware != null) {
		Job job = jobAware.getJob();
		if (job != null)
			return job.getParamSpecs();
	}
	return new ArrayList<>();
}