Skip to content

Commit

Permalink
Merge pull request #358 from bjoernranft/insertvalue-visibility
Browse files Browse the repository at this point in the history
Insertvalue visibility
  • Loading branch information
bjoernranft authored Oct 14, 2021
2 parents 2c6ab31 + acbc3a7 commit 5b144eb
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.sun.star.text.XTextDocument;

import de.muenchen.allg.afid.UnoProps;
import de.muenchen.allg.itd51.wollmux.SyncActionListener;
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
import de.muenchen.allg.itd51.wollmux.document.TextDocumentController;
import de.muenchen.allg.itd51.wollmux.document.TextDocumentModel;
Expand Down Expand Up @@ -80,7 +81,9 @@ public void removePrintFunction(String functionName)
@Override
public void setFormValue(String id, String value)
{
new OnSetFormValue(doc, id, value, null).emit();
SyncActionListener s = new SyncActionListener();
new OnSetFormValue(doc, id, value, s).emit();
s.synchronize();
}

@Override
Expand Down Expand Up @@ -125,7 +128,9 @@ public void updateInsertFields()
{
Map<String, String> m = new HashMap<>(mapDbSpalteToValue);
mapDbSpalteToValue.clear();
new OnSetInsertValues(doc, m, null).emit();
SyncActionListener s = new SyncActionListener();
new OnSetInsertValues(doc, m, s).emit();
s.synchronize();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ public TextDocumentModel(XTextDocument doc, PersistentDataContainer persistentDa
// parse document commands without changing modified state
boolean modified = isDocumentModified();
this.documentCommands = new DocumentCommands(UNO.XBookmarksSupplier(doc));
documentCommands.update();
setDocumentModified(modified);

// read persistent data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ public int executeCommand(DocumentCommand.InsertValue cmd)
}
else
{
XTextCursor cursor = cmd.getTextCursor();
String text = cmd.getLeftSeparator() + value + cmd.getRightSeparator();
cmd.getAnchor().getStart().setString(text);
cursor.setString("");
cmd.setTextRangeString(cmd.getLeftSeparator() + value
+ cmd.getRightSeparator());
}

cmd.markDone(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ public OnExecutePrintFunction(TextDocumentController documentController)
protected void doit() throws WollMuxFehlerException
{
final XPrintModel pmod = PrintModels.createPrintModel(documentController, true);
pmod.printWithProps();
new Thread()
{
@Override
public void run()
{
pmod.printWithProps();
}
}.start();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ public boolean equals(Object obj)
return Objects.equals(functionName, other.functionName) && order == other.order;
}

/**
* Execute this print function in a separate thread.
*
* @param printModel
* The {@link XPrintModel} to print.
* @return The separate thread.
*/
public Thread printAsync(XPrintModel printModel)
{
Thread t = new Thread(() -> {
try
{
print(printModel);
} catch (Exception ex)
{
LOGGER.error("Fehler beim Drucken", ex);
}
});
t.start();
return t;
}

/**
* Do the purpose of this print function.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
/**
* Configures and performs a mail merge.
*/
public class MailMergeRunner
public class MailMergeRunner implements Runnable
{
private static final Logger LOGGER = LoggerFactory.getLogger(MailMergeRunner.class);

Expand Down Expand Up @@ -87,7 +87,7 @@ public MailMergeRunner(TextDocumentController documentController, DatasourceMode
setProperties(settings);
}


@Override
public void run()
{
if (pmod.isCanceled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public void startWizard()
{
try
{
MailMergeRunner runner = new MailMergeRunner(textDocumentController, model, settings);
runner.run();
new Thread(new MailMergeRunner(textDocumentController, model, settings))
.start();
} catch (NoTableSelectedException e)
{
InfoDialog.showInfoModal("Seriendruck fehlgeschlagen", e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import de.muenchen.allg.itd51.wollmux.event.handlers.OnCollectNonWollMuxFormFieldsViaPrintModel;
import de.muenchen.allg.itd51.wollmux.event.handlers.OnSetFormValue;
import de.muenchen.allg.itd51.wollmux.event.handlers.OnSetVisibleState;
import de.muenchen.allg.itd51.wollmux.func.print.PrintException;
import de.muenchen.allg.itd51.wollmux.func.print.PrintFunction;
import de.muenchen.allg.itd51.wollmux.interfaces.XPrintModel;
import de.muenchen.allg.itd51.wollmux.print.PageRange.PageRangeType;
Expand Down Expand Up @@ -103,7 +102,7 @@ class MasterPrintModel implements XPrintModel
/**
* Flag indicating cancellation of print.
*/
private boolean isCanceled;
private boolean[] isCanceled = new boolean[] { false };

/**
* Dialog for showing the print progress.
Expand Down Expand Up @@ -177,23 +176,33 @@ public void print(short numberOfCopies)
@Override
public void printWithProps()
{
if (isCanceled())
return;

PrintFunction f = getPrintFunction(0);
if (f != null)
{
XPrintModel pmod = new SlavePrintModel(this, 0);
Thread t = f.printAsync(pmod);
try
{
f.print(pmod);
} catch (PrintException e)
t.join();
} catch (InterruptedException e)
{
PrintModels.LOGGER.error("", e);
Thread.currentThread().interrupt();
}

} else
{
setProperty(PROP_FINAL_SHOW_COPIES_SPINNER, Boolean.TRUE);
setPropertySynchronized(PROP_FINAL_SHOW_COPIES_SPINNER, Boolean.TRUE);
finalPrint();
}

if (printProgressBar != null)
{
printProgressBar.dispose();
printProgressBar = null;
}
}

/**
Expand All @@ -218,9 +227,9 @@ protected void finalPrint()
return;
}

setProperty(PROP_FINAL_COPY_COUNT, ppd.getKey());
setProperty(PROP_FINAL_PAGE_RANGE, ppd.getValue());
setProperty(PROP_FINAL_NO_PARAMS_DIALOG, Boolean.TRUE);
setPropertySynchronized(PROP_FINAL_COPY_COUNT, ppd.getKey());
setPropertySynchronized(PROP_FINAL_PAGE_RANGE, ppd.getValue());
setPropertySynchronized(PROP_FINAL_NO_PARAMS_DIALOG, Boolean.TRUE);
}

Short copyCount = (Short) getProperty(PROP_FINAL_COPY_COUNT);
Expand Down Expand Up @@ -287,9 +296,12 @@ private boolean print(PageRange pr, Short copyCount)
return false;
}

private void setProperty(String prop, Object o)
private void setPropertySynchronized(String prop, Object o)
{
props.put(prop, o);
synchronized (props)
{
props.put(prop, o);
}
}

public void setStage(String stage)
Expand All @@ -299,13 +311,18 @@ public void setStage(String stage)

private Object getProperty(String prop)
{
synchronized (props)
{
return props.get(prop);
}
}

@Override
public void setFormValue(String id, String value)
{
new OnSetFormValue(documentController.getModel().doc, id, value, null).emit();
SyncActionListener s = new SyncActionListener();
new OnSetFormValue(documentController.getModel().doc, id, value, s).emit();
s.synchronize();
}

@Override
Expand All @@ -323,16 +340,19 @@ public void setDocumentModified(boolean modified)
@Override
public void collectNonWollMuxFormFields()
{
new OnCollectNonWollMuxFormFieldsViaPrintModel(documentController, null).emit();
SyncActionListener s = new SyncActionListener();
new OnCollectNonWollMuxFormFieldsViaPrintModel(documentController, s).emit();
s.synchronize();
}

@Override
public XPropertySetInfo getPropertySetInfo()
{
final HashSet<String> propsKeySet;

synchronized (props)
{
propsKeySet = new HashSet<>(props.keySet());

}

return new XPropertySetInfo()
{
Expand Down Expand Up @@ -375,7 +395,7 @@ public Property[] getProperties()
public void setPropertyValue(String arg0, Object arg1)
throws UnknownPropertyException, PropertyVetoException, WrappedTargetException
{
setProperty(arg0, arg1);
setPropertySynchronized(arg0, arg1);
}

@Override
Expand Down Expand Up @@ -431,25 +451,35 @@ public void removeVetoableChangeListener(String arg0, XVetoableChangeListener ar
@Override
public void setPrintBlocksProps(String blockName, boolean visible, boolean showHighlightColor)
{
new OnSetPrintBlocksPropsViaPrintModel(documentController, blockName, visible, showHighlightColor, null).emit();
SyncActionListener s = new SyncActionListener();
new OnSetPrintBlocksPropsViaPrintModel(documentController, blockName, visible, showHighlightColor, s).emit();
s.synchronize();
}

@Override
public void setGroupVisible(String groupID, boolean visible)
{
new OnSetVisibleState(documentController, groupID, visible, null).emit();
SyncActionListener s = new SyncActionListener();
new OnSetVisibleState(documentController, groupID, visible, s).emit();
s.synchronize();
}

@Override
public boolean isCanceled()
{
return isCanceled;
synchronized (isCanceled)
{
return isCanceled[0];
}
}

@Override
public void cancel()
{
isCanceled = true;
synchronized (isCanceled)
{
isCanceled[0] = true;
}
}

@Override
Expand Down Expand Up @@ -494,18 +524,8 @@ void setPrintProgressMaxValue(Object key, short maxValue)
*/
void setPrintProgressValue(Object key, short value)
{
if (printProgressBar == null)
{
return;
}

printProgressBar.setValue(key, value);

if (printProgressBar.getMaxValue().get(key) == value)
{
printProgressBar.dispose();
printProgressBar = null;
}
if (printProgressBar != null)
printProgressBar.setValue(key, value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public void setMaxValue(Object key, int maxValue)
currentValues.put(key, 0);
}
}

refresh();
}

/**
Expand Down Expand Up @@ -247,16 +249,11 @@ public void setValue(Object key, int value)
currentValues.put(key, value);
refresh();
}

public HashMap<Object, Integer> getMaxValue()
{
return maxValues;
}

/**
* Update the progress bar and the message in the dialog.
*/
public void refresh()
private void refresh()
{
int allMax = 1;
int allCurrent = 0;
Expand Down Expand Up @@ -288,11 +285,6 @@ else if (showfms)
fromMaxString.append(")");
}

if (progressBar == null)
{
return;
}

progressBar.setRange(0, allMax);
progressBar.setValue(allCurrent);
statusLabel.setText(L.m(" %1 von %2%3 Schritten", allCurrent, allMax, fromMaxString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void print(XPrintModel printModel)
picker.appendFilter(filterName, "*.pdf");
picker.appendFilter("Alle Dateien", "*");
picker.setCurrentFilter(filterName);
short res = picker.execute(); // thread gets disposed when running in debug mode, no issues with built oxt.
short res = picker.execute();
if (res == com.sun.star.ui.dialogs.ExecutableDialogResults.OK)
{
String[] files = picker.getFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.sun.star.text.XTextDocument;

import de.muenchen.allg.itd51.wollmux.GlobalFunctions;
import de.muenchen.allg.itd51.wollmux.func.print.PrintException;
import de.muenchen.allg.itd51.wollmux.func.print.PrintFunction;
import de.muenchen.allg.itd51.wollmux.interfaces.XPrintModel;
import de.muenchen.allg.itd51.wollmux.util.L;
Expand Down Expand Up @@ -95,14 +94,15 @@ public void printWithProps()
if (f != null)
{
XPrintModel pmod = new SlavePrintModel(master, idx + 1);
Thread t = f.printAsync(pmod);
try
{
f.print(pmod);
} catch (PrintException e)
t.join();
} catch (InterruptedException e)
{
PrintModels.LOGGER.error("", e);
Thread.currentThread().interrupt();
}

master.setPrintProgressMaxValue(pmod, (short) 0);
} else
{
Expand Down

0 comments on commit 5b144eb

Please sign in to comment.