W2L custom config ui refactoring & enhancements

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@79 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2010-12-09 19:30:33 +00:00
parent 84f4d5cb20
commit ea5d8679c9
10 changed files with 322 additions and 161 deletions

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-04-12)
* Version 1.2 (2010-12-09)
*
*/
@ -288,6 +288,14 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
config.setOption(sConfigName, sConfigValues[dlg.getListBoxSelectedItem(sListBoxName)]);
}
// Utilities
protected String[] sortStringSet(Set<String> theSet) {
String[] theArray = theSet.toArray(new String[theSet.size()]);
// TODO: Get locale from OOo rather than the system
Collator collator = Collator.getInstance();
Arrays.sort(theArray, collator);
return theArray;
}
}
protected abstract class CustomFileHandler extends PageHandler {
@ -506,13 +514,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
private String newItem(Set<String> suggestions) {
XDialog xDialog=getDialog(getDialogLibraryName()+".NewDialog");
if (xDialog!=null) {
int nCount = suggestions.size();
String[] sItems = new String[nCount];
int i=0;
for (String s : suggestions) {
sItems[i++] = s;
}
sortStringArray(sItems);
String[] sItems = sortStringSet(suggestions);
DialogAccess ndlg = new DialogAccess(xDialog);
ndlg.setListBoxStringItemList("Name", sItems);
String sResult = null;
@ -547,23 +549,6 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
return sNewItem;
}
// Utilities
protected String[] sortStringSet(Set<String> theSet) {
String[] theArray = new String[theSet.size()];
int i=0;
for (String s : theSet) {
theArray[i++] = s;
}
sortStringArray(theArray);
return theArray;
}
protected void sortStringArray(String[] theArray) {
// TODO: Get locale from OOo rather than the system
Collator collator = Collator.getInstance();
Arrays.sort(theArray, collator);
}
}
protected abstract class StylesPageHandler extends UserListPageHandler {
@ -588,7 +573,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
protected abstract void clearControls(DialogAccess dlg);
protected abstract void prepareControls(DialogAccess dlg);
protected abstract void prepareControls(DialogAccess dlg, boolean bHasDefinitions);
// Constructor
protected StylesPageHandler(int nCount) {
@ -682,8 +667,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
dlg.setListBoxSelectedItem("StyleName", (short)-1);
}
updateDeleteButton(dlg);
prepareControls(dlg);
updateStyleControls(dlg);
styleNameChange(dlg);
}
}
@ -711,7 +695,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
styleMap[nCurrentFamily].put(sNewName, new HashMap<String,String>());
clearControls(dlg);
}
updateDeleteButton(dlg);
updateStyleControls(dlg);
}
}
@ -722,7 +706,7 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
styleMap[nCurrentFamily].remove(sStyleName);
styleNameChange(dlg);
}
updateDeleteButton(dlg);
updateStyleControls(dlg);
}
}
@ -776,8 +760,10 @@ public abstract class ConfigurationDialogBase extends WeakBase implements XConta
styleFamilyChange(dlg);
}
private void updateDeleteButton(DialogAccess dlg) {
dlg.setControlEnabled("DeleteStyleButton", dlg.getListBoxStringItemList("StyleName").length>0);
private void updateStyleControls(DialogAccess dlg) {
boolean bHasMappings = dlg.getListBoxStringItemList("StyleName").length>0;
dlg.setControlEnabled("DeleteStyleButton", bHasMappings);
prepareControls(dlg,bHasMappings);
}
private void copyStyles(ComplexOption source, ComplexOption target, Map<String,String> nameTranslation) {

View file

@ -0,0 +1,93 @@
/************************************************************************
*
* FiledMasterNameProvider.java
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2010-12-09)
*
*/
package org.openoffice.da.comp.w2lcommon.helper;
import java.util.HashSet;
import java.util.Set;
import com.sun.star.container.XNameAccess;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel;
import com.sun.star.text.XTextFieldsSupplier;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
/** This class provides access to the names of all field masters in the current document
*/
public class FieldMasterNameProvider {
private String[] fieldMasterNames;
/** Construct a new <code>FieldMasterNameProvider</code>
*
* @param xContext the component context to get the desktop from
*/
public FieldMasterNameProvider(XComponentContext xContext) {
fieldMasterNames = new String[0];
// TODO: This code should be shared (identical with StyleNameProvider...)
// Get the model for the current frame
XModel xModel = null;
try {
Object desktop = xContext.getServiceManager().createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop);
XController xController = xDesktop.getCurrentFrame().getController();
if (xController!=null) {
xModel = xController.getModel();
}
}
catch (Exception e) {
// do nothing
}
// Get the field masters from the model
if (xModel!=null) {
XTextFieldsSupplier xSupplier = (XTextFieldsSupplier) UnoRuntime.queryInterface(
XTextFieldsSupplier.class, xModel);
if (xSupplier!=null) {
XNameAccess xFieldMasters = xSupplier.getTextFieldMasters();
fieldMasterNames = xFieldMasters.getElementNames();
}
}
}
/** Get the names of all field masters relative to a given prefix
*
* @param sPrefix the prefix to look for, e.g. "com.sun.star.text.fieldmaster.SetExpression."
* @return a read only <code>Set</code> containing all known names with the given prefix, stripped for the prefix
*/
public Set<String> getFieldMasterNames(String sPrefix) {
Set<String> names = new HashSet<String>();
for (String sName : fieldMasterNames) {
if (sName.startsWith(sPrefix)) {
names.add(sName.substring(sPrefix.length()));
}
}
return names;
}
}