2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com
.sun
.star
.wiki
;
21 import com
.sun
.star
.awt
.XContainerWindowEventHandler
;
22 import com
.sun
.star
.awt
.XControl
;
23 import com
.sun
.star
.awt
.XControlContainer
;
24 import com
.sun
.star
.awt
.XDialog
;
25 import com
.sun
.star
.awt
.XDialogEventHandler
;
26 import com
.sun
.star
.awt
.XWindow
;
27 import com
.sun
.star
.beans
.XPropertySet
;
28 import com
.sun
.star
.lang
.WrappedTargetException
;
29 import com
.sun
.star
.lang
.XServiceInfo
;
30 import com
.sun
.star
.lib
.uno
.helper
.WeakBase
;
31 import com
.sun
.star
.uno
.AnyConverter
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XComponentContext
;
36 public final class WikiOptionsEventHandlerImpl
extends WeakBase
37 implements XServiceInfo
, XContainerWindowEventHandler
, XDialogEventHandler
39 static final String
[] m_pServiceNames
= { "com.sun.star.wiki.WikiOptionsEventHandler" };
40 static final String m_sImplementationName
= WikiOptionsEventHandlerImpl
.class.getName();
42 private static final String sExternalEvent
= "external_event";
43 private static final String sAdd
= "Add";
44 private static final String sEdit
= "Edit";
45 private static final String sRemove
= "Remove";
46 private static final String sListStatus
= "ListStatus";
47 private static final String sListEdit
= "ListEdit";
48 private static final String sInitialize
= "initialize";
49 private static final String sOk
= "ok";
50 private static final String sBack
= "back";
52 private final XComponentContext m_xContext
;
53 private XDialog m_xDialog
;
54 private XControlContainer m_xControlContainer
;
56 private Settings m_aSettings
;
58 public WikiOptionsEventHandlerImpl( XComponentContext xContext
)
60 m_xContext
= xContext
;
63 private XPropertySet
GetPropSet( String sControl
)
65 if ( m_xControlContainer
!= null )
67 XControl xControl
= m_xControlContainer
.getControl(sControl
);
68 XPropertySet xListProps
= UnoRuntime
.queryInterface(XPropertySet
.class, xControl
.getModel() );
75 private void RefreshView()
77 if ( m_aSettings
!= null )
79 String
[] pWikiList
= m_aSettings
.getWikiURLs();
80 XPropertySet xListProps
= GetPropSet( "WikiList" );
81 if ( xListProps
!= null )
85 xListProps
.setPropertyValue( "StringItemList", pWikiList
);
87 catch ( Exception ex
)
95 private void CheckButtonState()
97 XPropertySet xListProps
= GetPropSet( "WikiList" );
98 if ( xListProps
!= null )
102 short [] pSel
= (short []) xListProps
.getPropertyValue( "SelectedItems" );
103 XPropertySet xEditProps
= GetPropSet( "EditButton" );
104 XPropertySet xRemoveProps
= GetPropSet( "RemoveButton" );
105 Boolean bState
= Boolean
.valueOf( pSel
.length
!= 0 );
107 xEditProps
.setPropertyValue( "Enabled", bState
);
108 xRemoveProps
.setPropertyValue( "Enabled", bState
);
110 catch ( Exception ex
)
112 ex
.printStackTrace();
117 private void AddSetting()
119 WikiEditSettingDialog aSettingDialog
= new WikiEditSettingDialog( m_xContext
, "vnd.sun.star.script:WikiEditor.EditSetting?location=application" );
120 if ( aSettingDialog
.show() )
123 aSettingDialog
.DisposeDialog();
126 private void EditSetting()
128 XPropertySet xListProps
= GetPropSet( "WikiList" );
129 if ( xListProps
!= null )
131 Map
<String
,String
> ht
= null;
134 short[] pSel
= (short []) xListProps
.getPropertyValue( "SelectedItems" );
135 String
[] pItems
= (String
[]) xListProps
.getPropertyValue("StringItemList");
136 if ( pSel
.length
> 0 && pItems
.length
> pSel
[0] )
138 String selName
= pItems
[pSel
[0]];
139 ht
= m_aSettings
.getSettingByUrl( selName
);
142 catch ( Exception ex
)
144 ex
.printStackTrace();
147 WikiEditSettingDialog aSettingDialog
= new WikiEditSettingDialog(m_xContext
, "vnd.sun.star.script:WikiEditor.EditSetting?location=application", ht
, true );
148 if ( aSettingDialog
.show() )
151 aSettingDialog
.DisposeDialog();
155 private void RemoveSetting()
157 XPropertySet xListProps
= GetPropSet("WikiList");
158 if ( xListProps
!= null )
162 short[] pSel
= (short []) xListProps
.getPropertyValue("SelectedItems");
163 String
[] pItems
= (String
[]) GetPropSet("WikiList").getPropertyValue("StringItemList");
164 if ( pSel
.length
> 0 && pItems
.length
> pSel
[0] )
166 m_aSettings
.removeSettingByUrl( pItems
[pSel
[0]] );
172 ex
.printStackTrace();
177 private void InitStrings()
181 GetPropSet( "FixedLine1" ).setPropertyValue( "Label", Helper
.GetLocalizedString( m_xContext
, Helper
.DLG_MEDIAWIKIEXTENSION_STRING
) );
182 GetPropSet( "AddButton" ).setPropertyValue( "Label", Helper
.GetLocalizedString( m_xContext
, Helper
.DLG_ADDBUTTON
) );
183 GetPropSet( "EditButton" ).setPropertyValue( "Label", Helper
.GetLocalizedString( m_xContext
, Helper
.DLG_EDITBUTTON
) );
184 GetPropSet( "RemoveButton" ).setPropertyValue( "Label", Helper
.GetLocalizedString( m_xContext
, Helper
.DLG_REMOVEBUTTON
) );
192 // com.sun.star.lang.XServiceInfo:
193 public String
getImplementationName()
195 return m_sImplementationName
;
198 public boolean supportsService( String sService
)
200 int len
= m_pServiceNames
.length
;
202 for( int i
=0; i
< len
; i
++ )
204 if ( sService
.equals( m_pServiceNames
[i
] ))
210 public String
[] getSupportedServiceNames()
212 return m_pServiceNames
;
215 // XContainerWindowEventHandler
216 public boolean callHandlerMethod( XWindow xWindow
, Object aEventObject
, String sMethod
)
217 throws WrappedTargetException
, com
.sun
.star
.uno
.RuntimeException
219 if ( sMethod
.equals( sExternalEvent
) )
221 String sEvent
= AnyConverter
.toString( aEventObject
);
222 if ( sEvent
!= null )
224 if ( sEvent
.equals( sOk
) )
226 if ( m_aSettings
!= null )
227 m_aSettings
.storeConfiguration();
229 else if ( sEvent
.equals( sInitialize
) || sEvent
.equals( sBack
) )
231 if ( sEvent
.equals( sInitialize
) )
233 m_xDialog
= UnoRuntime
.queryInterface( XDialog
.class, xWindow
);
234 m_xControlContainer
= UnoRuntime
.queryInterface( XControlContainer
.class, m_xDialog
);
235 m_aSettings
= Settings
.getSettings( m_xContext
);
236 m_aSettings
.loadConfiguration(); // throw away all the noncommitted changes
239 else if ( m_aSettings
!= null )
240 m_aSettings
.loadConfiguration(); // throw away all the noncommitted changes
247 else if ( sMethod
.equals( sAdd
) )
251 else if ( sMethod
.equals( sEdit
) || sMethod
.equals( sListEdit
) )
255 else if ( sMethod
.equals( sRemove
) )
260 else if ( sMethod
.equals( sListStatus
) )
268 public boolean callHandlerMethod( XDialog xDialog
, Object aEventObject
, String sMethod
)
269 throws WrappedTargetException
, com
.sun
.star
.uno
.RuntimeException
274 public String
[] getSupportedMethodNames()
276 return new String
[] { sExternalEvent
, sAdd
, sEdit
, sRemove
};