Debian Codegraph @

swext/mediawiki/src/com/sun/star/wiki/WikiPropDialog.java

raw
1 /*
2 * This file is part of the LibreOffice project.
3 *
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/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
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 .
17 */
18
19 package com.sun.star.wiki;
20
21 import java.util.Map;
22
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;
27
28 public class WikiPropDialog extends WikiDialog{
29
30 private WikiEditorImpl m_aWikiEditor;
31
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";
36
37 private final String[] m_pMethods = {sSendMethod, sWikiListMethod, sArticleTextMethod, sAddWikiMethod};
38
39 private String m_sWikiTitle = "";
40 private String m_sWikiEngineURL = "";
41 protected String m_sWikiComment = "";
42 protected boolean m_bWikiMinorEdit = false;
43
44 /** Creates a new instance of WikiPropDialog */
45 public WikiPropDialog(XComponentContext xContext, String DialogURL, WikiEditorImpl aWikiEditorForThrobber )
46 {
47 super(xContext, DialogURL);
48 super.setMethods(m_pMethods);
49
50 if ( aWikiEditorForThrobber != null )
51 {
52 InsertThrobber( 224, 122, 10, 10 );
53 m_aWikiEditor = aWikiEditorForThrobber;
54 }
55
56 InitStrings( xContext );
57 InitShowBrowser();
58 InitControls();
59 }
60
61 private void InitControls()
62 {
63 try
64 {
65 GetPropSet( "CommentText" ).setPropertyValue( "AutoVScroll", Boolean.TRUE );
66 }
67 catch( Exception e )
68 {
69 e.printStackTrace();
70 }
71 }
72
73 private void InitStrings( XComponentContext xContext )
74 {
75 try
76 {
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 ) );
86 }
87 catch( Exception e )
88 {
89 e.printStackTrace();
90 }
91 }
92
93 private void InitShowBrowser()
94 {
95 try
96 {
97 GetPropSet( "BrowserCheck" ).setPropertyValue( "State", Short.valueOf( Helper.GetShowInBrowserByDefault( m_xContext ) ? (short)1 : (short)0 ) );
98 }
99 catch( Exception e )
100 {
101 e.printStackTrace();
102 }
103 }
104
105 @Override
106 public boolean show()
107 {
108 EnableControls( true );
109 boolean bResult = super.show();
110
111 if ( bResult && Helper.GetShowInBrowserByDefault( m_xContext ) )
112 Helper.ShowURLInBrowser( m_xContext, m_sWikiEngineURL + "index.php?title=" + m_sWikiTitle );
113
114 return bResult;
115 }
116
117 @Override
118 public synchronized void ThreadStop( boolean bSelf )
119 {
120 boolean bShowError = ( !bSelf && m_aThread != null && !m_bThreadFinished );
121
122 super.ThreadStop( bSelf );
123
124 if ( bShowError )
125 Helper.ShowError( m_xContext,
126 m_xDialog,
127 Helper.DLG_SENDTITLE,
128 Helper.CANCELSENDING_ERROR,
129 null,
130 false );
131 }
132
133 public void fillWikiList()
134 {
135 String [] WikiList = m_aSettings.getWikiURLs();
136
137 try
138 {
139 XPropertySet xPS = GetPropSet("WikiList");
140 xPS.setPropertyValue("StringItemList", WikiList);
141 }
142 catch (Exception ex)
143 {
144 ex.printStackTrace();
145 }
146 }
147
148 private void fillDocList()
149 {
150 XPropertySet xPS = GetPropSet("ArticleText");
151 try
152 {
153 short [] sel = (short[]) GetPropSet("WikiList").getPropertyValue("SelectedItems");
154 xPS.setPropertyValue("StringItemList", m_aSettings.getWikiDocList(sel[0]));
155 }
156 catch (Exception ex)
157 {
158 ex.printStackTrace();
159 }
160 }
161
162
163 public String GetWikiTitle()
164 {
165 return m_sWikiTitle;
166 }
167
168 public void SetWikiTitle(String sArticle)
169 {
170 m_sWikiTitle = sArticle;
171 try
172 {
173 XPropertySet xPS = GetPropSet("ArticleText");
174 xPS.setPropertyValue("Text", sArticle);
175 }
176 catch (Exception ex)
177 {
178 ex.printStackTrace();
179 }
180 }
181
182
183 private void switchSendButtonIfNecessary()
184 {
185 XPropertySet xSendButton = GetPropSet( "SendButton" );
186 if ( xSendButton != null )
187 {
188 XPropertySet xWikiListProps = GetPropSet( "WikiList" );
189 XPropertySet xArticleProps = GetPropSet( "ArticleText" );
190 if ( xWikiListProps != null && xArticleProps != null )
191 {
192 try
193 {
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 );
198 else
199 xSendButton.setPropertyValue( "Enabled", Boolean.FALSE );
200 }
201 catch (Exception ex)
202 {
203 ex.printStackTrace();
204 }
205 }
206 }
207 }
208
209 private void EnableControls( boolean bEnable )
210 {
211 try
212 {
213 String[] pControls = { "WikiList",
214 "ArticleText",
215 "CommentText",
216 "MinorCheck",
217 "BrowserCheck",
218 "HelpButton",
219 "AddButton" };
220
221 for ( int nInd = 0; nInd < pControls.length; nInd++ )
222 GetPropSet( pControls[nInd] ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) );
223
224 if ( bEnable )
225 {
226 SetFocusTo( "WikiList" );
227 switchSendButtonIfNecessary();
228 }
229 else
230 {
231 GetPropSet( "SendButton" ).setPropertyValue( "Enabled", Boolean.valueOf( bEnable ) );
232 SetFocusTo( "CancelButton" );
233 }
234 }
235 catch (Exception ex)
236 {
237 ex.printStackTrace();
238 }
239 }
240
241 @Override
242 public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName )
243 {
244 if ( MethodName.equals( sSendMethod ) )
245 {
246 try
247 {
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" );
253
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");
259
260 short minorState = ((Short) aMinorCheckProps.getPropertyValue("State")).shortValue();
261 if (minorState != 0)
262 m_bWikiMinorEdit = true;
263 else
264 m_bWikiMinorEdit = false;
265
266 short nBrowserState = ((Short) aBrowserCheckProps.getPropertyValue("State")).shortValue();
267 Helper.SetShowInBrowserByDefault( m_xContext, nBrowserState != 0 );
268
269 // allow to disable other buttons
270 EnableControls( false );
271 }
272 catch (Exception ex)
273 {
274 ex.printStackTrace();
275 }
276
277 final XDialog xDialogToClose = xDialog;
278 final XComponentContext xContext = m_xContext;
279
280 // start spinning
281 SetThrobberVisible( true );
282 SetThrobberActive( true );
283
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 ) )
287 {
288 m_aThread = new Thread( "com.sun.star.thread.WikiEditorSendingThread" )
289 {
290 @Override
291 public void run()
292 {
293 try
294 {
295 if ( m_aWikiEditor != null )
296 {
297 Thread.yield();
298 m_bAction = m_aWikiEditor.SendArticleImpl(
299 WikiPropDialog.this, aWikiSettings);
300 }
301 }
302 finally
303 {
304 EnableControls( true );
305 SetThrobberActive( false );
306 SetThrobberVisible( false );
307
308 ThreadStop( true );
309 if ( m_bAction )
310 MainThreadDialogExecutor.Close( xContext, xDialogToClose );
311 }
312 }
313 };
314
315 m_aThread.start();
316 }
317 else
318 {
319 try
320 {
321 if (m_aWikiEditor != null && aWikiSettings != null)
322 {
323 m_bAction = m_aWikiEditor.SendArticleImpl(
324 WikiPropDialog.this, aWikiSettings);
325 }
326 } catch( java.lang.Exception e )
327 {}
328 finally
329 {
330 EnableControls( true );
331 SetThrobberActive( false );
332 SetThrobberVisible( false );
333
334 if ( m_bAction )
335 xDialogToClose.endExecute();
336 }
337 }
338
339 return true;
340 }
341 else if ( MethodName.equals( sWikiListMethod ) )
342 {
343 fillDocList();
344 switchSendButtonIfNecessary();
345 return true;
346 }
347 else if ( MethodName.equals( sArticleTextMethod ) )
348 {
349 switchSendButtonIfNecessary();
350 return true;
351 }
352 else if ( MethodName.equals( sAddWikiMethod ) )
353 {
354 WikiEditSettingDialog xAddDialog = new WikiEditSettingDialog(m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application");
355 if ( xAddDialog.show() )
356 fillWikiList();
357
358 xAddDialog.DisposeDialog();
359
360 return true;
361 }
362
363 return false;
364 }
365
366 @Override
367 public void windowClosed( EventObject e )
368 {
369 ThreadStop( false );
370 }
371 }
372