org.apache.wicket.util.visit.IVisitor Java Examples

The following examples show how to use org.apache.wicket.util.visit.IVisitor. 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: BeanEditor.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected Serializable convertInputToValue() throws ConversionException {
	final Serializable bean = (Serializable) getDescriptor().newBeanInstance();
	
	visitChildren(PropertyEditor.class, new IVisitor<PropertyEditor<Serializable>, PropertyEditor<Serializable>>() {

		@Override
		public void component(PropertyEditor<Serializable> object, IVisit<PropertyEditor<Serializable>> visit) {
			if (!object.getDescriptor().isPropertyExcluded()) 
				object.getDescriptor().setPropertyValue(bean, object.getConvertedInput());
			visit.dontGoDeeper();
		}
		
	});
	
	return bean;
}
 
Example #2
Source File: AbstractMetaPanel.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <K extends AbstractMetaPanel<?, ?, ?>> K getMetaComponent(IMetaContext<?> context, final Object critery)
{
	if(context==null || critery==null) return null;
	else return (K)context.getContextComponent()
					.visitChildren(AbstractMetaPanel.class, new IVisitor<AbstractMetaPanel<?, ?, ?>, AbstractMetaPanel<?, ?, ?>>() {

						@Override
						public void component(
								AbstractMetaPanel<?, ?, ?> object,
								IVisit<AbstractMetaPanel<?, ?, ?>> visit) {
							if(Objects.isEqual(object.getPropertyObject(), critery)) visit.stop(object);
							else visit.dontGoDeeper();
						}
	});
}
 
Example #3
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 #4
Source File: SaveOLocalizationsCommand.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(Optional<AjaxRequestTarget> targetOptional) {
    table.visitChildren(OrienteerDataTable.MetaContextItem.class, new IVisitor<OrienteerDataTable.MetaContextItem<ODocument, ?>, Void>() {

        @Override
        public void component(OrienteerDataTable.MetaContextItem<ODocument, ?> rowItem, IVisit<Void> visit) {
            ODocument modelObject = rowItem.getModelObject();
            if (modelObject == null) {
                return;
            }

            String localizationLang = modelObject.field(OrienteerLocalizationModule.OPROPERTY_LANG);
            String localizationValue = modelObject.field(OrienteerLocalizationModule.OPROPERTY_VALUE);
            if (!Strings.isNullOrEmpty(localizationLang) && !Strings.isNullOrEmpty(localizationValue)) {
                modelObject.field(OrienteerLocalizationModule.OPROPERTY_ACTIVE, true);
            }

            modelObject.save();
            visit.dontGoDeeper();
        }
    });
    super.onClick(targetOptional);
}
 
Example #5
Source File: BootstrapFeedbackPopover.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	filter = new IFeedbackMessageFilter() {
		private static final long serialVersionUID = -7726392072697648969L;

		public boolean accept(final FeedbackMessage msg) {
			Boolean b = visitChildren(FormComponent.class, new IVisitor<FormComponent<?>, Boolean>() {
				@Override
				public void component(FormComponent<?> arg0, IVisit<Boolean> arg1) {
					if (arg0.equals(msg.getReporter()))
						arg1.stop(true);
				}
			});

			if (b == null)
				return false;

			return b;
		}
	};

}
 
Example #6
Source File: BootstrapFeedbackPanel.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean accept(final FeedbackMessage message) {
	if(BootstrapFeedbackPanel.this.getParent()!=null){
		BootstrapFeedbackPopover innerAccepted = BootstrapFeedbackPanel.this.getParent()
				.visitChildren(BootstrapFeedbackPopover.class, new IVisitor<BootstrapFeedbackPopover, BootstrapFeedbackPopover>() {

			@Override
			public void component(BootstrapFeedbackPopover object, IVisit<BootstrapFeedbackPopover> visit) {
				if(object.getFilter().accept(message)){
					visit.stop(object);
				}
			}
		});
		
		return innerAccepted==null;
	}
	return true;
}
 
Example #7
Source File: BootstrapControlGroupFeedback.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onConfigure() {
	super.onConfigure();
	
	filter = new IFeedbackMessageFilter() {
		private static final long serialVersionUID = -7726392072697648969L;

		public boolean accept(final FeedbackMessage msg) {
			Boolean b = visitChildren(FormComponent.class, new IVisitor<FormComponent<?>, Boolean>() {
				@Override
				public void component(FormComponent<?> arg0, IVisit<Boolean> arg1) {
					if (arg0.equals(msg.getReporter()))
						arg1.stop(true);
				}
			});

			if (b == null)
				return false;

			return b;
		}
	};
}
 
Example #8
Source File: BootstrapDateTimePicker.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the DateTextField inside this datepicker wrapper.
 *
 * @return the date field
 */
public DateTextField getDateTextField()
{
	DateTextField component = visitChildren(DateTextField.class, new IVisitor<DateTextField, DateTextField>() {
		@Override
		public void component(DateTextField arg0, IVisit<DateTextField> arg1) {
			arg1.stop(arg0);
		}
	});

	if (component == null) {
		
		throw new WicketRuntimeException("BootstrapDateTimepicker didn't have any DateTextField child!");
	}
	
	return component;
}
 
Example #9
Source File: SaveODocumentsCommand.java    From Orienteer with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(Optional<AjaxRequestTarget> targetOptional) {
	table.visitChildren(OrienteerDataTable.MetaContextItem.class, new IVisitor<OrienteerDataTable.MetaContextItem<ODocument, ?>, Void>() {

		@Override
		public void component(MetaContextItem<ODocument, ?> rowItem, IVisit<Void> visit) {
			ODocument doc = rowItem.getModelObject();
			if(doc.isDirty()) {
				if(doc.getIdentity().isNew()) SaveODocumentCommand.realizeMandatory(doc);
				doc.save();
			}
			visit.dontGoDeeper();
		}
	});
	if(forceCommit) {
		ODatabaseDocument db = getDatabase();
		boolean active = db.getTransaction().isActive();
		db.commit();
		if(active) db.begin();
	}
	super.onClick(targetOptional);
}
 
Example #10
Source File: WicketPageTestBase.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Searches ContentMenuEntryPanels.
 * @param container
 * @param accessKey
 * @return Found component with the given label or null if no such component found.
 * @see FormComponent#getModelObject()
 * @see LabeledWebMarkupContainer#getLabel()
 * @see ContentMenuEntryPanel#getLabel()
 */
public Component findComponentByAccessKey(final MarkupContainer container, final char accessKey)
{
  final Component[] component = new Component[1];
  container.visitChildren(new IVisitor<Component, Void>() {
    @Override
    public void component(final Component object, final IVisit<Void> visit)
    {
      if (object instanceof AbstractLink) {
        final AbstractLink link = (AbstractLink) object;
        final AttributeModifier attrMod = WicketUtils.getAttributeModifier(link, "accesskey");
        if (attrMod == null || attrMod.toString().contains("object=[n]") == false) {
          return;
        }
        component[0] = object;
        visit.stop();
      }
    }
  });
  return component[0];
}
 
Example #11
Source File: AjaxCheckTablePanel.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
private void onHeaderCheckChanged(final boolean selectAll, final AjaxRequestTarget target) {
 	// refresh rows affected by changing
 	dataTable.visitChildren(HighlitableDataItem.class, new IVisitor<HighlitableDataItem, Void>() {

@Override
public void component(HighlitableDataItem object, IVisit<Void> visit) {
 			if (object.isHighlite() != selectAll) {
 				object.toggleHighlite();
 				target.add(object);
 			}
}

 	});

 	// refresh bulk menu
 	updateSelectedObjects();
     new BulkMenuUpdateEvent(this, target).fire();
 }
 
Example #12
Source File: RevisionDiffPanel.java    From onedev with MIT License 6 votes vote down vote up
@Nullable
private SourceAware getSourceAware(String path) {
	return diffsView.visitChildren(new IVisitor<Component, SourceAware>() {

		@SuppressWarnings("unchecked")
		@Override
		public void component(Component object, IVisit<SourceAware> visit) {
			if (object instanceof ListItem) {
				ListItem<BlobChange> item = (ListItem<BlobChange>) object;
				if (item.getModelObject().getPaths().contains(path)) {
					visit.stop((SourceAware) item.get(DIFF_ID));
				} else {
					visit.dontGoDeeper();
				}
			} 
		}

	});
}
 
Example #13
Source File: BeanEditor.java    From onedev with MIT License 6 votes vote down vote up
@Override
public void error(PathNode propertyNode, Path pathInProperty, String errorMessage) {
	PathNode.Named named = (Named) propertyNode;
	PropertyEditor<?> propertyEditor = visitChildren(PropertyEditor.class, 
			new IVisitor<PropertyEditor<Serializable>, PropertyEditor<Serializable>>() {

		@Override
		public void component(PropertyEditor<Serializable> object, IVisit<PropertyEditor<Serializable>> visit) {
			if (object.getDescriptor().getPropertyName().equals(named.getName()) && object.isVisibleInHierarchy())
				visit.stop(object);
			else
				visit.dontGoDeeper();
		}
		
	});
	if (propertyEditor != null)
		propertyEditor.error(pathInProperty, errorMessage);
}
 
Example #14
Source File: StructureTable.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigure()
{
	super.onConfigure();

	toolbars.configure();

	Boolean visible = toolbars.visitChildren(new IVisitor<Component, Boolean>()
	{
		@Override
		public void component(Component object, IVisit<Boolean> visit)
		{
			object.configure();
			if (object.isVisible())
			{
				visit.stop(Boolean.TRUE);
			}
			else
			{
				visit.dontGoDeeper();
			}
		}
	});
	if (visible == null)
	{
		visible = false;
	}
	setVisible(visible);
}
 
Example #15
Source File: NextFeedbackPanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
private List<FormComponent<?>> getFormComponents(Form<?> form) {
     final List<FormComponent<?>> components = new ArrayList<FormComponent<?>>();
     form.visitFormComponents(new IVisitor<FormComponent<?>, Void>() {

@Override
public void component(FormComponent<?> object, IVisit<Void> visit) {
             components.add(object);
}

     });
     
     return components;
 }
 
Example #16
Source File: AjaxCheckTablePanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
private void updateSelectedObjects() {
 	selectedObjects.clear();
 	dataTable.visitChildren(HighlitableDataItem.class, new IVisitor<HighlitableDataItem, Void>() {

@Override
public void component(HighlitableDataItem object, IVisit<Void> visit) {
 			if (object.isHighlite()) {
 				selectedObjects.add(object.getModelObject());
 			}

	visit.dontGoDeeper();
}

 	});
 }
 
Example #17
Source File: AjaxCheckTablePanel.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@Override
    public Component getHeader(String componentId) {
    	IModel<Boolean> checkBoxHeaderModel = new LoadableDetachableModel<Boolean>() {

private static final long serialVersionUID = 1L;

private boolean selected;

@Override
protected Boolean load() {
	selected = false;
      	dataTable.visitChildren(HighlitableDataItem.class, new IVisitor<HighlitableDataItem, Void>() {

		@Override
		public void component(HighlitableDataItem object, IVisit<Void> visit) {
      			if (!object.isHighlite()) {
      				selected = false;
      				return;
      			}
      			
      			selected = true;
      			
  				visit.dontGoDeeper();
		}

      	});

      	return selected;
}
    		
    	};

        return new CheckBoxHeaderPanel(componentId, checkBoxHeaderModel);
    }
 
Example #18
Source File: EmbeddedCollectionEditPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
protected void convertToData() {
	visitFormComponentsPostOrder(this, new IVisitor<FormComponent<?>, Void>() {

		@Override
		public void component(FormComponent<?> object,
				IVisit<Void> visit) {
			if(embeddedView != null && embeddedView.equals(object.getClass()))
			{
				object.convertInput();
				object.updateModel();
				visit.dontGoDeeper();
			}
		}
	});
}
 
Example #19
Source File: EmbeddedMapEditPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
protected void convertToData() {
	visitChildren(FormComponent.class, new IVisitor<FormComponent<Object>, Void>() {

		@Override
		public void component(FormComponent<Object> object,
				IVisit<Void> visit) {
			if(!(EmbeddedMapEditPanel.this.equals(object)))
			{
				object.convertInput();
				object.updateModel();
				visit.dontGoDeeper();
			}
		}
	});
}
 
Example #20
Source File: AbstractMetaPanel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <C> IMetaContext<C> getMetaContext(Component component)
{
	return (IMetaContext<C>) component.visitParents(MarkupContainer.class, new IVisitor<MarkupContainer, IMetaContext<C>>() {

		@Override
		public void component(MarkupContainer object,
				IVisit<IMetaContext<C>> visit) {
			visit.stop((IMetaContext<C>)object);
		}
	}, new ClassVisitFilter(IMetaContext.class));
}
 
Example #21
Source File: InfinitePagingDataTable.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public void onConfigure()
{
	super.onConfigure();
	toolbars.configure();

	Boolean visible = toolbars.visitChildren(new IVisitor<Component, Boolean>()
	{
		@Override
		public void component(Component object, IVisit<Boolean> visit)
		{
			object.configure();
			if (object.isVisible())
			{
				visit.stop(Boolean.TRUE);
			}
			else
			{
				visit.dontGoDeeper();
			}
		}
	});

	if (visible == null)
	{
		visible = false;
	}

	setVisible(visible);
}
 
Example #22
Source File: BootstrapDatePicker.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the DateTextField inside this datepicker wrapper.
 *
 * @return the date field
 */
public DateTextField getDateTextField(){
	DateTextField component = visitChildren(DateTextField.class, new IVisitor<DateTextField, DateTextField>() {
		@Override
		public void component(DateTextField arg0, IVisit<DateTextField> arg1) {
			arg1.stop(arg0);
		}
	});

	if (component == null)
		throw new WicketRuntimeException("BootstrapDatepicker didn't have any DateTextField child!");

	return component;
}
 
Example #23
Source File: BootstrapTemporalDatepicker.java    From pm-wicket-utils with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onConfigure() {
	super.onConfigure();

	dateField = visitChildren(TemporalTextField.class, new IVisitor<TemporalTextField<T>, TemporalTextField<T>>() {
		@Override
		public void component(TemporalTextField<T> arg0, IVisit<TemporalTextField<T>> arg1) {
			arg1.stop(arg0);
		}
	});
}
 
Example #24
Source File: InfinitePagingDataTable.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Override
public void onConfigure()
{
	super.onConfigure();
	toolbars.configure();

	Boolean visible = toolbars.visitChildren(new IVisitor<Component, Boolean>()
	{
		@Override
		public void component(Component object, IVisit<Boolean> visit)
		{
			object.configure();
			if (object.isVisible())
			{
				visit.stop(Boolean.TRUE);
			}
			else
			{
				visit.dontGoDeeper();
			}
		}
	});

	if (visible == null)
	{
		visible = false;
	}

	setVisible(visible);
}
 
Example #25
Source File: AddClusterModalPanel.java    From etcd-viewer with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeModalShow(AjaxRequestTarget target) {
    target.add(form);

    form.clearInput();

    form.visitFormComponents(new IVisitor<FormComponent<?>, Void>() {
        @Override
        public void component(FormComponent<?> object, IVisit<Void> visit) {
            if (object.hasFeedbackMessage()) {
                object.getFeedbackMessages().clear();
            }
        }
    });
}
 
Example #26
Source File: BasePage.java    From onedev with MIT License 5 votes vote down vote up
private Collection<WebSocketObserver> findWebSocketObservers() {
	Collection<WebSocketObserver> observers = new HashSet<>();
	observers.addAll(getBehaviors(io.onedev.server.web.behavior.WebSocketObserver.class));
	visitChildren(Component.class, new IVisitor<Component, Void>() {

		@Override
		public void component(Component object, IVisit<Void> visit) {
			observers.addAll(object.getBehaviors(WebSocketObserver.class));
		}

	});
	return observers;
}
 
Example #27
Source File: ValueEditor.java    From onedev with MIT License 5 votes vote down vote up
public void clearErrors() {
	visitComponentsPostOrder(this, new IVisitor<Component, Void>() {
		
		@Override
		public void component(Component formComponent, IVisit<Void> visit) {
			formComponent.getFeedbackMessages().clear();
		}
		
	});
}
 
Example #28
Source File: WicketPageTestBase.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Searches FormComponents (model object), LabeledWebmarkupContainers (label model) and ContentMenuEntryPanels (label).
 * @param container
 * @param label i18n key of the label or label (for buttons).
 * @return Found component with the given label or null if no such component found.
 * @see FormComponent#getModelObject()
 * @see LabeledWebMarkupContainer#getLabel()
 * @see ContentMenuEntryPanel#getLabel()
 */
public Component findComponentByLabel(final MarkupContainer container, final String label)
{
  String str = label;
  try {
    str = container.getString(label);
  } catch (final MissingResourceException ex) {
    // OK
  }
  final String locLabel = str;
  final Component[] component = new Component[1];
  container.visitChildren(new IVisitor<Component, Void>() {
    @Override
    public void component(final Component object, final IVisit<Void> visit)
    {
      if (object instanceof AbstractLink) {
        final MarkupContainer parent = object.getParent();
        if (parent instanceof ContentMenuEntryPanel) {
          if (labelEquals(((ContentMenuEntryPanel) parent).getLabel(), label, locLabel) == true) {
            component[0] = object;
            visit.stop();
          }
        } else if (object.getId().equals(locLabel) == true) {
          component[0] = object;
          visit.stop();
        }
      } else {
        if (object instanceof LabeledWebMarkupContainer) {
          final IModel<String> labelModel = ((LabeledWebMarkupContainer) object).getLabel();
          if (labelModel != null) {
            if (labelEquals(labelModel.getObject(), label, locLabel) == true) {
              component[0] = object;
              visit.stop();
            }
          }
        }
        if (object instanceof FormComponent< ? >) {
          final Object modelObject = ((FormComponent< ? >) object).getModelObject();
          if (modelObject instanceof String) {
            if (labelEquals((String) modelObject, label, locLabel) == true) {
              component[0] = object;
              visit.stop();
            }
          }
        }
      }
    }
  });
  return component[0];
}
 
Example #29
Source File: FormGroupBorder.java    From etcd-viewer with Apache License 2.0 4 votes vote down vote up
public FormGroupBorder(String id, IModel<String> labelModel) {
    super(id);

    formComponent = new LoadableDetachableModel<FormComponent<?>>() {
        private static final long serialVersionUID = 1L;
        @Override
        protected FormComponent<?> load() {
            return getBodyContainer().visitChildren(FormComponent.class, new IVisitor<FormComponent<?>, FormComponent<?>>() {
                @Override
                public void component(FormComponent<?> object, IVisit<FormComponent<?>> visit) {
                    visit.stop(object);
                }
            });
        }
    };

    Label label;
    addToBorder(label = new Label("label", labelModel));

    label.add(new AttributeAppender("for", new PropertyModel<>(formComponent, "markupId")));

    addToBorder(feedbackPanel = new FeedbackPanel("feedback", new ContainerFeedbackMessageFilter(getBodyContainer())));

    WebMarkupContainer feedbackIcon;
    addToBorder(feedbackIcon = new WebMarkupContainer("feedbackIcon"));

    feedbackIcon.add(new AttributeAppender("class", new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;
        @Override
        protected String load() {
            if (!feedbackPanel.anyMessage()) {
                return "";
            }
            return feedbackPanel.anyErrorMessage() ? "glyphicon-remove" : "glyphicon-ok";
        }
    }, " "));

    add(new AttributeAppender("class", new LoadableDetachableModel<String>() {
        private static final long serialVersionUID = 1L;
        @Override
        protected String load() {
            if (!feedbackPanel.anyMessage()) {
                return "";
            }
            return feedbackPanel.anyErrorMessage() ? "has-feedback has-error" : "has-feedback has-success";
        }
    }, " "));
}