Search in sources :

Example 1 with Appointment

use of jfxtras.scene.control.agenda.Agenda.Appointment in project phoebus by ControlSystemStudio.

the class LogEntryCalenderViewController method initialize.

@FXML
public void initialize() {
    resize.setText("<");
    agenda = new Agenda();
    agenda.setEditAppointmentCallback(new Callback<Agenda.Appointment, Void>() {

        @Override
        public Void call(Appointment appointment) {
            return null;
        }
    });
    agenda.setActionCallback((appointment) -> {
        // show detailed view
        try {
            if (map != null) {
                final Stage dialog = new Stage();
                dialog.initModality(Modality.NONE);
                logEntryControl = new LogEntryControl();
                logEntryControl.setLog(map.get(appointment));
                Scene dialogScene = new Scene(logEntryControl, 300, 200);
                dialog.setScene(dialogScene);
                dialog.show();
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "Failed to show details for : " + appointment.getSummary(), e);
        }
        return null;
    });
    agenda.allowDraggingProperty().set(false);
    agenda.allowResizeProperty().set(false);
    appointmentGroupMap = agenda.appointmentGroups().stream().collect(Collectors.toMap(AppointmentGroup::getDescription, Function.identity()));
    try {
        String styleSheetResource = LogbookUiPreferences.calendar_view_item_stylesheet;
        agenda.getStylesheets().add(this.getClass().getResource(styleSheetResource).toString());
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to set css style", e);
    }
    AnchorPane.setTopAnchor(agenda, 6.0);
    AnchorPane.setBottomAnchor(agenda, 6.0);
    AnchorPane.setLeftAnchor(agenda, 6.0);
    AnchorPane.setRightAnchor(agenda, 6.0);
    agendaPane.getChildren().add(agenda);
    searchParameters = FXCollections.<Keys, String>observableHashMap();
    searchParameters.put(Keys.SEARCH, "*");
    searchParameters.put(Keys.STARTTIME, TimeParser.format(java.time.Duration.ofHours(8)));
    searchParameters.put(Keys.ENDTIME, TimeParser.format(java.time.Duration.ZERO));
    advancedSearchViewController.setSearchParameters(searchParameters);
    searchParameters.addListener(new MapChangeListener<Keys, String>() {

        @Override
        public void onChanged(Change<? extends Keys, ? extends String> change) {
            Platform.runLater(() -> {
                query.setText(searchParameters.entrySet().stream().sorted(Map.Entry.comparingByKey()).map((e) -> {
                    return e.getKey().getName().trim() + "=" + e.getValue().trim();
                }).collect(Collectors.joining("&")));
            });
        }
    });
    query.setText(searchParameters.entrySet().stream().sorted(Map.Entry.comparingByKey()).map((e) -> {
        return e.getKey().getName().trim() + "=" + e.getValue().trim();
    }).collect(Collectors.joining("&")));
    VBox timeBox = new VBox();
    TimeRelativeIntervalPane timeSelectionPane = new TimeRelativeIntervalPane(TEMPORAL_AMOUNTS_AND_NOW);
    // TODO needs to be initialized from the values in the search parameters
    TimeRelativeInterval initial = TimeRelativeInterval.of(java.time.Duration.ofHours(8), java.time.Duration.ZERO);
    timeSelectionPane.setInterval(initial);
    HBox hbox = new HBox();
    hbox.setSpacing(5);
    hbox.setAlignment(Pos.CENTER_RIGHT);
    Button apply = new Button();
    apply.setText("Apply");
    apply.setPrefWidth(80);
    apply.setOnAction((event) -> {
        Platform.runLater(() -> {
            TimeRelativeInterval interval = timeSelectionPane.getInterval();
            if (interval.isStartAbsolute()) {
                searchParameters.put(Keys.STARTTIME, TimestampFormats.MILLI_FORMAT.format(interval.getAbsoluteStart().get()));
            } else {
                searchParameters.put(Keys.STARTTIME, TimeParser.format(interval.getRelativeStart().get()));
            }
            if (interval.isEndAbsolute()) {
                searchParameters.put(Keys.ENDTIME, TimestampFormats.MILLI_FORMAT.format(interval.getAbsoluteEnd().get()));
            } else {
                searchParameters.put(Keys.ENDTIME, TimeParser.format(interval.getRelativeEnd().get()));
            }
        });
    });
    Button cancel = new Button();
    cancel.setText("Cancel");
    cancel.setPrefWidth(80);
    hbox.getChildren().addAll(apply, cancel);
    timeBox.getChildren().addAll(timeSelectionPane, hbox);
    // Bind ENTER key press to search
    query.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
        if (event.getCode() == KeyCode.ENTER) {
            search();
        }
    });
}
Also used : Appointment(jfxtras.scene.control.agenda.Agenda.Appointment) AppointmentGroup(jfxtras.scene.control.agenda.Agenda.AppointmentGroup) Button(javafx.scene.control.Button) LogEntry(org.phoebus.logbook.LogEntry) Pos(javafx.geometry.Pos) Scene(javafx.scene.Scene) Arrays(java.util.Arrays) LocalDateTime(java.time.LocalDateTime) TimeRelativeIntervalPane(org.phoebus.ui.time.TimeRelativeIntervalPane) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) TimestampFormats(org.phoebus.util.time.TimestampFormats) VBox(javafx.scene.layout.VBox) Function(java.util.function.Function) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) Level(java.util.logging.Level) TimeParser(org.phoebus.util.time.TimeParser) TimeRelativeInterval(org.phoebus.util.time.TimeRelativeInterval) Map(java.util.Map) Agenda(jfxtras.scene.control.agenda.Agenda) KeyValue(javafx.animation.KeyValue) Callback(javafx.util.Callback) GridPane(javafx.scene.layout.GridPane) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) KeyFrame(javafx.animation.KeyFrame) TextField(javafx.scene.control.TextField) Modality(javafx.stage.Modality) MapChangeListener(javafx.collections.MapChangeListener) Timeline(javafx.animation.Timeline) KeyEvent(javafx.scene.input.KeyEvent) ObservableMap(javafx.collections.ObservableMap) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) Duration(javafx.util.Duration) Keys(org.phoebus.logbook.ui.LogbookQueryUtil.Keys) TreeMap(java.util.TreeMap) Stage(javafx.stage.Stage) AnchorPane(javafx.scene.layout.AnchorPane) Appointment(jfxtras.scene.control.agenda.Agenda.Appointment) LogClient(org.phoebus.logbook.LogClient) TEMPORAL_AMOUNTS_AND_NOW(org.phoebus.ui.time.TemporalAmountPane.Type.TEMPORAL_AMOUNTS_AND_NOW) AppointmentGroup(jfxtras.scene.control.agenda.Agenda.AppointmentGroup) TimeRelativeInterval(org.phoebus.util.time.TimeRelativeInterval) HBox(javafx.scene.layout.HBox) Agenda(jfxtras.scene.control.agenda.Agenda) Scene(javafx.scene.Scene) TimeRelativeIntervalPane(org.phoebus.ui.time.TimeRelativeIntervalPane) Button(javafx.scene.control.Button) Keys(org.phoebus.logbook.ui.LogbookQueryUtil.Keys) Stage(javafx.stage.Stage) VBox(javafx.scene.layout.VBox) FXML(javafx.fxml.FXML)

Example 2 with Appointment

use of jfxtras.scene.control.agenda.Agenda.Appointment in project phoebus by ControlSystemStudio.

the class LogEntryCalenderViewController method refresh.

private void refresh() {
    map = new HashMap<Appointment, LogEntry>();
    map = this.logEntries.stream().collect(Collectors.toMap(new Function<LogEntry, Appointment>() {

        @Override
        public Appointment apply(LogEntry logentry) {
            AppointmentImplLocal appointment = new Agenda.AppointmentImplLocal();
            appointment.withSummary(logentry.getDescription());
            appointment.withDescription(logentry.getDescription());
            appointment.withStartLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate(), ZoneId.systemDefault()));
            appointment.withEndLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate().plusSeconds(2400), ZoneId.systemDefault()));
            List<String> logbookNames = getLogbookNames();
            if (logbookNames != null && !logbookNames.isEmpty()) {
                int index = logbookNames.indexOf(logentry.getLogbooks().iterator().next().getName());
                if (index >= 0 && index <= 22) {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", (index + 1))));
                } else {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", 23)));
                }
            }
            return appointment;
        }
    }, new Function<LogEntry, LogEntry>() {

        @Override
        public LogEntry apply(LogEntry logentry) {
            return logentry;
        }
    }));
    agenda.appointments().clear();
    agenda.appointments().setAll(map.keySet());
}
Also used : Appointment(jfxtras.scene.control.agenda.Agenda.Appointment) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) Agenda(jfxtras.scene.control.agenda.Agenda) List(java.util.List) LogEntry(org.phoebus.logbook.LogEntry)

Example 3 with Appointment

use of jfxtras.scene.control.agenda.Agenda.Appointment in project phoebus by ControlSystemStudio.

the class LogEntryCalenderViewController method initialize.

@FXML
public void initialize() {
    configureComboBox();
    // Set the search parameters in the advanced search controller so that it operates on the same object.
    ologQueries.setAll(ologQueryManager.getQueries());
    searchParameters.addListener((observable, oldValue, newValue) -> {
        query.getEditor().setText(newValue);
    });
    agenda = new Agenda();
    agenda.setEditAppointmentCallback(new Callback<Agenda.Appointment, Void>() {

        @Override
        public Void call(Appointment appointment) {
            return null;
        }
    });
    agenda.setActionCallback((appointment) -> {
        // show detailed view
        try {
            if (map != null) {
                final Stage dialog = new Stage();
                dialog.initModality(Modality.NONE);
                ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
                FXMLLoader loader = new FXMLLoader();
                loader.setResources(resourceBundle);
                loader.setLocation(this.getClass().getResource("LogEntryDisplay.fxml"));
                loader.setControllerFactory(clazz -> {
                    try {
                        if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
                            return clazz.getConstructor(LogClient.class).newInstance(client);
                        } else if (clazz.isAssignableFrom(AttachmentsPreviewController.class)) {
                            return clazz.getConstructor().newInstance();
                        } else if (clazz.isAssignableFrom(LogEntryDisplayController.class)) {
                            return clazz.getConstructor(LogClient.class).newInstance(client);
                        } else if (clazz.isAssignableFrom(LogPropertiesController.class)) {
                            return clazz.getConstructor().newInstance();
                        }
                    } catch (Exception e) {
                        logger.log(Level.SEVERE, "Failed to construct controller for log entry display", e);
                    }
                    return null;
                });
                loader.load();
                LogEntryDisplayController controller = loader.getController();
                controller.setLogEntry(map.get(appointment));
                Scene dialogScene = new Scene(loader.getRoot(), 800, 600);
                dialog.setScene(dialogScene);
                dialog.show();
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "Failed to show details for : " + appointment.getSummary(), e);
        }
        return null;
    });
    agenda.allowDraggingProperty().set(false);
    agenda.allowResizeProperty().set(false);
    appointmentGroupMap = agenda.appointmentGroups().stream().collect(Collectors.toMap(AppointmentGroup::getDescription, Function.identity()));
    try {
        String styleSheetResource = LogbookUIPreferences.calendar_view_item_stylesheet;
        URL url = this.getClass().getResource(styleSheetResource);
        // url may be null...
        if (url != null) {
            agenda.getStylesheets().add(this.getClass().getResource(styleSheetResource).toString());
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to set css style", e);
    }
    AnchorPane.setTopAnchor(agenda, 6.0);
    AnchorPane.setBottomAnchor(agenda, 6.0);
    AnchorPane.setLeftAnchor(agenda, 6.0);
    AnchorPane.setRightAnchor(agenda, 6.0);
    agendaPane.getChildren().add(agenda);
    query.itemsProperty().bind(new SimpleObjectProperty<>(ologQueries));
    query.setOnKeyPressed(e -> {
        if (e.getCode() == KeyCode.ENTER) {
            // Query set -> search is triggered!
            query.setValue(new OlogQuery(query.getEditor().getText()));
        }
    });
    query.getEditor().setText(ologQueries.get(0).getQuery());
    // Query set -> search is triggered!
    query.getSelectionModel().select(ologQueries.get(0));
    resize.setText(">");
    search.disableProperty().bind(searchInProgress);
    search();
}
Also used : Appointment(jfxtras.scene.control.agenda.Agenda.Appointment) AppointmentGroup(jfxtras.scene.control.agenda.Agenda.AppointmentGroup) LogClient(org.phoebus.logbook.LogClient) Agenda(jfxtras.scene.control.agenda.Agenda) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) URL(java.net.URL) OlogQuery(org.phoebus.logbook.olog.ui.query.OlogQuery) Stage(javafx.stage.Stage) ResourceBundle(java.util.ResourceBundle) FXML(javafx.fxml.FXML)

Example 4 with Appointment

use of jfxtras.scene.control.agenda.Agenda.Appointment in project phoebus by ControlSystemStudio.

the class LogEntryCalenderViewController method refresh.

private void refresh() {
    map = new HashMap<Appointment, LogEntry>();
    map = this.logEntries.stream().collect(Collectors.toMap(new Function<LogEntry, Appointment>() {

        @Override
        public Appointment apply(LogEntry logentry) {
            AppointmentImplLocal appointment = new Agenda.AppointmentImplLocal();
            appointment.withSummary(logentry.getDescription());
            appointment.withDescription(logentry.getDescription());
            appointment.withStartLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate(), ZoneId.systemDefault()));
            appointment.withEndLocalDateTime(LocalDateTime.ofInstant(logentry.getCreatedDate().plusSeconds(2400), ZoneId.systemDefault()));
            List<String> logbookNames = getLogbookNames();
            if (logbookNames != null && !logbookNames.isEmpty()) {
                int index = logbookNames.indexOf(logentry.getLogbooks().iterator().next().getName());
                if (index >= 0 && index <= 22) {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", (index + 1))));
                } else {
                    appointment.setAppointmentGroup(appointmentGroupMap.get(String.format("group%02d", 23)));
                }
            }
            return appointment;
        }
    }, new Function<LogEntry, LogEntry>() {

        @Override
        public LogEntry apply(LogEntry logentry) {
            return logentry;
        }
    }));
    Platform.runLater(() -> {
        agenda.appointments().clear();
        agenda.appointments().setAll(map.keySet());
    });
}
Also used : Appointment(jfxtras.scene.control.agenda.Agenda.Appointment) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) AppointmentImplLocal(jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal) Agenda(jfxtras.scene.control.agenda.Agenda) List(java.util.List) ObservableList(javafx.collections.ObservableList) LogEntry(org.phoebus.logbook.LogEntry)

Aggregations

Agenda (jfxtras.scene.control.agenda.Agenda)4 Appointment (jfxtras.scene.control.agenda.Agenda.Appointment)4 List (java.util.List)3 AppointmentImplLocal (jfxtras.scene.control.agenda.Agenda.AppointmentImplLocal)3 LogEntry (org.phoebus.logbook.LogEntry)3 FXML (javafx.fxml.FXML)2 Scene (javafx.scene.Scene)2 Stage (javafx.stage.Stage)2 AppointmentGroup (jfxtras.scene.control.agenda.Agenda.AppointmentGroup)2 LogClient (org.phoebus.logbook.LogClient)2 URL (java.net.URL)1 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ResourceBundle (java.util.ResourceBundle)1 TreeMap (java.util.TreeMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Function (java.util.function.Function)1