org.apache.wicket.model.LoadableDetachableModel Java Examples

The following examples show how to use org.apache.wicket.model.LoadableDetachableModel. 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: WatchStatusLink.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {

		@Override
		protected String load() {
			WatchStatus status = getWatchStatus();
			if (status == WatchStatus.DO_NOT_WATCH)
				return "do-not-watch";
			else if (status == WatchStatus.WATCH)
				return "watch";
			else
				return "default";
		}
		
	}));
	
}
 
Example #2
Source File: StringMatchingRecommenderTraitsEditor.java    From inception with Apache License 2.0 6 votes vote down vote up
public GazeteerList(String aId, IModel<? extends List<Gazeteer>> aChoices)
{
    super(aId, aChoices);
    
    setOutputMarkupPlaceholderTag(true);
    
    gazeteerList = new ListView<Gazeteer>("gazeteer", aChoices) {
        private static final long serialVersionUID = 2827701590781214260L;

        @Override
        protected void populateItem(ListItem<Gazeteer> aItem)
        {
            Gazeteer gazeteer = aItem.getModelObject();
            
            aItem.add(new Label("name", aItem.getModelObject().getName()));

            aItem.add(new LambdaAjaxLink("delete",
                _target -> actionDeleteGazeteer(_target, gazeteer)));

            aItem.add(new DownloadLink("download",
                    LoadableDetachableModel.of(() -> getGazeteerFile(gazeteer)),
                    gazeteer.getName()));
        }
    };
    add(gazeteerList);
}
 
Example #3
Source File: FieldsEditorExistingPanel.java    From ontopia with Apache License 2.0 6 votes vote down vote up
private static Component getCardinality(String id, final FieldAssignmentModel fam) {    
  LoadableDetachableModel<List<Cardinality>> cardinalityChoicesModel = new LoadableDetachableModel<List<Cardinality>>() {
    @Override
    protected List<Cardinality> load() {
      return Cardinality.getCardinalityTypes(fam.getFieldAssignment().getFieldDefinition().getTopicMap());
    }   
  };
  final IModel<Cardinality> cardModel = new MutableLoadableDetachableModel<Cardinality>() {
    @Override
    protected Cardinality load() {
      return fam.getFieldAssignment().getCardinality();
    }
    @Override
    public void setObject(Cardinality card) {
      fam.getFieldAssignment().getFieldDefinition().setCardinality(card);
      super.setObject(card);
    }
  };
  AjaxOntopolyDropDownChoice<Cardinality> choice = new AjaxOntopolyDropDownChoice<Cardinality>(id, cardModel,
      cardinalityChoicesModel, new TopicChoiceRenderer<Cardinality>());
  return choice;
}
 
Example #4
Source File: AnnotationInfoPanel.java    From webanno with Apache License 2.0 6 votes vote down vote up
private Label createSelectedAnnotationTypeLabel()
{
    Label label = new Label("selectedAnnotationType", LoadableDetachableModel.of(() -> {
        try {
            AnnotationDetailEditorPanel editorPanel = findParent(
                    AnnotationDetailEditorPanel.class);
            return String.valueOf(selectFsByAddr(editorPanel.getEditorCas(),
                    getModelObject().getSelection().getAnnotation().getId())).trim();
        }
        catch (IOException e) {
            return "";
        }
    }));
    label.setOutputMarkupPlaceholderTag(true);
    // We show the extended info on the selected annotation only when run in development mode
    label.add(visibleWhen(() -> getModelObject().getSelection().getAnnotation().isSet()
            && DEVELOPMENT.equals(getApplication().getConfigurationType())));
    return label;
}
 
Example #5
Source File: SessionFeedbackPanel.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {

		@Override
		protected String load() {
			if (anyMessage(FeedbackMessage.ERROR) || anyMessage(FeedbackMessage.FATAL))
				return " error";
			else if (anyMessage(FeedbackMessage.WARNING))
				return " warning";
			else if (anyMessage(FeedbackMessage.SUCCESS))
				return " success";
			else
				return " info";
		}
		
	}));
}
 
Example #6
Source File: RoleDetailPage.java    From onedev with MIT License 6 votes vote down vote up
public RoleDetailPage(PageParameters params) {
	super(params);
	
	String roleIdString = params.get(PARAM_ROLE).toString();
	if (StringUtils.isBlank(roleIdString))
		throw new RestartResponseException(RoleListPage.class);
	
	roleModel = new LoadableDetachableModel<Role>() {

		@Override
		protected Role load() {
			return OneDev.getInstance(RoleManager.class).load(Long.valueOf(roleIdString));
		}
		
	};
}
 
Example #7
Source File: GroupPage.java    From onedev with MIT License 6 votes vote down vote up
public GroupPage(PageParameters params) {
	super(params);
	
	String groupIdString = params.get(PARAM_GROUP).toString();
	if (StringUtils.isBlank(groupIdString))
		throw new RestartResponseException(GroupListPage.class);
	
	Long groupId = Long.valueOf(groupIdString);
	
	groupModel = new LoadableDetachableModel<Group>() {

		@Override
		protected Group load() {
			return OneDev.getInstance(GroupManager.class).load(groupId);
		}
		
	};
}
 
Example #8
Source File: UserPage.java    From onedev with MIT License 6 votes vote down vote up
public UserPage(PageParameters params) {
	super(params);
	
	String userIdString = params.get(PARAM_USER).toString();
	if (StringUtils.isBlank(userIdString))
		throw new RestartResponseException(UserListPage.class);
	
	Long userId = Long.valueOf(userIdString);
	if (userId == User.SYSTEM_ID)
		throw new OneException("System user is not accessible");
	
	userModel = new LoadableDetachableModel<User>() {

		@Override
		protected User load() {
			return OneDev.getInstance(UserManager.class).load(userId);
		}
		
	};
}
 
Example #9
Source File: PullRequestCommentedActivity.java    From onedev with MIT License 6 votes vote down vote up
@Override
public Component render(String componentId, DeleteCallback deleteCallback) {
	return new PullRequestCommentedPanel(componentId, new LoadableDetachableModel<PullRequestComment>() {

		@Override
		protected PullRequestComment load() {
			return getComment();
		}
		
	}, new DeleteCallback() {
		
		@Override
		public void onDelete(AjaxRequestTarget target) {
			OneDev.getInstance(PullRequestCommentManager.class).delete(getComment());
			deleteCallback.onDelete(target);
		}
	});
}
 
Example #10
Source File: ProductCatalogPage.java    From the-app with Apache License 2.0 6 votes vote down vote up
private IModel<List<List<ProductInfo>>> productListModel() {
    return new LoadableDetachableModel<List<List<ProductInfo>>>() {
        @Override
        protected List<List<ProductInfo>> load() {
            List<List<ProductInfo>> lists = new ArrayList<>();
            List<ProductInfo> allProductInfos = new ArrayList<>(productService.findAll(productTypeModel.getObject()));
            while (allProductInfos.size() > 4) {
                List<ProductInfo> subList = allProductInfos.subList(0, 4);
                lists.add(new ArrayList<>(subList));
                allProductInfos.removeAll(subList);
            }
            lists.add(allProductInfos);
            return lists;
        }
    };
}
 
Example #11
Source File: MilestoneDetailPage.java    From onedev with MIT License 6 votes vote down vote up
public MilestoneDetailPage(PageParameters params) {
	super(params);
	
	String idString = params.get(PARAM_MILESTONE).toString();
	if (StringUtils.isBlank(idString))
		throw new RestartResponseException(MilestoneListPage.class, MilestoneListPage.paramsOf(getProject(), false, null));
	
	Long milestoneId = Long.valueOf(idString);
	milestoneModel = new LoadableDetachableModel<Milestone>() {

		@Override
		protected Milestone load() {
			return OneDev.getInstance(MilestoneManager.class).load(milestoneId);
		}
		
	};
	
	query = params.get(PARAM_QUERY).toString();
}
 
Example #12
Source File: InvalidPullRequestPage.java    From onedev with MIT License 6 votes vote down vote up
public InvalidPullRequestPage(PageParameters params) {
	super(params);
	
	requestModel = new LoadableDetachableModel<PullRequest>() {

		@Override
		protected PullRequest load() {
			Long requestNumber = params.get(PARAM_REQUEST).toLong();
			PullRequest request = OneDev.getInstance(PullRequestManager.class).find(getProject(), requestNumber);
			if (request == null)
				throw new EntityNotFoundException("Unable to find pull request #" + requestNumber + " in project " + getProject());
			Preconditions.checkState(!request.isValid());
			return request;
		}

	};
}
 
Example #13
Source File: BlobIcon.java    From onedev with MIT License 6 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {

		@Override
		protected String load() {
			BlobIdent blobIdent = (BlobIdent) getDefaultModelObject();
			if (blobIdent.isTree())
				return " fa fa-folder-o";
			else if (blobIdent.isGitLink()) 
				return " fa fa-ext fa-folder-submodule-o";
			else if (blobIdent.isSymbolLink()) 
				return " fa fa-ext fa-folder-symbol-link-o";
			else  
				return " fa fa-file-text-o";
		}
		
	}));
}
 
Example #14
Source File: SearchPage.java    From inception with Apache License 2.0 6 votes vote down vote up
public SearchForm(String id)
{
    super(id);
    
    setModel(CompoundPropertyModel.of(new SearchFormModel()));
    
    DropDownChoice<DocumentRepository> repositoryCombo = 
            new BootstrapSelect<DocumentRepository>("repository");
    repositoryCombo.setChoices(LoadableDetachableModel
            .of(() -> externalSearchService.listDocumentRepositories(project)));
    repositoryCombo.setChoiceRenderer(new ChoiceRenderer<DocumentRepository>("name"));
    repositoryCombo.setNullValid(false);
    add(repositoryCombo);
    
    if (!repositoryCombo.getChoices().isEmpty()) {
        repositoryCombo.setModelObject(repositoryCombo.getChoices().get(0));
    }
    
    add(new TextField<>("query", String.class));
    
    LambdaAjaxSubmitLink searchLink = new LambdaAjaxSubmitLink("submitSearch",
            this::actionSearch);
    add(searchLink);
    setDefaultButton(searchLink);
}
 
Example #15
Source File: ExternalResultDataProvider.java    From inception with Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.wicket.markup.repeater.data.IDataProvider#model(java.lang.Object)
 */
@Override
public IModel<ExternalSearchResult> model(ExternalSearchResult object)
{
    return new LoadableDetachableModel<ExternalSearchResult>(object)
    {

        private static final long serialVersionUID = -8141568381625089300L;

        @Override
        protected ExternalSearchResult load()
        {
            return object;
        }
    };
}
 
Example #16
Source File: RequestStatusLabel.java    From onedev with MIT License 6 votes vote down vote up
public RequestStatusLabel(String id, IModel<PullRequest> requestModel) {
	super(id, new LoadableDetachableModel<String>() {

		@Override
		protected String load() {
			PullRequest request = requestModel.getObject();
			CloseInfo closeInfo = request.getCloseInfo();
			if (closeInfo == null)
				return PullRequest.STATE_OPEN;
			else 
				return closeInfo.getStatus().toString();
		}
		
	});
	this.requestModel = requestModel;
}
 
Example #17
Source File: ActionBar.java    From webanno with Apache License 2.0 6 votes vote down vote up
public ActionBar(String aId)
{
    super(aId);

    add(new ListView<ActionBarExtension>("items",
            LoadableDetachableModel.of(this::getExtensions))
    {
        private static final long serialVersionUID = -3124915140030491897L;

        @Override
        protected void populateItem(ListItem<ActionBarExtension> aItem)
        {
            aItem.add(aItem.getModelObject().createActionBarItem("item",
                    (AnnotationPageBase) getPage()));
        }
    });
}
 
Example #18
Source File: StartPage.java    From ontopia with Apache License 2.0 6 votes vote down vote up
private void addOtherTopicMapsSection() {
  // Alt. 2 Make a loadabledetachableModel for repository
  IModel<List<TopicMapReference>> eachNonOntopolyTopicMapModel = new LoadableDetachableModel<List<TopicMapReference>>() {
    @Override
    protected List<TopicMapReference> load() {
      OntopolyRepository repository = OntopolyContext.getOntopolyRepository();
      return repository.getNonOntopolyTopicMaps();
    }
  }; 

  ListView<TopicMapReference> eachTopicMap = new ListView<TopicMapReference>("eachNonOntopolyTopicMap", eachNonOntopolyTopicMapModel) {
    @Override
    protected void populateItem(ListItem<TopicMapReference> item) {
      final TopicMapReference ref = item.getModelObject();
      Map<String,String> pageParameterMap = new HashMap<String,String>();
      pageParameterMap.put("topicMapId",ref.getId());
      
      OntopolyBookmarkablePageLink link = new OntopolyBookmarkablePageLink(
          "nonOntTMLink", ConvertPage.class, new PageParameters(pageParameterMap), ref.getName());
      item.add(link);
    }
  };
  add(eachTopicMap);
}
 
Example #19
Source File: ActiveLearningSidebar.java    From inception with Apache License 2.0 6 votes vote down vote up
private Form<Void> createSessionControlForm()
{
    Form<Void> form = new Form<>(CID_SESSION_CONTROL_FORM);

    DropDownChoice<AnnotationLayer> layersDropdown = new BootstrapSelect<>(CID_SELECT_LAYER);
    layersDropdown.setModel(alStateModel.bind("layer"));
    layersDropdown.setChoices(LoadableDetachableModel.of(this::listLayersWithRecommenders));
    layersDropdown.setChoiceRenderer(new LambdaChoiceRenderer<>(AnnotationLayer::getUiName));
    layersDropdown.add(LambdaBehavior.onConfigure(it -> it.setEnabled(!alStateModel
        .getObject().isSessionActive())));
    layersDropdown.setOutputMarkupId(true);
    layersDropdown.setRequired(true);
    form.add(layersDropdown);
    
    form.add(new LambdaAjaxSubmitLink(CID_START_SESSION_BUTTON, this::actionStartSession)
            .add(visibleWhen(() -> !alStateModel.getObject().isSessionActive())));
    form.add(new LambdaAjaxLink(CID_STOP_SESSION_BUTTON, this::actionStopSession)
        .add(visibleWhen(() -> alStateModel.getObject().isSessionActive())));
    form.add(visibleWhen(() -> alStateModel.getObject().isDoExistRecommenders()));

    return form;
}
 
Example #20
Source File: PullRequestChangeActivity.java    From onedev with 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 #21
Source File: CardCountLabel.java    From onedev with MIT License 5 votes vote down vote up
public CardCountLabel(String id) {
	super(id);
	
	setDefaultModel(new LoadableDetachableModel<String>() {

		@Override
		protected String load() {
			return String.valueOf(getCount());
		}
	
	});
}
 
Example #22
Source File: ReviewListPanel.java    From onedev with MIT License 5 votes vote down vote up
public ReviewListPanel(String id) {
	super(id);
	
	reviewsModel = new LoadableDetachableModel<List<PullRequestReview>>() {

		@Override
		protected List<PullRequestReview> load() {
			return getPullRequest().getSortedReviews();
		}
		
	};		
}
 
Example #23
Source File: PullRequestOpenedActivity.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Component render(String componentId, DeleteCallback deleteCallback) {
	return new PullRequestOpenedPanel(componentId, new LoadableDetachableModel<PullRequest>() {

		@Override
		protected PullRequest load() {
			return getRequest();
		}
		
	});
}
 
Example #24
Source File: ReferencedFromPullRequestPanel.java    From onedev with MIT License 5 votes vote down vote up
public ReferencedFromPullRequestPanel(String id, Long requestId) {
	super(id, new LoadableDetachableModel<PullRequest>() {

		@Override
		protected PullRequest load() {
			return OneDev.getInstance(PullRequestManager.class).load(requestId);
		}
		
	});
}
 
Example #25
Source File: AssignmentListPanel.java    From onedev with MIT License 5 votes vote down vote up
public AssignmentListPanel(String id) {
	super(id);
	
	assignmentsModel = new LoadableDetachableModel<List<PullRequestAssignment>>() {

		@Override
		protected List<PullRequestAssignment> load() {
			PullRequest request = getPullRequest();
			List<PullRequestAssignment> assignments = new ArrayList<>(request.getAssignments());
			
			Collections.sort(assignments, new Comparator<PullRequestAssignment>() {

				@Override
				public int compare(PullRequestAssignment o1, PullRequestAssignment o2) {
					if (o1.getId() != null && o2.getId() != null)
						return o1.getId().compareTo(o1.getId());
					else
						return 0;
				}
				
			});
			
			return assignments;
		}
		
	};		
}
 
Example #26
Source File: InvalidCodeCommentPage.java    From onedev with MIT License 5 votes vote down vote up
public InvalidCodeCommentPage(PageParameters params) {
	super(params);
	
	codeCommentModel = new LoadableDetachableModel<CodeComment>() {

		@Override
		protected CodeComment load() {
			Long codeCommentId = params.get(PARAM_COEDE_COMMENT).toLong();
			CodeComment codeComment = OneDev.getInstance(CodeCommentManager.class).load(codeCommentId);
			Preconditions.checkState(!codeComment.isValid());
			return codeComment;
		}

	};
}
 
Example #27
Source File: CartPanel.java    From the-app with Apache License 2.0 5 votes vote down vote up
private IModel<List<CartItemInfo>> cartListModel() {
    return new LoadableDetachableModel<List<CartItemInfo>>() {
        @Override
        protected List<CartItemInfo> load() {
            try {
                return cart.getAll();
            } catch (Exception e) {
                getSession().error("Cart is not available yet, please try again later.");
                return Collections.emptyList();
            }
        }
    };
}
 
Example #28
Source File: MilestoneStatusLabel.java    From onedev with MIT License 5 votes vote down vote up
public MilestoneStatusLabel(String id, IModel<Milestone> milestoneModel) {
	super(id, new LoadableDetachableModel<String>() {

		@Override
		protected String load() {
			return milestoneModel.getObject().getStatusName();
		}
		
	});
	this.milestoneModel = milestoneModel;
}
 
Example #29
Source File: HomePage.java    From the-app with Apache License 2.0 5 votes vote down vote up
private Component youMayAlsoLikeProductsPanel() {
    return new RecommendationItemListPanel("youMayAlsoLikeProductsContainer", feedback, "MAY_ALSO_LIKE", new ResourceModel("you.may.also.like.topic"),
            new LoadableDetachableModel<List<ProductInfo>>() {
                @Override
                protected List<ProductInfo> load() {
                    return recommendationService.getCollaborativeFilteringRecommendations(4);
                }
            }) {
    };
}
 
Example #30
Source File: IssueChangeActivity.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Panel render(String panelId, DeleteCallback callback) {
	return new IssueChangePanel(panelId, new LoadableDetachableModel<IssueChange>() {

		@Override
		protected IssueChange load() {
			return getChange();
		}
		
	});
}