Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trac#34252 Better editor guidance to fill a formular #396

Open
wants to merge 1 commit into
base: WollMux_18.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -608,4 +608,12 @@ public void updateFormUiValues(Map<String,Control> formControls)
setFormUiValue(ctrl.getId(), ctrl.getValue());
}
}

/**
* updates status of tab.
*/
public void checkTabIsOk()
{
formSidebarPanel.checkTabIsOk(formModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -94,10 +96,16 @@ public class FormSidebarPanel extends AbstractSidebarPanel implements XToolPanel
private XComponentContext context;
private XMultiComponentFactory xMCF;
private Map<Control, Short> buttons = new HashMap<>();
private Map<Short, String> buttons_nextTab = new HashMap<>();
private XTabPageContainer tabControlContainer;
private FormSidebarController formSidebarController;
private Map<String, Pair<XControl, XControl>> controls = new HashMap<>();
private boolean tabChanged = true;
private Map<Short, VerticalLayout> verticalLayoutPerTab = new HashMap<>();
private Map<Layout, String> 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.
Expand Down Expand Up @@ -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);
}
Expand All @@ -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++;
}

Expand Down Expand Up @@ -260,6 +270,7 @@ private void setControls(TabConfig tab, XControlContainer tabPageControlContaine
} else
{
layout.addLayout(controlLayout, 1);
Layout2ControlId.put(controlLayout, control.getId());
}
});
}
Expand Down Expand Up @@ -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());
}
}
}
}
Expand Down Expand Up @@ -620,7 +635,7 @@ public void dispose()
/**
* Activate the previous tab.
*/
public void previousTab()
public void previousTab(FormModel model)
{
if (tabChanged)
{
Expand All @@ -640,14 +655,15 @@ public void previousTab()
{
tabControlContainer.setActiveTabPageID(tabControlContainer.getTabPageCount());
}
checkTabIsOk(tabControlContainer.getActiveTabPageID(), model);
tabChanged = true;
}
}

/**
* Activate the next tab.
*/
public void nextTab()
public void nextTab(FormModel model)
{
if (tabChanged)
{
Expand All @@ -662,6 +678,7 @@ public void nextTab()
{
tabControlContainer.setActiveTabPageID(next);
}
checkTabIsOk(tabControlContainer.getActiveTabPageID(), model);
tabChanged = true;
}
}
Expand Down Expand Up @@ -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<Layout> 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());
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -157,6 +159,11 @@ public int getMinimalWidth(int maxWidth)
return width;
}

public List<Layout> getVisibleLayouts()
{
return layouts.stream().filter(e -> e.isVisible()).collect(Collectors.toList());
}

@Override
public int size()
{
Expand Down