diff --git a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/model/FormModel.java b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/model/FormModel.java index f2245d30b..4c417a5e7 100644 --- a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/model/FormModel.java +++ b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/model/FormModel.java @@ -290,15 +290,17 @@ public void setValue(final String id, final String value) } modifiedGroups.forEach(g -> g.computeVisibility(newValues)); - for (VisibilityGroup g : modifiedGroups) - { - if (txtDocController != null && formSidebarController != null) { - //update vis. in doc - txtDocController.setVisibilityChanged(g.getGroupId(), g.isVisible()); - //update vis in form-ui - formSidebarController.visibilityChanged(g.getGroupId()); - } + for (VisibilityGroup g : modifiedGroups) + { + if (txtDocController != null && formSidebarController != null) { + //update vis. in doc + txtDocController.setVisibilityChanged(g.getGroupId(), g.isVisible()); + //update vis in form-ui + formSidebarController.visibilityChanged(g.getGroupId()); } + } + + formSidebarController.checkTabIsOk(); } } diff --git a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java index 69488b4fd..1bc14917b 100644 --- a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java +++ b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarController.java @@ -458,10 +458,10 @@ public void buttonPressed(ActionEvent actionEvent) formController.close(); break; case "nextTab": - formSidebarPanel.nextTab(); + formSidebarPanel.nextTab(formModel); break; case "prevTab": - formSidebarPanel.previousTab(); + formSidebarPanel.previousTab(formModel); break; case "funcDialog": String dialogName = formControl.getDialog(); @@ -608,4 +608,12 @@ public void updateFormUiValues(Map formControls) setFormUiValue(ctrl.getId(), ctrl.getValue()); } } + + /** + * updates status of tab. + */ + public void checkTabIsOk() + { + formSidebarPanel.checkTabIsOk(formModel); + } } diff --git a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarPanel.java b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarPanel.java index 2dcaa72d1..9d00a351e 100644 --- a/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarPanel.java +++ b/core/src/main/java/de/muenchen/allg/itd51/wollmux/form/sidebar/FormSidebarPanel.java @@ -50,7 +50,8 @@ import com.sun.star.awt.XWindowPeer; import com.sun.star.awt.tab.XTabPage; import com.sun.star.awt.tab.XTabPageContainer; -import com.sun.star.lang.EventObject; +import com.sun.star.awt.tab.XTabPageModel; +import com.sun.star.deployment.PackageInformationProvider; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.ui.LayoutSize; import com.sun.star.ui.XSidebarPanel; @@ -78,6 +79,7 @@ import de.muenchen.allg.itd51.wollmux.ui.layout.Layout; import de.muenchen.allg.itd51.wollmux.ui.layout.TabLayout; import de.muenchen.allg.itd51.wollmux.ui.layout.VerticalLayout; +import de.muenchen.allg.itd51.wollmux.util.Utils; import de.muenchen.allg.util.UnoConfiguration; import de.muenchen.allg.util.UnoProperty; @@ -94,10 +96,16 @@ public class FormSidebarPanel extends AbstractSidebarPanel implements XToolPanel private XComponentContext context; private XMultiComponentFactory xMCF; private Map buttons = new HashMap<>(); + private Map buttons_nextTab = new HashMap<>(); private XTabPageContainer tabControlContainer; private FormSidebarController formSidebarController; private Map> controls = new HashMap<>(); private boolean tabChanged = true; + private Map verticalLayoutPerTab = new HashMap<>(); + private Map Layout2ControlId = new HashMap<>(); + + private static final String IMAGE_LOCATION = PackageInformationProvider.get(UNO.defaultContext) + .getPackageLocation(Utils.getWollMuxProperties().getProperty("extension.id")) + "/image/"; /** * Creates a new form panel. @@ -192,12 +200,12 @@ public void createTabControl(FormConfig config, FormModel model) element.getText(), tabId, 1000); XTabPage xTabPage = tabControlContainer.getTabPageByID(tabId); XControlContainer tabPageControlContainer = UNO.XControlContainer(xTabPage); - Layout controlsVLayout = new VerticalLayout(5, 5, 0, 15, 6); + VerticalLayout controlsVLayout = new VerticalLayout(5, 5, 0, 15, 6); if (i > 0) { addTabSwitcher("backward", tabs.get(i - 1), s -> { - previousTab(); + previousTab(model); s.reduce((f, se) -> se).ifPresent(XWindow::setFocus); }, tabPageControlContainer, controlsVLayout); } @@ -207,14 +215,16 @@ public void createTabControl(FormConfig config, FormModel model) if (i < tabs.size() - 1) { addTabSwitcher("forward", tabs.get(i + 1), s -> { - nextTab(); + nextTab(model); s.findFirst().ifPresent(XWindow::setFocus); }, tabPageControlContainer, controlsVLayout); } tabLayouts.add(controlsVLayout); addButtonsToLayout(tab, model, controlContainer, buttonLayout, tabId); + verticalLayoutPerTab.put(tabId, controlsVLayout); + checkTabIsOk(tabId, model); tabId++; } @@ -260,6 +270,7 @@ private void setControls(TabConfig tab, XControlContainer tabPageControlContaine } else { layout.addLayout(controlLayout, 1); + Layout2ControlId.put(controlLayout, control.getId()); } }); } @@ -347,6 +358,10 @@ private void addButtonsToLayout(TabConfig tab, FormModel model, XControlContaine { buttons.put(model.getControl(control.getId()), tabId); tabButtonLayout.addLayout(controlLayout, 1); + if(control.getAction().equals("nextTab")) + { + buttons_nextTab.put(tabId, control.getId()); + } } } } @@ -620,7 +635,7 @@ public void dispose() /** * Activate the previous tab. */ - public void previousTab() + public void previousTab(FormModel model) { if (tabChanged) { @@ -640,6 +655,7 @@ public void previousTab() { tabControlContainer.setActiveTabPageID(tabControlContainer.getTabPageCount()); } + checkTabIsOk(tabControlContainer.getActiveTabPageID(), model); tabChanged = true; } } @@ -647,7 +663,7 @@ public void previousTab() /** * Activate the next tab. */ - public void nextTab() + public void nextTab(FormModel model) { if (tabChanged) { @@ -662,6 +678,7 @@ public void nextTab() { tabControlContainer.setActiveTabPageID(next); } + checkTabIsOk(tabControlContainer.getActiveTabPageID(), model); tabChanged = true; } } @@ -727,4 +744,55 @@ public void setBackgroundColor(String id, boolean okay, int color, boolean init) LOGGER.debug("", e); } } + + public void checkTabIsOk(FormModel model) + { + if (tabControlContainer != null) + { + checkTabIsOk(tabControlContainer.getActiveTabPageID(), model); + } + } + + public void checkTabIsOk(short tab, FormModel model) + { + if (tabControlContainer != null) + { + VerticalLayout controlsVLayout = verticalLayoutPerTab.get(tab); + List visibleLayouts = controlsVLayout.getVisibleLayouts(); + XTabPageModel pageModel = UNO.XTabPageModel(UNO.XControl(tabControlContainer.getTabPageByID(tab)).getModel()); + if(pageModel==null) + return; + + boolean isOkay = true; + for (Layout l : visibleLayouts) + { + if(Layout2ControlId.containsKey(l)) + { + String controlId = Layout2ControlId.get(l); + Control ctrl = model.getControl(controlId); + if(!ctrl.isOkay()) + isOkay = false; + } + } + if(isOkay) + { + pageModel.setImageURL(IMAGE_LOCATION + "if.png"); + } + else + { + pageModel.setImageURL(IMAGE_LOCATION + "red.png"); + } + if(buttons_nextTab.containsKey(tab)) + { + String buttonId = buttons_nextTab.get(tab); + XWindow window = UNO.XWindow(controls.get(buttonId).getRight()); + Control ctrl = model.getControl(buttonId); + if (window != null) + { + window.setEnable(isOkay && ctrl.isOkay()); + } + } + } + + } } diff --git a/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/GuiFactory.java b/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/GuiFactory.java index 19feddd4c..f3efa1a32 100644 --- a/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/GuiFactory.java +++ b/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/GuiFactory.java @@ -130,7 +130,8 @@ public static XControl createTextfield(XMultiComponentFactory xMCF, XComponentCo XControl buttonCtrl = createControl(xMCF, context, UnoComponent.CSS_AWT_UNO_CONTROL_EDIT, props, size); XTextComponent txt = UNO.XTextComponent(buttonCtrl); - txt.addTextListener(textListener); + if(textListener!=null) + txt.addTextListener(textListener); txt.setText(text); return buttonCtrl; } @@ -353,7 +354,7 @@ public static void createTab(XMultiComponentFactory xMCF, XComponentContext cont String tabTitle, short tabId, int scrollHeight) { XTabPageModel tabPageModel = model.createTabPage(tabId); // 0 is not valid - tabPageModel.setTitle(tabTitle); + tabPageModel.setTitle(tabId + ". " + tabTitle); if (scrollHeight > 0) { try diff --git a/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/layout/VerticalLayout.java b/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/layout/VerticalLayout.java index 8ed1917ac..208a0d3c3 100644 --- a/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/layout/VerticalLayout.java +++ b/core/src/main/java/de/muenchen/allg/itd51/wollmux/ui/layout/VerticalLayout.java @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import org.apache.commons.lang3.tuple.Pair; @@ -157,6 +159,11 @@ public int getMinimalWidth(int maxWidth) return width; } + public List getVisibleLayouts() + { + return layouts.stream().filter(e -> e.isVisible()).collect(Collectors.toList()); + } + @Override public int size() {