Skip to content

Commit

Permalink
#22
Browse files Browse the repository at this point in the history
  • Loading branch information
bozanfaruk committed Jan 8, 2019
1 parent 5b5f04c commit 9ef38b1
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2014-2019 Logo Business Solutions
* (a.k.a. LOGO YAZILIM SAN. VE TIC. A.S)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.lbs.tedam.ui.components;

import com.lbs.tedam.localization.TedamLocalizerWrapper;
import com.lbs.tedam.ui.components.basic.TedamButton;
import com.lbs.tedam.ui.components.basic.TedamLabel;
import com.lbs.tedam.ui.components.basic.TedamPanel;
import com.lbs.tedam.ui.util.DateTimeFormatter;
import com.lbs.tedam.util.EnumsV2.JobStatus;
import com.vaadin.server.Resource;
import com.vaadin.ui.ProgressBar;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;

public class AbstractManagerPanel extends TedamPanel implements TedamLocalizerWrapper {

private static final long serialVersionUID = 1L;

protected final String PANEL_STYLE = ValoTheme.PANEL_WELL + " jobpanel";

protected TedamButton btnStart;
protected TedamButton btnStop;
protected TedamButton btnUnfollow;
protected TedamButton btnReset;
protected DateTimeFormatter dateTimeFormetter;
protected VerticalLayout mainLayout;

protected void initUI() {
setSizeUndefined();
mainLayout = new VerticalLayout();
setContent(mainLayout);
}

protected void buildButtons(JobStatus jobStatus) {
if (JobStatus.getInActiveJobStatus().contains(jobStatus)) {
getBtnStart().setEnabled(true);
getBtnStop().setEnabled(false);
} else {
getBtnStart().setEnabled(false);
getBtnStop().setEnabled(true);
}
}

protected TedamLabel buildLabel(String parameter) {
TedamLabel label = new TedamLabel(parameter);
label.setStyleName(ValoTheme.LABEL_TINY);
return label;
}

protected ProgressBar buildProgressBar(int completedJobDetailSize, int allJobDetailSize) {
ProgressBar progressBar = new ProgressBar();
progressBar.setValue(((float) completedJobDetailSize / allJobDetailSize));
progressBar.setDescription(completedJobDetailSize + "/" + allJobDetailSize);
return progressBar;
}

protected TedamButton buildButton(String id, String jobId, Resource icon) {
TedamButton button = new TedamButton(id, icon);
button.setId(button.getId() + jobId);
button.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
button.setWidthUndefined();
button.setCaption("");
return button;
}

protected TedamButton getBtnStart() {
return btnStart;
}

protected TedamButton getBtnStop() {
return btnStop;
}

protected TedamButton getBtnUnfollow() {
return btnUnfollow;
}
}
141 changes: 141 additions & 0 deletions src/main/java/com/lbs/tedam/ui/components/TedamJobGroupPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Copyright 2014-2019 Logo Business Solutions
* (a.k.a. LOGO YAZILIM SAN. VE TIC. A.S)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.lbs.tedam.ui.components;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.lbs.tedam.localization.LocaleConstants;
import com.lbs.tedam.localization.TedamLocalizerWrapper;
import com.lbs.tedam.model.Job;
import com.lbs.tedam.model.JobDetail;
import com.lbs.tedam.model.JobGroup;
import com.lbs.tedam.ui.components.basic.TedamLabel;
import com.lbs.tedam.ui.components.layout.TedamHorizontalLayout;
import com.lbs.tedam.ui.util.DateTimeFormatter;
import com.lbs.tedam.ui.util.TedamStatic;
import com.lbs.tedam.util.EnumsV2.CommandStatus;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.ui.ProgressBar;

@Component
@Scope("prototype")
public class TedamJobGroupPanel extends AbstractManagerPanel implements TedamLocalizerWrapper {

private static final long serialVersionUID = 1L;

private JobGroup jobGroup;
private JobGroupPanelButtonClickListener clickListener;

@Autowired
public TedamJobGroupPanel(DateTimeFormatter dateTimeFormetter) {
this.dateTimeFormetter = dateTimeFormetter;
}

@PostConstruct
public void init() {
initUI();
}

private void build() {
setStyleName(PANEL_STYLE);
addStyleName(TedamStatic.getJobStatusColorMap().get(jobGroup.getStatus()).toString().toLowerCase());
setCaption(jobGroup.getId() + " - " + jobGroup.getName());
setIcon(VaadinIcons.FILE_TREE);
buildVerticalLayout(jobGroup);
buildButtons(jobGroup.getStatus());
}

private void buildVerticalLayout(JobGroup jobGroup) {
mainLayout.removeAllComponents();
if (jobGroup.getLastExecutedStartDate() != null) {
TedamLabel startDate = buildLabel(
dateTimeFormetter.format(jobGroup.getLastExecutedStartDate(), LocaleConstants.LOCALE_TRTR));
mainLayout.addComponent(startDate);
}
TedamLabel environment = buildLabel("");
TedamLabel lastExecutingUser = buildLabel(getLocaleValue("view.jobmanager.lastexecutingusertitle"));
if (jobGroup.getLastExecutingUser() != null) {
lastExecutingUser.setValue(lastExecutingUser.getValue() + jobGroup.getLastExecutingUser().getUserName());
}
int[] countJobDetailSize = countJobDetailSize();
ProgressBar progressBar = buildProgressBar(countJobDetailSize[0], countJobDetailSize[1]);
TedamHorizontalLayout footer = buildFooter(jobGroup);
mainLayout.addComponents(environment, lastExecutingUser, progressBar, footer);
}

private int[] countJobDetailSize() {
int[] countJobDetailSize = new int[2];
countJobDetailSize[0] = 0;
countJobDetailSize[1] = 0;
for (Job job : jobGroup.getJobs()) {
for (JobDetail jobDetail : job.getJobDetails()) {
if (CommandStatus.COMPLETED.equals(jobDetail.getStatus())) {
countJobDetailSize[0]++;
}
countJobDetailSize[1]++;
}
}
return countJobDetailSize;
}

private TedamHorizontalLayout buildFooter(JobGroup jobGroup) {
TedamHorizontalLayout footer = new TedamHorizontalLayout();
footer.setStyleName("v-window-bottom-toolbar");
btnStart = buildButton("view.tedammanager.button.startjob", jobGroup.getId().toString(), VaadinIcons.PLAY);
btnStart.setDisableOnClick(true);
btnStart.addClickListener(e -> clickListener.startButtonClickOperations(jobGroup));
btnStop = buildButton("view.tedammanager.button.stopjob", jobGroup.getId().toString(), VaadinIcons.STOP);
btnStop.setDisableOnClick(true);
btnStop.addClickListener(e -> clickListener.stopButtonClickOperations(jobGroup));
btnUnfollow = buildButton("view.tedammanager.button.unfollowJob", jobGroup.getId().toString(),
VaadinIcons.EYE_SLASH);
btnUnfollow.addClickListener(e -> clickListener.unfollowButtonClickOperations(jobGroup));
btnReset = buildButton("view.tedammanager.button.resetJob", jobGroup.getId().toString(), VaadinIcons.REFRESH);
btnReset.addClickListener(e -> clickListener.resetButtonClickOperations(jobGroup));
footer.addComponents(btnStart, btnStop, btnUnfollow, btnReset);
return footer;
}

public JobGroup getJobGroup() {
return jobGroup;
}

public void setJobGroup(JobGroup jobGroup) {
this.jobGroup = jobGroup;
build();
}

public void setClickListener(JobGroupPanelButtonClickListener clickListener) {
this.clickListener = clickListener;
}

public interface JobGroupPanelButtonClickListener {

public void stopButtonClickOperations(JobGroup jobGroup);

public void unfollowButtonClickOperations(JobGroup jobGroup);

public void startButtonClickOperations(JobGroup jobGroup);

public void resetButtonClickOperations(JobGroup jobGroup);
}
}
81 changes: 5 additions & 76 deletions src/main/java/com/lbs/tedam/ui/components/TedamJobPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,21 @@
import com.lbs.tedam.localization.LocaleConstants;
import com.lbs.tedam.localization.TedamLocalizerWrapper;
import com.lbs.tedam.model.Job;
import com.lbs.tedam.ui.components.basic.TedamButton;
import com.lbs.tedam.ui.components.basic.TedamLabel;
import com.lbs.tedam.ui.components.basic.TedamPanel;
import com.lbs.tedam.ui.components.layout.TedamHorizontalLayout;
import com.lbs.tedam.ui.util.DateTimeFormatter;
import com.lbs.tedam.ui.util.TedamStatic;
import com.lbs.tedam.util.EnumsV2.CommandStatus;
import com.lbs.tedam.util.EnumsV2.JobStatus;
import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.Resource;
import com.vaadin.ui.ProgressBar;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;

@Component
@Scope("prototype")
public class TedamJobPanel extends TedamPanel implements TedamLocalizerWrapper {
public class TedamJobPanel extends AbstractManagerPanel implements TedamLocalizerWrapper {

/**
* long serialVersionUID
*/
private static final long serialVersionUID = 1L;

private final String JOB_PANEL_STYLE = ValoTheme.PANEL_WELL + " jobpanel";

private final DateTimeFormatter dateTimeFormetter;
private Job job;

private VerticalLayout mainLayout;
private TedamButton btnStart;
private TedamButton btnStop;
private TedamButton btnUnfollow;
private TedamButton btnReset;

private JobPanelButtonClickListener clickListener;

@Autowired
Expand All @@ -72,30 +53,13 @@ public void init() {
initUI();
}

private void initUI() {
setSizeUndefined();

mainLayout = new VerticalLayout();
setContent(mainLayout);
}

public void build() {
setStyleName(JOB_PANEL_STYLE);
private void build() {
setStyleName(PANEL_STYLE);
addStyleName(TedamStatic.getJobStatusColorMap().get(job.getStatus()).toString().toLowerCase());
setCaption(job.getId() + " - " + job.getName());
setIcon(VaadinIcons.FILE);
buildVerticalLayout(job);
buildButtons(job);

}

private void buildButtons(Job job) {
if (JobStatus.getInActiveJobStatus().contains(job.getStatus())) {
getBtnStart().setEnabled(true);
getBtnStop().setEnabled(false);
} else {
getBtnStart().setEnabled(false);
getBtnStop().setEnabled(true);
}
buildButtons(job.getStatus());
}

private void buildVerticalLayout(Job job) {
Expand All @@ -112,23 +76,9 @@ private void buildVerticalLayout(Job job) {
int completedJobDetailSize = (int) job.getJobDetails().stream().filter(jobDetail -> CommandStatus.COMPLETED.equals(jobDetail.getStatus())).count();
ProgressBar progressBar = buildProgressBar(completedJobDetailSize, job.getJobDetails().size());
TedamHorizontalLayout footer = buildFooter(job);

mainLayout.addComponents(environment, lastExecutingUser, progressBar, footer);
}

private ProgressBar buildProgressBar(int completedJobDetailSize, int allJobDetailSize) {
ProgressBar progressBar = new ProgressBar();
progressBar.setValue(((float) completedJobDetailSize / allJobDetailSize));
progressBar.setDescription(completedJobDetailSize + "/" + allJobDetailSize);
return progressBar;
}

private TedamLabel buildLabel(String parameter) {
TedamLabel label = new TedamLabel(parameter);
label.setStyleName(ValoTheme.LABEL_TINY);
return label;
}

private TedamHorizontalLayout buildFooter(Job job) {
TedamHorizontalLayout footer = new TedamHorizontalLayout();
footer.setStyleName("v-window-bottom-toolbar");
Expand All @@ -146,27 +96,6 @@ private TedamHorizontalLayout buildFooter(Job job) {
return footer;
}

private TedamButton buildButton(String id, String jobId, Resource icon) {
TedamButton button = new TedamButton(id, icon);
button.setId(button.getId() + jobId);
button.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
button.setWidthUndefined();
button.setCaption("");
return button;
}

public TedamButton getBtnStart() {
return btnStart;
}

public TedamButton getBtnStop() {
return btnStop;
}

public TedamButton getBtnUnfollow() {
return btnUnfollow;
}

public Job getJob() {
return job;
}
Expand Down
Loading

0 comments on commit 9ef38b1

Please sign in to comment.