-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trac#18139 Importieren von Formularinhalten
- Loading branch information
Showing
8 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
core/src/main/java/de/muenchen/allg/itd51/wollmux/dispatch/ImportFormularinhaltDispatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*- | ||
* #%L | ||
* WollMux | ||
* %% | ||
* Copyright (C) 2005 - 2020 Landeshauptstadt München | ||
* %% | ||
* Licensed under the EUPL, Version 1.1 or – as soon they will be | ||
* approved by the European Commission - subsequent versions of the | ||
* EUPL (the "Licence"); | ||
* | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl5 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
* #L% | ||
*/ | ||
package de.muenchen.allg.itd51.wollmux.dispatch; | ||
|
||
import com.sun.star.beans.PropertyValue; | ||
import com.sun.star.frame.XDispatch; | ||
import com.sun.star.frame.XFrame; | ||
import com.sun.star.util.URL; | ||
|
||
import de.muenchen.allg.itd51.wollmux.document.DocumentManager; | ||
import de.muenchen.allg.itd51.wollmux.event.handlers.OnImportFormularinhalt; | ||
|
||
/** | ||
* Dispatch, which shows the GUI for creating or modifying a form. | ||
*/ | ||
public class ImportFormularinhaltDispatch extends WollMuxDispatch | ||
{ | ||
/** | ||
* Command of this dispatch. | ||
*/ | ||
public static final String COMMAND = "wollmux:ImportFormularinhalt"; | ||
|
||
ImportFormularinhaltDispatch(XDispatch origDisp, URL origUrl, XFrame frame) | ||
{ | ||
super(origDisp, origUrl, frame); | ||
} | ||
|
||
@Override | ||
public void dispatch(URL url, PropertyValue[] props) | ||
{ | ||
new OnImportFormularinhalt(DocumentManager.getTextDocumentController(frame)).emit(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
core/src/main/java/de/muenchen/allg/itd51/wollmux/event/handlers/OnImportFormularinhalt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/*- | ||
* #%L | ||
* WollMux | ||
* %% | ||
* Copyright (C) 2005 - 2020 Landeshauptstadt München | ||
* %% | ||
* Licensed under the EUPL, Version 1.1 or – as soon they will be | ||
* approved by the European Commission - subsequent versions of the | ||
* EUPL (the "Licence"); | ||
* | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl5 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
* #L% | ||
*/ | ||
package de.muenchen.allg.itd51.wollmux.event.handlers; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import de.muenchen.allg.itd51.wollmux.WollMuxFehlerException; | ||
import de.muenchen.allg.itd51.wollmux.document.DocumentManager; | ||
import de.muenchen.allg.itd51.wollmux.document.TextDocumentController; | ||
import de.muenchen.allg.itd51.wollmux.form.control.FormController; | ||
import de.muenchen.allg.itd51.wollmux.event.WollMuxEventHandler; | ||
|
||
import com.sun.star.ui.dialogs.FilePicker; | ||
import com.sun.star.ui.dialogs.TemplateDescription; | ||
import com.sun.star.ui.dialogs.XFilePicker3; | ||
import com.sun.star.uno.UnoRuntime; | ||
import com.sun.star.text.XTextDocument; | ||
import com.sun.star.document.XEventListener; | ||
import com.sun.star.lang.EventObject; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
|
||
import de.muenchen.allg.afid.UNO; | ||
import de.muenchen.allg.afid.UnoHelperException; | ||
|
||
|
||
/** | ||
* Event for importing content of formular. | ||
*/ | ||
public class OnImportFormularinhalt extends WollMuxEvent | ||
{ | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(OnImportFormularinhalt.class); | ||
|
||
private TextDocumentController documentController; | ||
/** | ||
* Create this event. | ||
* | ||
* @param documentController | ||
* The document associated with the FormularMax. | ||
*/ | ||
public OnImportFormularinhalt(TextDocumentController documentController) | ||
{ | ||
this.documentController = documentController; | ||
} | ||
|
||
|
||
@Override | ||
protected void doit() throws WollMuxFehlerException | ||
{ | ||
XFilePicker3 picker = FilePicker.createWithMode(UNO.defaultContext, | ||
TemplateDescription.FILEOPEN_SIMPLE); | ||
String filterName = "Tabellendokument"; | ||
picker.appendFilter(filterName, "*.odt"); | ||
picker.appendFilter("Alle Dateien", "*"); | ||
picker.setCurrentFilter(filterName); | ||
picker.setMultiSelectionMode(false); | ||
|
||
short res = picker.execute(); | ||
if (res == com.sun.star.ui.dialogs.ExecutableDialogResults.OK) | ||
{ | ||
String[] files = picker.getFiles(); | ||
try | ||
{ | ||
XTextDocument importDoc = UNO.XTextDocument(UNO.loadComponentFromURL(files[0], false, false, false)); | ||
|
||
XEventListener listener = new XEventListener() | ||
{ | ||
@Override | ||
public void disposing(EventObject arg0) | ||
{ | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void notifyEvent(com.sun.star.document.EventObject event) | ||
{ | ||
if (importDoc!=null | ||
&& UnoRuntime.areSame(importDoc, event.Source) | ||
&& WollMuxEventHandler.ON_WOLLMUX_PROCESSING_FINISHED.equals(event.EventName)) | ||
{ | ||
new OnRemoveDocumentEventListener(this).emit(); | ||
try(ByteArrayOutputStream out = new ByteArrayOutputStream()) | ||
{ | ||
FormController fc = DocumentManager.getDocumentManager().getFormController(importDoc); | ||
fc.exportFormValues(out); | ||
fc.importFormValues(out.toString()); | ||
TextDocumentController importDocumentController = DocumentManager.getDocumentManager().getTextDocumentController(importDoc); | ||
Map<String, String> id2value = importDocumentController.getModel().getFormFieldValuesMap(); | ||
for (Entry<String, String> e : id2value.entrySet()) | ||
{ | ||
if (e.getValue() != null) | ||
{ | ||
new OnSetFormValue(documentController.getModel().doc, e.getKey(), | ||
e.getValue(), null).emit(); | ||
} | ||
} | ||
} catch(Exception e) | ||
{ | ||
LOGGER.error("", e); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
new OnAddDocumentEventListener(listener).emit(); | ||
} catch ( UnoHelperException e ) | ||
{ | ||
LOGGER.error("", e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return this.getClass().getSimpleName() + "(" + documentController.getModel() | ||
+ ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters