Skip to content

Commit

Permalink
Now showing entry details in ResourcesView after entry creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Sep 16, 2022
1 parent b058247 commit e587158
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ protected Node wrap(Node node) {
outerPane.setStyle("-fx-padding: 20px;");

StackPane stackPane = new StackPane();
stackPane.setStyle(
"-fx-background-color: white; -fx-border-color: gray; -fx-border-width: .25px; -fx-padding: 20px;");
stackPane.setStyle("-fx-background-color: white; -fx-border-color: gray; -fx-border-width: .25px; -fx-padding: 20px;");
outerPane.getChildren().add(stackPane);

StackPane.setAlignment(node, Pos.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.calendarfx.model.Calendar.Style;
import com.calendarfx.view.DateControl;
import com.calendarfx.view.DayViewBase.AvailabilityEditingEntryBehaviour;
import com.calendarfx.view.DayViewBase.EarlyLateHoursStrategy;
import com.calendarfx.view.resources.Resource;
import com.calendarfx.view.resources.ResourcesView;
import javafx.scene.Node;
Expand Down Expand Up @@ -50,6 +51,11 @@ protected Class<?> getJavaDocClass() {
return ResourcesView.class;
}

@Override
protected boolean isSupportingDeveloperConsole() {
return false;
}

@Override
public Node getControlPanel() {
ToggleButton availabilityButton = new ToggleButton("Edit Schedule");
Expand Down Expand Up @@ -78,8 +84,8 @@ public Node getControlPanel() {
@Override
protected DateControl createControl() {
resourcesView = new ResourcesView();
resourcesView.setPrefHeight(800);
resourcesView.setPrefWidth(700);
resourcesView.setNumberOfDays(5);
resourcesView.setEarlyLateHoursStrategy(EarlyLateHoursStrategy.HIDE);
resourcesView.getResources().addAll(create("Dirk", Style.STYLE1), create("Katja", Style.STYLE2), create("Philip", Style.STYLE3), create("Jule", Style.STYLE4), create("Armin", Style.STYLE5));
return resourcesView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void createEntry(MouseEvent evt) {
Optional<Calendar> calendar = dateControl.getCalendarAt(evt.getX(), evt.getY());
if (time != null) {
Entry<?> entry = dateControl.createEntryAt(time, calendar.orElse(null));
if (dateControl.isShowDetailsUponCreation()) {
if (dateControl.isShowDetailsUponEntryCreation()) {
dateControl.fireEvent(new RequestEvent(dateControl, dateControl, entry));
}
}
Expand Down
24 changes: 12 additions & 12 deletions CalendarFXView/src/main/java/com/calendarfx/view/DateControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2564,10 +2564,10 @@ public final void setAvailabilityFill(Paint availabilityFill) {
this.availabilityFill.set(availabilityFill);
}

private final BooleanProperty showDetailsUponCreation = new SimpleBooleanProperty(this, "showDetailsUponCreation", true);
private final BooleanProperty showDetailsUponEntryCreation = new SimpleBooleanProperty(this, "showDetailsUponEntryCreation", true);

public final boolean isShowDetailsUponCreation() {
return showDetailsUponCreation.get();
public final boolean isShowDetailsUponEntryCreation() {
return showDetailsUponEntryCreation.get();
}

/**
Expand All @@ -2576,12 +2576,12 @@ public final boolean isShowDetailsUponCreation() {
*
* @return true if the date control shows a dialog immediately after a new entry was added by the user
*/
public final BooleanProperty showDetailsUponCreationProperty() {
return showDetailsUponCreation;
public final BooleanProperty showDetailsUponEntryCreationProperty() {
return showDetailsUponEntryCreation;
}

public final void setShowDetailsUponCreation(boolean showDetailsUponCreation) {
this.showDetailsUponCreation.set(showDetailsUponCreation);
public final void setShowDetailsUponEntryCreation(boolean showDetailsUponEntryCreation) {
this.showDetailsUponEntryCreation.set(showDetailsUponEntryCreation);
}

/**
Expand Down Expand Up @@ -2632,7 +2632,7 @@ public final void bind(DateControl otherControl, boolean bindDate) {
Bindings.bindBidirectional(otherControl.usagePolicyProperty(), usagePolicyProperty());
Bindings.bindBidirectional(otherControl.availableZoneIdsProperty(), availableZoneIdsProperty());
Bindings.bindBidirectional(otherControl.enableTimeZoneSupportProperty(), enableTimeZoneSupportProperty());
Bindings.bindBidirectional(otherControl.showDetailsUponCreationProperty(), showDetailsUponCreationProperty());
Bindings.bindBidirectional(otherControl.showDetailsUponEntryCreationProperty(), showDetailsUponEntryCreationProperty());
Bindings.bindBidirectional(otherControl.showNoonMarkerProperty(), showNoonMarkerProperty());
Bindings.bindBidirectional(otherControl.showTodayProperty(), showTodayProperty());

Expand Down Expand Up @@ -2702,7 +2702,7 @@ public final void unbind(DateControl otherControl) {
Bindings.unbindBidirectional(otherControl.availabilityCalendarProperty(), availabilityCalendarProperty());
Bindings.unbindBidirectional(otherControl.availabilityGridProperty(), availabilityGridProperty());
Bindings.unbindBidirectional(otherControl.availabilityFillProperty(), availabilityFillProperty());
Bindings.unbindBidirectional(otherControl.showDetailsUponCreationProperty(), showDetailsUponCreationProperty());
Bindings.unbindBidirectional(otherControl.showDetailsUponEntryCreationProperty(), showDetailsUponEntryCreationProperty());
Bindings.unbindBidirectional(otherControl.showNoonMarkerProperty(), showNoonMarkerProperty());
Bindings.unbindBidirectional(otherControl.showTodayProperty(), showTodayProperty());

Expand Down Expand Up @@ -3458,17 +3458,17 @@ public String getCategory() {

@Override
public Optional<ObservableValue<?>> getObservableValue() {
return Optional.of(showDetailsUponCreationProperty());
return Optional.of(showDetailsUponEntryCreationProperty());
}

@Override
public void setValue(Object value) {
setShowDetailsUponCreation((boolean) value);
setShowDetailsUponEntryCreation((boolean) value);
}

@Override
public Object getValue() {
return isShowDetailsUponCreation();
return isShowDetailsUponEntryCreation();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ public final void setOnLassoFinished(BiConsumer<Instant, Instant> onLassoFinishe
this.onLassoFinished.set(onLassoFinished);
}

private final ObjectProperty<Paint> lassoColor = new SimpleObjectProperty<>(this, "lassoColor", Color.ALICEBLUE);
private final ObjectProperty<Paint> lassoColor = new SimpleObjectProperty<>(this, "lassoColor", Color.GREY);

public final Paint getLassoColor() {
return lassoColor.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.calendarfx.view.CalendarHeaderView;
import com.calendarfx.view.DayView;
import com.calendarfx.view.DayViewBase;
import com.calendarfx.view.RequestEvent;
import com.calendarfx.view.TimeScaleView;
import com.calendarfx.view.WeekDayHeaderView;
import com.calendarfx.view.WeekView;
Expand All @@ -41,6 +42,10 @@
import javafx.scene.layout.Region;
import javafx.util.Callback;

import java.util.function.Consumer;

import static com.calendarfx.view.RequestEvent.REQUEST_ENTRY;

/**
* The detailed day view is a composite control consisting of a {@link DayView},
* an {@link AllDayView}, an {@link CalendarHeaderView}, and a
Expand All @@ -63,6 +68,15 @@ public class ResourcesView<T extends Resource<?>> extends DayViewBase {
public ResourcesView() {
getStyleClass().add(DEFAULT_STYLE);
setShowToday(false);

addEventHandler(REQUEST_ENTRY, evt -> maybeRunAndConsume(evt, e -> editEntry(evt.getEntry())));
}

private void maybeRunAndConsume(RequestEvent evt, Consumer<RequestEvent> runnable) {
if (!evt.isConsumed()) {
runnable.accept(evt);
evt.consume();
}
}

@Override
Expand Down Expand Up @@ -273,7 +287,11 @@ public final boolean isShowScrollBar() {
return showScrollBar.get();
}

private final ObjectProperty<Callback<T, WeekView>> weekViewFactory = new SimpleObjectProperty<>(this, "weekViewFactory", resource -> new WeekView());
private final ObjectProperty<Callback<T, WeekView>> weekViewFactory = new SimpleObjectProperty<>(this, "weekViewFactory", resource -> {
WeekView view = new WeekView();
view.setAdjustToFirstDayOfWeek(false);
return view;
});

public final Callback<T, WeekView> getWeekViewFactory() {
return weekViewFactory.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.calendarfx.view.CalendarView.Page;
import com.calendarfx.view.DeveloperConsole;
import com.calendarfx.view.Messages;
import com.calendarfx.view.RequestEvent;
import com.calendarfx.view.SearchResultView;
import com.calendarfx.view.SourceView;
import com.calendarfx.view.YearMonthView;
Expand Down Expand Up @@ -65,6 +66,7 @@
import org.kordamp.ikonli.javafx.FontIcon;

import java.time.ZoneId;
import java.util.function.Consumer;

import static com.calendarfx.view.CalendarView.Page.DAY;
import static com.calendarfx.view.CalendarView.Page.MONTH;
Expand Down Expand Up @@ -113,12 +115,12 @@ public CalendarViewSkin(CalendarView view) {
});
}

view.addEventHandler(REQUEST_DATE, evt -> view.showDate(evt.getDate()));
view.addEventHandler(REQUEST_DATE_TIME, evt -> view.showDateTime(evt.getDateTime()));
view.addEventHandler(REQUEST_WEEK, evt -> view.showWeek(evt.getYear(), evt.getWeekOfYear()));
view.addEventHandler(REQUEST_YEAR_MONTH, evt -> view.showYearMonth(evt.getYearMonth()));
view.addEventHandler(REQUEST_YEAR, evt -> view.showYear(evt.getYear()));
view.addEventHandler(REQUEST_ENTRY, evt -> view.getSelectedPageView().editEntry(evt.getEntry()));
view.addEventHandler(REQUEST_DATE, evt -> maybeRunAndConsume(evt, e -> view.showDate(evt.getDate())));
view.addEventHandler(REQUEST_DATE_TIME, evt -> maybeRunAndConsume(evt, e -> view.showDateTime(evt.getDateTime())));
view.addEventHandler(REQUEST_WEEK, evt -> maybeRunAndConsume(evt, e -> view.showWeek(evt.getYear(), evt.getWeekOfYear())));
view.addEventHandler(REQUEST_YEAR_MONTH, evt -> maybeRunAndConsume(evt, e -> view.showYearMonth(evt.getYearMonth())));
view.addEventHandler(REQUEST_YEAR, evt -> maybeRunAndConsume(evt, e -> view.showYear(evt.getYear())));
view.addEventHandler(REQUEST_ENTRY, evt -> maybeRunAndConsume(evt, e -> view.getSelectedPageView().editEntry(evt.getEntry())));

view.getAvailablePages().addListener((Observable it) -> buildSwitcher());

Expand Down Expand Up @@ -344,6 +346,13 @@ public CalendarViewSkin(CalendarView view) {
updateToggleButtons();
}

private void maybeRunAndConsume(RequestEvent evt, Consumer<RequestEvent> runnable) {
if (!evt.isConsumed()) {
runnable.accept(evt);
evt.consume();
}
}

private void openTray() {
leftMasterDetailPane.resetDividerPosition();
leftMasterDetailPane.setShowDetailNode(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private void mouseReleased(MouseEvent evt) {
if (draggedEntry != null) {
entry.setInterval(draggedEntry.getInterval());
dayViewBase.setDraggedEntry(null);
if (dayViewBase.isShowDetailsUponCreation() && showEntryDetails) {
if (dayViewBase.isShowDetailsUponEntryCreation() && showEntryDetails) {
dayViewBase.fireEvent(new RequestEvent(dayViewBase, dayViewBase, entry));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class WeekViewSkin extends SkinBase<WeekView> {
public WeekViewSkin(WeekView view) {
super(view);


final InvalidationListener rebuildListener = it -> buildDays();
view.numberOfDaysProperty().addListener(rebuildListener);
view.adjustToFirstDayOfWeekProperty().addListener(rebuildListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ private void updateView() {

if (view.isShowAllDayView()) {
AllDayView allDayView = new AllDayView();
allDayView.setAdjustToFirstDayOfWeek(false);

// bind AllDayView
view.bind(allDayView, true);
allDayView.numberOfDaysProperty().bind(view.numberOfDaysProperty());

// some unbindings for AllDayView
Bindings.unbindBidirectional(view.defaultCalendarProviderProperty(), allDayView.defaultCalendarProviderProperty());
Bindings.unbindBidirectional(view.draggedEntryProperty(), allDayView.draggedEntryProperty());
Bindings.unbindContentBidirectional(view.getCalendarSources(), allDayView.getCalendarSources());

allDayView.setNumberOfDays(1);
CalendarSource calendarSource = createCalendarSource(resource);
allDayView.getCalendarSources().setAll(calendarSource);
allDayView.setDefaultCalendarProvider(control -> calendarSource.getCalendars().get(0));
Expand All @@ -154,6 +158,7 @@ private void updateView() {
HBox.setHgrow(resourceHeader, Priority.ALWAYS);

WeekDayHeaderView weekDayHeaderView = view.getWeekDayHeaderViewFactory().call(resource);
weekDayHeaderView.setAdjustToFirstDayOfWeek(false);
weekDayHeaderView.numberOfDaysProperty().bind(view.numberOfDaysProperty());
view.bind(weekDayHeaderView, true);

Expand Down

0 comments on commit e587158

Please sign in to comment.