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
;
23 import com
.sun
.star
.awt
.XDialog
;
24 import com
.sun
.star
.beans
.XPropertySet
;
25 import com
.sun
.star
.lang
.EventObject
;
26 import com
.sun
.star
.uno
.XComponentContext
;
28 public class WikiPropDialog
extends WikiDialog
{
30 private WikiEditorImpl m_aWikiEditor
;
32 private static final String sSendMethod
= "Send";
33 private static final String sWikiListMethod
= "WikiListChange";
34 private static final String sArticleTextMethod
= "ArticleTextChange";
35 private static final String sAddWikiMethod
= "AddWiki";
37 private final String
[] m_pMethods
= {sSendMethod
, sWikiListMethod
, sArticleTextMethod
, sAddWikiMethod
};
39 private String m_sWikiTitle
= "";
40 private String m_sWikiEngineURL
= "";
41 protected String m_sWikiComment
= "";
42 protected boolean m_bWikiMinorEdit
= false;
44 /** Creates a new instance of WikiPropDialog */
45 public WikiPropDialog(XComponentContext xContext
, String DialogURL
, WikiEditorImpl aWikiEditorForThrobber
)
47 super(xContext
, DialogURL
);
48 super.setMethods(m_pMethods
);
50 if ( aWikiEditorForThrobber
!= null )
52 InsertThrobber( 224, 122, 10, 10 );
53 m_aWikiEditor
= aWikiEditorForThrobber
;
56 InitStrings( xContext
);
61 private void InitControls()
65 GetPropSet( "CommentText" ).setPropertyValue( "AutoVScroll", Boolean
.TRUE
);
73 private void InitStrings( XComponentContext xContext
)
77 SetTitle( Helper
.GetLocalizedString( xContext
, Helper
.DLG_SENDTITLE
) );
78 GetPropSet( "Label1" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_SENDTOMEDIAWIKI_LABEL1
) );
79 GetPropSet( "FixedLine2" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_WIKIARTICLE
) );
80 GetPropSet( "Label2" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_SENDTOMEDIAWIKI_LABEL2
) );
81 GetPropSet( "Label3" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_SENDTOMEDIAWIKI_LABEL3
) );
82 GetPropSet( "MinorCheck" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_SENDTOMEDIAWIKI_MINORCHECK
) );
83 GetPropSet( "BrowserCheck" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_SENDTOMEDIAWIKI_BROWSERCHECK
) );
84 GetPropSet( "AddButton" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_ADDBUTTON
) );
85 GetPropSet( "SendButton" ).setPropertyValue( "Label", Helper
.GetLocalizedString( xContext
, Helper
.DLG_SENDBUTTON
) );
93 private void InitShowBrowser()
97 GetPropSet( "BrowserCheck" ).setPropertyValue( "State", Short
.valueOf( Helper
.GetShowInBrowserByDefault( m_xContext
) ?
(short)1 : (short)0 ) );
106 public boolean show()
108 EnableControls( true );
109 boolean bResult
= super.show();
111 if ( bResult
&& Helper
.GetShowInBrowserByDefault( m_xContext
) )
112 Helper
.ShowURLInBrowser( m_xContext
, m_sWikiEngineURL
+ "index.php?title=" + m_sWikiTitle
);
118 public synchronized void ThreadStop( boolean bSelf
)
120 boolean bShowError
= ( !bSelf
&& m_aThread
!= null && !m_bThreadFinished
);
122 super.ThreadStop( bSelf
);
125 Helper
.ShowError( m_xContext
,
127 Helper
.DLG_SENDTITLE
,
128 Helper
.CANCELSENDING_ERROR
,
133 public void fillWikiList()
135 String
[] WikiList
= m_aSettings
.getWikiURLs();
139 XPropertySet xPS
= GetPropSet("WikiList");
140 xPS
.setPropertyValue("StringItemList", WikiList
);
144 ex
.printStackTrace();
148 private void fillDocList()
150 XPropertySet xPS
= GetPropSet("ArticleText");
153 short [] sel
= (short[]) GetPropSet("WikiList").getPropertyValue("SelectedItems");
154 xPS
.setPropertyValue("StringItemList", m_aSettings
.getWikiDocList(sel
[0]));
158 ex
.printStackTrace();
163 public String
GetWikiTitle()
168 public void SetWikiTitle(String sArticle
)
170 m_sWikiTitle
= sArticle
;
173 XPropertySet xPS
= GetPropSet("ArticleText");
174 xPS
.setPropertyValue("Text", sArticle
);
178 ex
.printStackTrace();
183 private void switchSendButtonIfNecessary()
185 XPropertySet xSendButton
= GetPropSet( "SendButton" );
186 if ( xSendButton
!= null )
188 XPropertySet xWikiListProps
= GetPropSet( "WikiList" );
189 XPropertySet xArticleProps
= GetPropSet( "ArticleText" );
190 if ( xWikiListProps
!= null && xArticleProps
!= null )
194 short [] pSel
= (short[]) GetPropSet("WikiList").getPropertyValue("SelectedItems");
195 String sArticle
= (String
)xArticleProps
.getPropertyValue( "Text" );
196 if ( pSel
!= null && pSel
.length
> 0 && sArticle
!= null && sArticle
.length() != 0 )
197 xSendButton
.setPropertyValue( "Enabled", Boolean
.TRUE
);
199 xSendButton
.setPropertyValue( "Enabled", Boolean
.FALSE
);
203 ex
.printStackTrace();
209 private void EnableControls( boolean bEnable
)
213 String
[] pControls
= { "WikiList",
221 for ( int nInd
= 0; nInd
< pControls
.length
; nInd
++ )
222 GetPropSet( pControls
[nInd
] ).setPropertyValue( "Enabled", Boolean
.valueOf( bEnable
) );
226 SetFocusTo( "WikiList" );
227 switchSendButtonIfNecessary();
231 GetPropSet( "SendButton" ).setPropertyValue( "Enabled", Boolean
.valueOf( bEnable
) );
232 SetFocusTo( "CancelButton" );
237 ex
.printStackTrace();
242 public boolean callHandlerMethod( XDialog xDialog
, Object EventObject
, String MethodName
)
244 if ( MethodName
.equals( sSendMethod
) )
248 XPropertySet aWikiListProps
= GetPropSet( "WikiList" );
249 XPropertySet aArticleTextProps
= GetPropSet( "ArticleText" );
250 XPropertySet aCommentTextProps
= GetPropSet( "CommentText" );
251 XPropertySet aMinorCheckProps
= GetPropSet( "MinorCheck" );
252 XPropertySet aBrowserCheckProps
= GetPropSet( "BrowserCheck" );
254 short [] sel
= (short[]) aWikiListProps
.getPropertyValue("SelectedItems");
255 String
[] items
= (String
[]) aWikiListProps
.getPropertyValue("StringItemList");
256 m_sWikiEngineURL
= items
[sel
[0]];
257 m_sWikiTitle
= (String
) aArticleTextProps
.getPropertyValue("Text");
258 m_sWikiComment
= (String
) aCommentTextProps
.getPropertyValue("Text");
260 short minorState
= ((Short
) aMinorCheckProps
.getPropertyValue("State")).shortValue();
262 m_bWikiMinorEdit
= true;
264 m_bWikiMinorEdit
= false;
266 short nBrowserState
= ((Short
) aBrowserCheckProps
.getPropertyValue("State")).shortValue();
267 Helper
.SetShowInBrowserByDefault( m_xContext
, nBrowserState
!= 0 );
269 // allow to disable other buttons
270 EnableControls( false );
274 ex
.printStackTrace();
277 final XDialog xDialogToClose
= xDialog
;
278 final XComponentContext xContext
= m_xContext
;
281 SetThrobberVisible( true );
282 SetThrobberActive( true );
284 // the following method might show a dialog, should be used in main thread
285 final Map
<String
,String
> aWikiSettings
= m_aSettings
.getSettingByUrl( m_sWikiEngineURL
);
286 if ( Helper
.AllowThreadUsage( m_xContext
) )
288 m_aThread
= new Thread( "com.sun.star.thread.WikiEditorSendingThread" )
295 if ( m_aWikiEditor
!= null )
298 m_bAction
= m_aWikiEditor
.SendArticleImpl(
299 WikiPropDialog
.this, aWikiSettings
);
304 EnableControls( true );
305 SetThrobberActive( false );
306 SetThrobberVisible( false );
310 MainThreadDialogExecutor
.Close( xContext
, xDialogToClose
);
321 if (m_aWikiEditor
!= null && aWikiSettings
!= null)
323 m_bAction
= m_aWikiEditor
.SendArticleImpl(
324 WikiPropDialog
.this, aWikiSettings
);
326 } catch( java
.lang
.Exception e
)
330 EnableControls( true );
331 SetThrobberActive( false );
332 SetThrobberVisible( false );
335 xDialogToClose
.endExecute();
341 else if ( MethodName
.equals( sWikiListMethod
) )
344 switchSendButtonIfNecessary();
347 else if ( MethodName
.equals( sArticleTextMethod
) )
349 switchSendButtonIfNecessary();
352 else if ( MethodName
.equals( sAddWikiMethod
) )
354 WikiEditSettingDialog xAddDialog
= new WikiEditSettingDialog(m_xContext
, "vnd.sun.star.script:WikiEditor.EditSetting?location=application");
355 if ( xAddDialog
.show() )
358 xAddDialog
.DisposeDialog();
367 public void windowClosed( EventObject e
)