Alpha working
This commit is contained in:
parent
adf19bc4ab
commit
90617b8120
4 changed files with 81 additions and 27 deletions
|
@ -82,16 +82,18 @@ public class Document {
|
|||
reader.parse();
|
||||
}
|
||||
|
||||
private void writeOutlineMetadata() {
|
||||
public void writeOutlineMetadata() {
|
||||
cleanMetadataInDocument();
|
||||
for (OutlineElement element : outline){
|
||||
Object annotation;
|
||||
try {
|
||||
annotation = multiServiceFactory.createInstance("com.sun.star.text.textfield.annotation");
|
||||
element.writeMetadata(annotation);
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (!element.isEmpty()) {
|
||||
Object annotation;
|
||||
try {
|
||||
annotation = multiServiceFactory.createInstance("com.sun.star.text.TextField.Annotation");
|
||||
element.writeMetadata(annotation);
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,22 @@ public class OutlineElement {
|
|||
|
||||
private String elementName;
|
||||
private ArrayList<MetadataElement> metadata = null;
|
||||
|
||||
private XTextRange textRange;
|
||||
|
||||
public String getName() {
|
||||
return elementName;
|
||||
}
|
||||
|
||||
private XTextRange textRange;
|
||||
public boolean isEmpty() {
|
||||
if (metadata.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < metadata.size(); i++) {
|
||||
if (!metadata.get(i).getName().isEmpty() && !metadata.get(i).getValue().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public OutlineElement(XTextRange textRange, String name) {
|
||||
this.textRange = textRange;
|
||||
|
@ -39,9 +49,9 @@ public class OutlineElement {
|
|||
int size = metadata.size();
|
||||
if (metadata.size() == 0) {
|
||||
result = new Object[][] {
|
||||
{null, null},
|
||||
{null, null},
|
||||
{null, null},
|
||||
{"", ""},
|
||||
{"", ""},
|
||||
{"", ""},
|
||||
};
|
||||
} else {
|
||||
result = new Object [size] [2];
|
||||
|
@ -83,14 +93,15 @@ private String metadataToString() {
|
|||
|
||||
public void writeMetadata(Object annotation) {
|
||||
XPropertySet properties = UnoRuntime.queryInterface(XPropertySet.class, annotation);
|
||||
XText startText = textRange.getText();
|
||||
XText text = textRange.getText();
|
||||
try {
|
||||
properties.setPropertyValue("Author", METADATA_EXTENSION);
|
||||
properties.setPropertyValue("Content", metadataToString());
|
||||
|
||||
XTextRange annotationRange = null;
|
||||
annotationRange = textRange;
|
||||
XTextField textField = UnoRuntime.queryInterface(XTextField.class, annotation);
|
||||
startText.insertTextContent( annotationRange, textField, true );
|
||||
text.insertTextContent( annotationRange, textField, false );
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (UnknownPropertyException e) {
|
||||
|
@ -101,6 +112,10 @@ public void writeMetadata(Object annotation) {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void setMetadata(ArrayList<MetadataElement> metadataInput) {
|
||||
this.metadata.clear();
|
||||
this.metadata.addAll(metadataInput);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class EditorGUI extends JFrame {
|
|||
//Components
|
||||
private JTable tableDocStandard;
|
||||
private JTable tableDocCustom;
|
||||
|
||||
private ArrayList<MetadataTableModel> tableModels ;
|
||||
|
||||
//Component models
|
||||
private DefaultTableModel docPropertiesModel;
|
||||
|
@ -121,6 +121,7 @@ public class EditorGUI extends JFrame {
|
|||
docProps = document.getDocumentProperties();
|
||||
docCustomProps = document.getDocumentCustomProperties();
|
||||
outline = document.getOutline();
|
||||
tableModels = new ArrayList<MetadataTableModel>();
|
||||
initComponents();
|
||||
createEvents();
|
||||
}
|
||||
|
@ -176,7 +177,6 @@ public class EditorGUI extends JFrame {
|
|||
tabbedPane.addTab("Метаданные либры", null, panelStandardMetadata, null);
|
||||
tabbedPane.setEnabledAt(0, true);
|
||||
if (true) {
|
||||
//TEST ONLY
|
||||
addMetadataTab(new OutlineElement(null, "Тестовое название"));
|
||||
}
|
||||
for (OutlineElement element : outline) {
|
||||
|
@ -213,7 +213,8 @@ public class EditorGUI extends JFrame {
|
|||
private void addMetadataTab(OutlineElement element) {
|
||||
JPanel panelOutline = new JPanel();
|
||||
JTable tableOutline = new JTable();
|
||||
DefaultTableModel outlineTableModel = createOutlineTableModel(element);
|
||||
MetadataTableModel outlineTableModel = createOutlineTableModel(element);
|
||||
tableModels.add(outlineTableModel);
|
||||
configureTableOutline(tableOutline, outlineTableModel);
|
||||
|
||||
JButton btnOutlineSave = new JButton("Сохранить");
|
||||
|
@ -354,14 +355,9 @@ public class EditorGUI extends JFrame {
|
|||
});
|
||||
}
|
||||
|
||||
private DefaultTableModel createOutlineTableModel(OutlineElement element) {
|
||||
private MetadataTableModel createOutlineTableModel(OutlineElement element) {
|
||||
|
||||
DefaultTableModel outlineTableModel = new DefaultTableModel(
|
||||
element.metadataToArray(),
|
||||
new String[] {
|
||||
"Metadata Name", "Metadata Value"
|
||||
}
|
||||
);
|
||||
MetadataTableModel outlineTableModel = new MetadataTableModel(element);
|
||||
return outlineTableModel;
|
||||
}
|
||||
private void createCustomDocPropsModel() {
|
||||
|
@ -387,7 +383,7 @@ public class EditorGUI extends JFrame {
|
|||
}
|
||||
|
||||
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
private static void addPopup(Component component, JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
|
@ -409,5 +405,12 @@ public class EditorGUI extends JFrame {
|
|||
document.setDocumentProperties(docProps);
|
||||
updateDocCustomProps();
|
||||
document.setCustomDocumentProperties(docCustomProps);
|
||||
updateOutlineMetadata();
|
||||
document.writeOutlineMetadata();
|
||||
}
|
||||
private void updateOutlineMetadata() {
|
||||
for (MetadataTableModel table : tableModels) {
|
||||
table.writeToOutline();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package pro.litvinovg.libreoffice.metadata.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import pro.litvinovg.libreoffice.metadata.CustomDocumentProperty;
|
||||
import pro.litvinovg.libreoffice.metadata.MetadataElement;
|
||||
import pro.litvinovg.libreoffice.metadata.OutlineElement;
|
||||
|
||||
public class MetadataTableModel extends DefaultTableModel {
|
||||
private OutlineElement outlineElement;
|
||||
public MetadataTableModel(OutlineElement element) {
|
||||
super(element.metadataToArray(), new String[] { "Metadata Name", "Metadata Value" });
|
||||
this.outlineElement = element;
|
||||
}
|
||||
|
||||
public void writeToOutline() {
|
||||
Vector dataVector = this.getDataVector();
|
||||
Enumeration elements = dataVector.elements();
|
||||
ArrayList<MetadataElement> metadata = new ArrayList<MetadataElement>();
|
||||
while (elements.hasMoreElements()) {
|
||||
Vector row = (Vector) elements.nextElement();
|
||||
String name = (String) row.get(0);
|
||||
String value = (String) row.get(1);
|
||||
if (!name.isEmpty() && !value.isEmpty()) {
|
||||
metadata.add(new MetadataElement(name, value));
|
||||
}
|
||||
}
|
||||
outlineElement.setMetadata(metadata);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue