Java Code Examples for org.apache.wicket.model.IModel#getObject()

The following examples show how to use org.apache.wicket.model.IModel#getObject() . 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 File: AjaxPalettePanel.java    From syncope with Apache License 2.0 6 votes vote down vote up
public AjaxPalettePanel(
        final String id, final IModel<List<T>> model, final IModel<List<T>> choices, final Builder<T> builder) {
    super(id, builder.name == null ? id : builder.name, model);

    choicesModel = new PaletteLoadableDetachableModel(builder) {

        private static final long serialVersionUID = -108100712154481840L;

        @Override
        protected List<T> getChoices() {
            return builder.filtered
                    ? getFilteredList(choices.getObject(), queryFilter.getObject().replaceAll("\\*", "\\.\\*"))
                    : choices.getObject();
        }
    };
    initialize(model, builder);
}
 
Example 2
Source File: SaveOArtifactCommand.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(final Optional<AjaxRequestTarget> targetOptional) {
    final IModel<Boolean> failed = Model.of(Boolean.FALSE);
    table.visitChildren(MetaContextItem.class, new IVisitor<MetaContextItem<OArtifact, ?>,Void >() {
        @Override
        public void component(MetaContextItem<OArtifact, ?> rowItem, IVisit<Void> visit) {
            OArtifact module = rowItem.getModelObject();
            if (isUserArtifactValid(targetOptional, module)) {
                OArtifact moduleForUpdate = new OArtifact(module.getPreviousArtifactRefence());
                moduleForUpdate.setLoad(module.isLoad())
                        .setTrusted(module.isTrusted());
                OrienteerClassLoaderUtil.updateOArtifactInMetadata(moduleForUpdate, module);
            } else failed.setObject(Boolean.TRUE);
            visit.dontGoDeeper();
        }
    });

    if (!failed.getObject()) {
        showFeedback(targetOptional, false);
        super.onClick(targetOptional);
    }
}
 
Example 3
Source File: BootstrapPaginatorTest.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testLastButton(){
	WicketTester tester = createTester();
	final Boxed<Integer> pageBox = new Boxed<Integer>();
	
	BootstrapPaginator paginator = new BootstrapPaginator("paginator", Model.of(100)) {
		private static final long serialVersionUID = -4486050808642574868L;

		@Override
		public void onPageChange(AjaxRequestTarget target, IModel<Integer> page) {
			pageBox.value=page.getObject();
		}
	};
	paginator.setTotalResults(Model.of(100));
	paginator.setNumberResultsPerPage(10);
	tester.startComponentInPage(paginator);
	
	tester.clickLink("paginator:last:link");
	assertEquals(9, (int) pageBox.value);
	tester.assertDisabled("paginator:last:link");
	tester.assertDisabled("paginator:next:link");
	tester.assertEnabled("paginator:previous:link");
	tester.assertEnabled("paginator:first:link");
	
}
 
Example 4
Source File: TypeColumn.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public void populateItem(Item<ICellPopulator<Entity>> item, String componentId, IModel<Entity> rowModel) {
    String type = rowModel.getObject().getClass().getSimpleName();
    Entity entity = rowModel.getObject(); 
    if (entity instanceof Report) {
        type = ((Report) entity).getType() + " " + new StringResourceModel(type, null).getString();
    } else if (entity instanceof DataSource) {
    	type = ((DataSource) entity).getVendor();
    } else if ((entity instanceof Folder) || (entity instanceof Chart)) {
    	type = new StringResourceModel(type, null).getString();
    }
    item.add(new Label(componentId, new Model<String>(type)));
}
 
Example 5
Source File: TextDiffPanel.java    From onedev with MIT License 5 votes vote down vote up
public TextDiffPanel(String id, IModel<Project> projectModel, IModel<PullRequest> requestModel, 
		BlobChange change, DiffViewMode diffMode, @Nullable IModel<Boolean> blameModel, 
		@Nullable BlobCommentSupport commentSupport) {
	super(id);
	
	this.projectModel = projectModel;
	this.requestModel = requestModel;
	this.change = change;
	this.diffMode = diffMode;
	this.commentSupport = commentSupport;
	this.blameModel = blameModel;
	
	if (blameModel != null && blameModel.getObject()) {
		blameInfo = getBlameInfo();
	}
	
	initialMarks = new ArrayList<>();
	if (commentSupport != null) {
		Mark mark = commentSupport.getMark();
		if (mark != null) {
			initialMarks.add(mark);
		}
		for (CodeComment comment: commentSupport.getComments()) {
			mark = comment.getMark();
			initialMarks.add(mark);
		}
	}
}
 
Example 6
Source File: LinksAsEmbeddedVisualizer.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public <V> Component createComponent(String id, DisplayMode mode, IModel<ODocument> documentModel,
		IModel<OProperty> propertyModel, IModel<V> valueModel) {
	OProperty property = propertyModel.getObject();
	OType oType = property.getType();
	if(DisplayMode.VIEW.equals(mode))
	{
		switch(oType)
		{
			case LINK:
				return new EmbeddedDocumentPanel(id, (IModel<ODocument>)valueModel, new PropertyModel<OClass>(propertyModel, "linkedClass"), mode.asModel());
			case LINKLIST:
			case LINKSET:
				return new EmbeddedCollectionViewPanel<>(id, documentModel, propertyModel);
               case LINKMAP:
               	return new EmbeddedMapViewPanel<V>(id, documentModel, propertyModel);
               default:
               	return null;
		}
	}
	else if(DisplayMode.EDIT.equals(mode))
	{
		switch(oType)
		{
			case LINK:
				return new EmbeddedDocumentPanel(id, (IModel<ODocument>)valueModel, new PropertyModel<OClass>(propertyModel, "linkedClass"), mode.asModel());
			case LINKLIST:
				return new EmbeddedCollectionEditPanel<Object, List<Object>>(id, documentModel, propertyModel, ArrayList.class);
			case LINKSET:
				return new EmbeddedCollectionEditPanel<Object, Set<Object>>(id, documentModel, propertyModel, HashSet.class);
               case LINKMAP:
               	return new EmbeddedMapEditPanel<V>(id, documentModel, propertyModel);
               default:
               	return null;
		}
	}
	else return null;
}
 
Example 7
Source File: NumberFeatureSupport.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public FeatureEditor createEditor(String aId, MarkupContainer aOwner,
        AnnotationActionHandler aHandler, final IModel<AnnotatorState> aStateModel,
        final IModel<FeatureState> aFeatureStateModel)
{
    AnnotationFeature feature = aFeatureStateModel.getObject().feature;
    
    if (!accepts(feature)) {
        throw unsupportedFeatureTypeException(feature);
    }

    NumberFeatureTraits traits = readTraits(feature);

    switch (feature.getType()) {
    case CAS.TYPE_NAME_INTEGER: {
        if (traits.getEditorType().equals(NumberFeatureTraits.EDITOR_TYPE.RADIO_BUTTONS)) {
            int min = (int) traits.getMinimum();
            int max = (int) traits.getMaximum();
            List<Integer> range = IntStream.range(min, max + 1).boxed()
                    .collect(Collectors.toList());
            return new RatingFeatureEditor(aId, aOwner, aFeatureStateModel, range);
        }
        else {
            return new NumberFeatureEditor(aId, aOwner, aFeatureStateModel, traits);
        }
    }
    case CAS.TYPE_NAME_FLOAT: {
        return new NumberFeatureEditor(aId, aOwner, aFeatureStateModel, traits);
    }
    default:
        throw unsupportedFeatureTypeException(feature);
    }
}
 
Example 8
Source File: RecipientsPanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public void populateItem(Item<ICellPopulator<Recipient>> item, String componentId, IModel<Recipient> rowModel) {
    final Recipient recipient = rowModel.getObject();
    final String name = recipient.getName();

    Component component = new AbstractImageLabelPanel(componentId) {

        @Override
        public String getDisplayString() {
            return name;
        }

        @Override
        public String getImageName() {
            if (recipient.getType() == Recipient.EMAIL_TYPE) {
                return "images/email.png";
            } else if (recipient.getType() == Recipient.USER_TYPE) {
                return "images/user.png";
            } else if (recipient.getType() == Recipient.GROUP_TYPE) {
                return "images/group.png";
            }
            // TODO
            return null; // return "blank.png"
        }

    };

    item.add(component);
}
 
Example 9
Source File: LogDialog.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public void show(IPartialPageRequestHandler aTarget)
{
    IModel<List<LogMessageGroup>> model = getModel();
    
    if (model == null || model.getObject() == null) {
        LogMessageGroup group = new LogMessageGroup("No recommendations");
        group.setMessages(asList(LogMessage.info("", "No recommender run has completed yet.")));
        model = new ListModel<>(asList(group));
    }
    
    setContent(new LogDialogContent(getContentId(), this, model));
    
    super.show(aTarget);
}
 
Example 10
Source File: ODBScriptResultRenderer.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public Component render(String id, IModel<?> dataModel) {
	if(dataModel == null) return null;
	else if(dataModel instanceof OQueryModel) {
		OQueryModel<ODocument> queryModel = (OQueryModel<ODocument>) dataModel;
		OClass oClass = queryModel.probeOClass(20);
		if(oClass!=null) {
			return new OQueryModelResultsPanel(id, queryModel);
		}
	} else {
		// Trying to find ODocument related stuff
		Object value = dataModel.getObject();
		if(value == null) return null;
		Class<?> valueClass = value.getClass();
		if(valueClass.isArray()) {
			Class<?> arrayClass = valueClass.getComponentType();
			if(!arrayClass.isPrimitive()) {
				value = Arrays.asList((Object[])value);
				if(arrayClass != null && OIdentifiable.class.isAssignableFrom(arrayClass)) {
					return new MultiLineLabel(id, serializeODocuments((Collection<OIdentifiable>)value));
				}
			}
		}
		if(value instanceof Collection<?>) {
			Collection<?> collection = (Collection<?>)value;
			if(!collection.isEmpty() && collection.iterator().next() instanceof OIdentifiable) {
				//TODO: add more suitable component for visualization of result set
				return new MultiLineLabel(id, serializeODocuments((Collection<OIdentifiable>)collection));
			}
		}
	}
	return null;
}
 
Example 11
Source File: KeyBindingsConfigurationPanel.java    From webanno with Apache License 2.0 5 votes vote down vote up
public KeyBindingsConfigurationPanel(String aId, IModel<AnnotationFeature> aModel,
        IModel<List<KeyBinding>> aKeyBindings)
{
    super(aId, aModel);
    
    keyBindings = aKeyBindings;
    
    Form<KeyBinding> keyBindingForm = new Form<>("keyBindingForm",
            CompoundPropertyModel.of(new KeyBinding()));
    add(keyBindingForm);

    keyBindingsContainer = new WebMarkupContainer("keyBindingsContainer");
    keyBindingsContainer.setOutputMarkupPlaceholderTag(true);
    keyBindingForm.add(keyBindingsContainer);

    // We cannot make the key-combo field a required one here because then we'd get a message
    // about keyCombo not being set when saving the entire feature details form!
    keyBindingsContainer.add(new TextField<String>("keyCombo")
            .add(new KeyComboValidator()));
    keyBindingsContainer.add(new LambdaAjaxSubmitLink<>("addKeyBinding", this::addKeyBinding));
    
    AnnotationFeature feature = aModel.getObject();
    FeatureSupport<?> fs = featureSupportRegistry.getFeatureSupport(feature);
    featureState = Model.of(new FeatureState(VID.NONE_ID, feature, null));
    if (feature.getTagset() != null) {
        featureState.getObject().tagset = schemaService.listTags(feature.getTagset());
    }
    // We are adding only the focus component here because we do not want to display the label
    // which usually goes along with the feature editor. This assumes that there is a sensible
    // focus component... might not be the case for some multi-component editors.
    editor = fs.createEditor("value", this, null, null, featureState);
    editor.addFeatureUpdateBehavior();
    editor.getLabelComponent().setVisible(false);
    keyBindingsContainer.add(editor);
    
    keyBindingsContainer.add(createKeyBindingsList("keyBindings", keyBindings));
}
 
Example 12
Source File: EmbeddedMapViewPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public EmbeddedMapViewPanel(String id, final IModel<ODocument> documentModel, final IModel<OProperty> propertyModel) {
	super(id, new DynamicPropertyValueModel<Map<String, V>>(documentModel, propertyModel));
	OProperty property = propertyModel.getObject();
	final DefaultVisualizer visualizer = DefaultVisualizer.INSTANCE;
	final OType linkedType = property.getLinkedType();
	final OType oType = linkedType != null ? linkedType : (OType.LINKMAP.equals(property.getType()) ? OType.LINK :OType.ANY);
	IModel<Set<Map.Entry<String, V>>> entriesModel = new PropertyModel<>(getModel(), "entrySet()");
	ListView<Map.Entry<String, V>> listView = 
			new ListView<Map.Entry<String, V>>("items", new CollectionAdapterModel<>(entriesModel)) {

		@Override
		protected void populateItem(ListItem<Map.Entry<String, V>> item) {
			item.add(new Label("key", new PropertyModel<String>(item.getModel(), "key")));
			item.add(visualizer.createComponent("item", DisplayMode.VIEW, documentModel, propertyModel, oType, new PropertyModel<V>(item.getModel(), "value")));
		}
		
		@Override
		protected ListItem<Map.Entry<String, V>> newItem(int index, IModel<Map.Entry<String, V>> itemModel) {
			return new ListItem<Map.Entry<String, V>>(index, itemModel)
					{
						@Override
						public IMarkupFragment getMarkup(Component child) {
							if(child==null || !child.getId().equals("item")) return super.getMarkup(child);
							IMarkupFragment ret = markupProvider.provideMarkup(child);
							return ret!=null?ret:super.getMarkup(child);
						}
					};
		}
	};
	add(listView);
}
 
Example 13
Source File: MergeLinkedAccountsWizardBuilder.java    From syncope with Apache License 2.0 5 votes vote down vote up
public MergeLinkedAccountsWizardBuilder(
        final IModel<UserTO> model,
        final PageReference pageRef,
        final UserDirectoryPanel parentPanel,
        final BaseModal<?> modal) {

    super(model.getObject(), pageRef);
    this.parentPanel = parentPanel;
    this.modal = modal;
}
 
Example 14
Source File: OChoiceRenderer.java    From wicket-orientdb with Apache License 2.0 5 votes vote down vote up
@Override
public ODocument getObject(String id,
		IModel<? extends List<? extends ODocument>> choicesModel) {
	List<? extends ODocument> choices = choicesModel.getObject();
	for (int index = 0; index < choices.size(); index++)
	{
		// Get next choice
		final ODocument choice = choices.get(index);
		if (getIdValue(choice, index).equals(id))
		{
			return choice;
		}
	}
	return null;
}
 
Example 15
Source File: QuickSelectMonthPanel.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param id
 * @param model Should contain begin of month as object.
 * @param caller
 * @param selectProperty
 */
public QuickSelectMonthPanel(final String id, final IModel<Date> model, final ISelectCallerPage caller, final String selectProperty)
{
  super(id, model, caller, selectProperty);
  this.beginOfMonth = model.getObject();
  this.selectProperty = selectProperty;
}
 
Example 16
Source File: DefaultVisualizer.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <V> Component getFilterComponent(final String id, final IModel<OProperty> propertyModel,
										final FilterForm<OQueryModel<?>> filterForm) {
	IFilterCriteriaManager manager = getManager(propertyModel, filterForm);
	OProperty property = propertyModel.getObject();
	OType type = property.getType();
	List<AbstractFilterPanel<?, ?>> filters = new LinkedList<>();

	switch (type) {
		case LINKBAG:
		case TRANSIENT:
		case BINARY:
		case ANY:
			return null;
		case EMBEDDED:
			filters.add(new EmbeddedContainsValuePanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new EmbeddedContainsKeyPanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case LINK:
			filters.add(new LinkEqualsFilterPanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new CollectionLinkFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case EMBEDDEDLIST:
		case EMBEDDEDSET:
			OProperty prop = propertyModel.getObject();
			if (prop != null) {
				if (prop.getLinkedType() != null) {
					filters.add(new EmbeddedCollectionContainsFilterPanel(FilterPanel.PANEL_ID, Model.of(),
							id, propertyModel, DefaultVisualizer.this, manager));
				} else {
					filters.add(new EmbeddedCollectionFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
							id, propertyModel, DefaultVisualizer.this, manager, true));
				}
			}
			break;
		case LINKLIST:
		case LINKSET:
			filters.add(new CollectionLinkFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case EMBEDDEDMAP:
		case LINKMAP:
			filters.add(new MapContainsKeyFilterPanel(FilterPanel.PANEL_ID, Model.<String>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			if (type == OType.EMBEDDEDMAP) {
				filters.add(new EmbeddedMapContainsValueFilterPanel(FilterPanel.PANEL_ID, Model.of(),
						id, propertyModel, DefaultVisualizer.this, manager));
			} else {
				filters.add(new LinkMapContainsValueFilterPanel(FilterPanel.PANEL_ID, Model.<ODocument>of(),
						id, propertyModel, DefaultVisualizer.this, manager));
			}
			break;
		case STRING:

			filters.add(new ContainsStringFilterPanel(FilterPanel.PANEL_ID, Model.<String>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new EqualsFilterPanel(FilterPanel.PANEL_ID, Model.<String>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new CollectionFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<String>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		case BOOLEAN:
			filters.add(new EqualsFilterPanel(FilterPanel.PANEL_ID, Model.<Boolean>of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			break;
		default:
			filters.add(new EqualsFilterPanel(FilterPanel.PANEL_ID, Model.of(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new CollectionFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
			filters.add(new RangeFilterPanel(FilterPanel.PANEL_ID, new CollectionModel<>(),
					id, propertyModel, DefaultVisualizer.this, manager));
	}

	return new FilterPanel(id, new OPropertyNamingModel(propertyModel), filterForm, filters);
}
 
Example 17
Source File: SortObjectDataProvider.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
public SortObjectDataProvider(IModel<ArrayList<String>> propertyModel, IModel<ArrayList<Boolean>> orderModel) {
	Injector.get().inject(this);
	sortProperty = propertyModel.getObject();
	ascending = orderModel.getObject();
}
 
Example 18
Source File: TreePanel.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@Override
protected Component newNodeComponent(String id, IModel<java.lang.Object> model) {
  TreeNode treeNode = (TreeNode) model.getObject();
  return populateNode(id, treeNode);
}
 
Example 19
Source File: AnalysisNavigationPanel.java    From nextreports-server with Apache License 2.0 3 votes vote down vote up
public Tab(String id, final IModel<Object> model, int index) {
	super(id, "tab", AnalysisNavigationPanel.this);

	setOutputMarkupId(true);

	final Object analysis = model.getObject();

	add(createTitleLink(analysis, index));
}
 
Example 20
Source File: EditJasperParametersPanel.java    From nextreports-server with Apache License 2.0 3 votes vote down vote up
public ActionPanel(String id, final IModel<JasperParameterSource> model) {
    super(id, model);

    setRenderBodyOnly(true);

    MenuPanel menuPanel = new MenuPanel("menuPanel");
    add(menuPanel);

    MenuItem mi = new MenuItem("images/actions.png", null);
    menuPanel.addMenuItem(mi);


    AjaxLink<JasperParameterSource> editLink = new AjaxLink<JasperParameterSource>(MenuPanel.LINK_ID, model) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            JasperParameterSource parameter = model.getObject();

            EntityBrowserPanel panel = findParent(EntityBrowserPanel.class);
            panel.forwardWorkspace(new ChangeJasperParameterPanel("work", report, parameter), target);    

            //setResponsePage(new ChangeJasperParameterPage(report, parameter));

        }
    };
    mi.addMenuItem(new MenuItem(editLink, getString("ActionContributor.EditParameters.edit"), "images/paramedit.png"));
}