LibreOffice Module cui (master)  1
optjava.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
23 #include <memory>
24 #include <vector>
25 
26 #include <config_java.h>
27 
28 #include "optaboutconfig.hxx"
29 #include "optjava.hxx"
30 #include <treeopt.hxx>
31 #include <dialmgr.hxx>
32 
33 #include <officecfg/Office/Common.hxx>
34 #include <osl/file.hxx>
35 #include <svtools/miscopt.hxx>
36 
37 #include <strings.hrc>
38 #include <vcl/svapp.hxx>
39 #include <tools/debug.hxx>
40 #include <tools/urlobj.hxx>
41 #include <vcl/weld.hxx>
42 #include <unotools/pathoptions.hxx>
43 #include <svtools/imagemgr.hxx>
45 #include <sfx2/filedlghelper.hxx>
46 #include <sfx2/inputdlg.hxx>
47 #include <tools/diagnose_ex.h>
49 #include <comphelper/string.hxx>
50 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
51 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
52 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
53 #include <com/sun/star/ui/dialogs/FolderPicker.hpp>
54 #include <com/sun/star/ucb/XContentProvider.hpp>
55 #if HAVE_FEATURE_JAVA
56 #include <jvmfwk/framework.hxx>
57 #endif
58 
59 // define ----------------------------------------------------------------
60 
61 #define CLASSPATH_DELIMITER SAL_PATHSEPARATOR
62 
63 using namespace ::com::sun::star::lang;
64 using namespace ::com::sun::star::ucb;
65 using namespace ::com::sun::star::ui::dialogs;
66 using namespace ::com::sun::star::uno;
67 
68 // class SvxJavaOptionsPage ----------------------------------------------
70  : SfxTabPage(pPage, pController, "cui/ui/optadvancedpage.ui", "OptAdvancedPage", &rSet)
71  , m_aResetIdle("cui options SvxJavaOptionsPage Reset")
72  , xDialogListener(new ::svt::DialogClosedListener())
73  , m_xJavaEnableCB(m_xBuilder->weld_check_button("javaenabled"))
74  , m_xJavaList(m_xBuilder->weld_tree_view("javas"))
75  , m_xJavaPathText(m_xBuilder->weld_label("javapath"))
76  , m_xAddBtn(m_xBuilder->weld_button("add"))
77  , m_xParameterBtn(m_xBuilder->weld_button("parameters"))
78  , m_xClassPathBtn(m_xBuilder->weld_button("classpath"))
79  , m_xExpertConfigBtn(m_xBuilder->weld_button("expertconfig"))
80  , m_xExperimentalCB(m_xBuilder->weld_check_button("experimental"))
81  , m_xMacroCB(m_xBuilder->weld_check_button("macrorecording"))
82  , m_xAccessibilityText(m_xBuilder->weld_label("a11y"))
83  , m_xAddDialogText(m_xBuilder->weld_label("selectruntime"))
84  , m_xJavaFrame(m_xBuilder->weld_widget("javaframe"))
85 {
86  m_sInstallText = m_xJavaPathText->get_label();
88  m_sAddDialogText = m_xAddDialogText->get_label();
89 
90  m_xJavaList->set_size_request(m_xJavaList->get_approximate_digit_width() * 30,
91  m_xJavaList->get_height_rows(8));
92 
93  std::vector<int> aWidths;
94  aWidths.push_back(m_xJavaList->get_checkbox_column_width());
95  aWidths.push_back(m_xJavaList->get_pixel_size("Sun Microsystems Inc.").Width());
96  aWidths.push_back(m_xJavaList->get_pixel_size("0.0.0_00-icedtea").Width());
97  m_xJavaList->set_column_fixed_widths(aWidths);
98 
99  std::vector<int> aRadioColumns;
100  aRadioColumns.push_back(0);
101  m_xJavaList->set_toggle_columns_as_radio(aRadioColumns);
102 
103  m_xJavaEnableCB->connect_clicked( LINK( this, SvxJavaOptionsPage, EnableHdl_Impl ) );
104  m_xJavaList->connect_toggled( LINK( this, SvxJavaOptionsPage, CheckHdl_Impl ) );
105  m_xJavaList->connect_changed( LINK( this, SvxJavaOptionsPage, SelectHdl_Impl ) );
106  m_xAddBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, AddHdl_Impl ) );
107  m_xParameterBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, ParameterHdl_Impl ) );
108  m_xClassPathBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, ClassPathHdl_Impl ) );
109  m_aResetIdle.SetInvokeHandler( LINK( this, SvxJavaOptionsPage, ResetHdl_Impl ) );
110 
111  m_xExpertConfigBtn->connect_clicked( LINK( this, SvxJavaOptionsPage, ExpertConfigHdl_Impl) );
112  if (!officecfg::Office::Common::Security::EnableExpertConfiguration::get())
113  m_xExpertConfigBtn->set_sensitive(false);
114 
115  if (officecfg::Office::Common::Misc::MacroRecorderMode::isReadOnly())
116  m_xMacroCB->set_sensitive(false);
117 
118  if (officecfg::Office::Common::Misc::ExperimentalMode::isReadOnly())
119  m_xExperimentalCB->set_sensitive(false);
120 
121  xDialogListener->SetDialogClosedLink( LINK( this, SvxJavaOptionsPage, DialogClosedHdl ) );
122 
123  EnableHdl_Impl(*m_xJavaEnableCB);
124 #if HAVE_FEATURE_JAVA
125  jfw_lock();
126 #else
127  m_xJavaFrame->set_sensitive(false);
128 #endif
129 }
130 
132 {
133  ClearJavaInfo();
134 #if HAVE_FEATURE_JAVA
135  m_aAddedInfos.clear();
136 
137  jfw_unlock();
138 #endif
139 }
140 
142 {
143  bool bEnable = m_xJavaEnableCB->get_active();
144  m_xJavaList->set_sensitive(bEnable);
145 }
146 
147 IMPL_LINK(SvxJavaOptionsPage, CheckHdl_Impl, const row_col&, rRowCol, void)
148 {
149  HandleCheckEntry(rRowCol.first);
150 }
151 
153 {
154  // set installation directory info
155  OUString sLocation = m_xJavaList->get_selected_id();
156  // tdf#80646 insert LTR mark after label
157  OUString sInfo = m_sInstallText + u"\u200E" + sLocation;
158  m_xJavaPathText->set_label(sInfo);
159 }
160 
162 {
163  try
164  {
166  xFolderPicker = FolderPicker::create(xContext);
167 
168  OUString sWorkFolder = SvtPathOptions().GetWorkPath();
169  xFolderPicker->setDisplayDirectory( sWorkFolder );
170  xFolderPicker->setDescription( m_sAddDialogText );
171 
172  Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
173  if ( xAsyncDlg.is() )
174  xAsyncDlg->startExecuteModal( xDialogListener.get() );
175  else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
176  AddFolder( xFolderPicker->getDirectory() );
177  }
178  catch (const Exception&)
179  {
180  TOOLS_WARN_EXCEPTION( "cui.options", "SvxJavaOptionsPage::AddHdl_Impl()");
181  }
182 }
183 
185 {
186 #if HAVE_FEATURE_JAVA
187  std::vector< OUString > aParameterList;
188  if (!m_xParamDlg)
189  {
190  m_xParamDlg.reset(new SvxJavaParameterDlg(GetFrameWeld()));
191  javaFrameworkError eErr = jfw_getVMParameters( &m_parParameters );
192  if ( JFW_E_NONE == eErr && !m_parParameters.empty() )
193  {
194  aParameterList = m_parParameters;
195  m_xParamDlg->SetParameters( aParameterList );
196  }
197  }
198  else
199  {
200  aParameterList = m_xParamDlg->GetParameters();
201  m_xParamDlg->DisableButtons(); //disable add, edit and remove button when dialog is reopened
202  }
203 
204  if (m_xParamDlg->run() == RET_OK)
205  {
206  if ( aParameterList != m_xParamDlg->GetParameters() )
207  {
208  aParameterList = m_xParamDlg->GetParameters();
209  if ( jfw_isVMRunning() )
210  {
212  }
213  }
214  }
215  else
216  m_xParamDlg->SetParameters( aParameterList );
217 #else
218  (void) this; // Silence loplugin:staticmethods
219 #endif
220 }
221 
222 
224 {
225 #if HAVE_FEATURE_JAVA
226  OUString sClassPath;
227 
228  if ( !m_xPathDlg )
229  {
230  m_xPathDlg.reset(new SvxJavaClassPathDlg(GetFrameWeld()));
231  javaFrameworkError eErr = jfw_getUserClassPath( &m_pClassPath );
232  if ( JFW_E_NONE == eErr )
233  {
234  sClassPath = m_pClassPath;
235  m_xPathDlg->SetClassPath( sClassPath );
236  }
237  }
238  else
239  sClassPath = m_xPathDlg->GetClassPath();
240 
241  m_xPathDlg->SetFocus();
242  if (m_xPathDlg->run() == RET_OK)
243  {
244 
245  if (m_xPathDlg->GetClassPath() != sClassPath)
246  {
247  sClassPath = m_xPathDlg->GetClassPath();
248  if ( jfw_isVMRunning() )
249  {
251  }
252  }
253  }
254  else
255  m_xPathDlg->SetClassPath( sClassPath );
256 #else
257  (void) this;
258 #endif
259 }
260 
261 
262 IMPL_LINK_NOARG(SvxJavaOptionsPage, ResetHdl_Impl, Timer *, void)
263 {
264  LoadJREs();
265 }
266 
267 
268 IMPL_LINK_NOARG(SvxJavaOptionsPage, StartFolderPickerHdl, void*, void)
269 {
270  try
271  {
272  Reference< XAsynchronousExecutableDialog > xAsyncDlg( xFolderPicker, UNO_QUERY );
273  if ( xAsyncDlg.is() )
274  xAsyncDlg->startExecuteModal( xDialogListener.get() );
275  else if ( xFolderPicker.is() && xFolderPicker->execute() == ExecutableDialogResults::OK )
276  AddFolder( xFolderPicker->getDirectory() );
277  }
278  catch ( Exception const & )
279  {
280  TOOLS_WARN_EXCEPTION( "cui.options", "SvxJavaOptionsPage::StartFolderPickerHdl()" );
281  }
282 }
283 
284 IMPL_LINK( SvxJavaOptionsPage, DialogClosedHdl, DialogClosedEvent*, pEvt, void )
285 {
286  if ( RET_OK == pEvt->DialogResult )
287  {
288  DBG_ASSERT( xFolderPicker.is(), "SvxJavaOptionsPage::DialogClosedHdl(): no folder picker" );
289 
290  AddFolder( xFolderPicker->getDirectory() );
291  }
292 }
293 
294 IMPL_LINK_NOARG(SvxJavaOptionsPage, ExpertConfigHdl_Impl, weld::Button&, void)
295 {
296  CuiAboutConfigTabPage aExpertConfigDlg(GetFrameWeld());
297  aExpertConfigDlg.Reset();//initialize and reset function
298 
299  if (RET_OK == aExpertConfigDlg.run())
300  {
301  aExpertConfigDlg.FillItemSet();//save changes if there are any
302  }
303 }
304 
306 {
307 #if HAVE_FEATURE_JAVA
308  m_parJavaInfo.clear();
309 #else
310  (void) this;
311 #endif
312 }
313 
315 {
316  m_xJavaList->clear();
317 }
318 
319 
321 {
322 #if HAVE_FEATURE_JAVA
323  weld::WaitObject aWaitObj(GetFrameWeld());
324  javaFrameworkError eErr = jfw_findAllJREs( &m_parJavaInfo );
325  if ( JFW_E_NONE == eErr )
326  {
327  for (auto const & pInfo: m_parJavaInfo)
328  {
329  AddJRE( pInfo.get() );
330  }
331  }
332 
333  for (auto const & pInfo: m_aAddedInfos)
334  {
335  AddJRE( pInfo.get() );
336  }
337 
338  std::unique_ptr<JavaInfo> pSelectedJava;
339  eErr = jfw_getSelectedJRE( &pSelectedJava );
340  if ( JFW_E_NONE == eErr && pSelectedJava )
341  {
342  sal_Int32 i = 0;
343  for (auto const & pCmpInfo: m_parJavaInfo)
344  {
345  if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pSelectedJava.get() ) )
346  {
347  HandleCheckEntry(i);
348  break;
349  }
350  ++i;
351  }
352  }
353 #else
354  (void) this;
355 #endif
356 }
357 
358 
359 void SvxJavaOptionsPage::AddJRE( JavaInfo const * _pInfo )
360 {
361 #if HAVE_FEATURE_JAVA
362  int nPos = m_xJavaList->n_children();
363  m_xJavaList->append();
364  m_xJavaList->set_toggle(nPos, TRISTATE_FALSE, 0);
365  m_xJavaList->set_text(nPos, _pInfo->sVendor, 1);
366  m_xJavaList->set_text(nPos, _pInfo->sVersion, 2);
367  OUString sFeature;
369  sFeature = m_sAccessibilityText;
370  m_xJavaList->set_text(nPos, sFeature, 3);
371 
372  INetURLObject aLocObj(_pInfo->sLocation);
373  OUString sLocation = aLocObj.getFSysPath(FSysStyle::Detect);
374  m_xJavaList->set_id(nPos, sLocation);
375 #else
376  (void) this;
377  (void)_pInfo;
378 #endif
379 }
380 
382 {
383  m_xJavaList->select(nCheckedRow);
384  for (int i = 0, nCount = m_xJavaList->n_children(); i < nCount; ++i)
385  {
386  // we have radio button behavior -> so uncheck the other entries
387  m_xJavaList->set_toggle(i, i == nCheckedRow ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
388  }
389 }
390 
391 void SvxJavaOptionsPage::AddFolder( const OUString& _rFolder )
392 {
393 #if HAVE_FEATURE_JAVA
394  bool bStartAgain = true;
395  std::unique_ptr<JavaInfo> pInfo;
396  javaFrameworkError eErr = jfw_getJavaInfoByPath( _rFolder, &pInfo );
397  if ( JFW_E_NONE == eErr && pInfo )
398  {
399  sal_Int32 nPos = 0;
400  bool bFound = false;
401  for (auto const & pCmpInfo: m_parJavaInfo)
402  {
403  if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pInfo.get() ) )
404  {
405  bFound = true;
406  break;
407  }
408  ++nPos;
409  }
410 
411  if ( !bFound )
412  {
413  for (auto const & pCmpInfo: m_aAddedInfos)
414  {
415  if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pInfo.get() ) )
416  {
417  bFound = true;
418  break;
419  }
420  ++nPos;
421  }
422  }
423 
424  if ( !bFound )
425  {
426  jfw_addJRELocation( pInfo->sLocation );
427  AddJRE( pInfo.get() );
428  m_aAddedInfos.push_back( std::move(pInfo) );
429  nPos = m_xJavaList->n_children() - 1;
430  }
431 
432  HandleCheckEntry(nPos);
433  bStartAgain = false;
434  }
435  else if ( JFW_E_NOT_RECOGNIZED == eErr )
436  {
437  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
438  VclMessageType::Warning, VclButtonsType::Ok,
439  CuiResId(RID_SVXSTR_JRE_NOT_RECOGNIZED)));
440  xBox->run();
441  }
442  else if ( JFW_E_FAILED_VERSION == eErr )
443  {
444  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
445  VclMessageType::Warning, VclButtonsType::Ok,
446  CuiResId(RID_SVXSTR_JRE_FAILED_VERSION)));
447  xBox->run();
448  }
449 
450  if ( bStartAgain )
451  {
452  xFolderPicker->setDisplayDirectory( _rFolder );
453  Application::PostUserEvent( LINK( this, SvxJavaOptionsPage, StartFolderPickerHdl ) );
454  }
455 #else
456  (void) this;
457  (void)_rFolder;
458 #endif
459 }
460 
462 {
463  OfaTreeOptionsDialog* pParentDlg(static_cast<OfaTreeOptionsDialog*>(GetDialogController()));
464  if (pParentDlg)
465  pParentDlg->SetNeedsRestart(eReason);
466 }
467 
468 std::unique_ptr<SfxTabPage> SvxJavaOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
469 {
470  return std::make_unique<SvxJavaOptionsPage>(pPage, pController, *rAttrSet);
471 }
472 
474 {
475  bool bModified = false;
476 
477  if ( m_xExperimentalCB->get_state_changed_from_saved() )
478  {
479  SvtMiscOptions aMiscOpt;
480  aMiscOpt.SetExperimentalMode( m_xExperimentalCB->get_active() );
481  bModified = true;
483  }
484 
485  if ( m_xMacroCB->get_state_changed_from_saved() )
486  {
487  SvtMiscOptions aMiscOpt;
488  aMiscOpt.SetMacroRecorderMode(m_xMacroCB->get_active());
489  bModified = true;
490  }
491 
492 #if HAVE_FEATURE_JAVA
494  if (m_xParamDlg)
495  {
496  eErr = jfw_setVMParameters(m_xParamDlg->GetParameters());
497  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters");
498  bModified = true;
499  }
500 
501  if (m_xPathDlg)
502  {
503  OUString sPath(m_xPathDlg->GetClassPath());
504  if (m_xPathDlg->GetOldPath() != sPath)
505  {
506  eErr = jfw_setUserClassPath( sPath );
507  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath");
508  bModified = true;
509  }
510  }
511 
512  sal_uInt32 nCount = m_xJavaList->n_children();
513  for (sal_uInt32 i = 0; i < nCount; ++i)
514  {
515  if (m_xJavaList->get_toggle(i, 0) == TRISTATE_TRUE)
516  {
517  JavaInfo const * pInfo;
518  if ( i < m_parJavaInfo.size() )
519  pInfo = m_parJavaInfo[i].get();
520  else
521  pInfo = m_aAddedInfos[ i - m_parJavaInfo.size() ].get();
522 
523  std::unique_ptr<JavaInfo> pSelectedJava;
524  eErr = jfw_getSelectedJRE( &pSelectedJava );
525  if ( JFW_E_NONE == eErr || JFW_E_INVALID_SETTINGS == eErr )
526  {
527  if (!pSelectedJava || !jfw_areEqualJavaInfo( pInfo, pSelectedJava.get() ) )
528  {
529  if ( jfw_isVMRunning() ||
531  {
533  }
534 
535  eErr = jfw_setSelectedJRE( pInfo );
536  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE");
537  bModified = true;
538  }
539  }
540  break;
541  }
542  }
543 
544  bool bEnabled = false;
545  eErr = jfw_getEnabled( &bEnabled );
546  DBG_ASSERT( JFW_E_NONE == eErr,
547  "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
548  if ( bEnabled != m_xJavaEnableCB->get_active() )
549  {
550  eErr = jfw_setEnabled( m_xJavaEnableCB->get_active() );
551  DBG_ASSERT( JFW_E_NONE == eErr,
552  "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
553  bModified = true;
554  }
555 #endif
556 
557  return bModified;
558 }
559 
560 
561 void SvxJavaOptionsPage::Reset( const SfxItemSet* /*rSet*/ )
562 {
563  ClearJavaInfo();
564  ClearJavaList();
565 
566  SvtMiscOptions aMiscOpt;
567 
568 #if HAVE_FEATURE_JAVA
569  bool bEnabled = false;
570  javaFrameworkError eErr = jfw_getEnabled( &bEnabled );
571  if ( eErr != JFW_E_NONE )
572  bEnabled = false;
573  m_xJavaEnableCB->set_active(bEnabled);
574  EnableHdl_Impl(*m_xJavaEnableCB);
575 #else
576  m_xJavaEnableCB->set_active(false);
577  m_xJavaEnableCB->set_sensitive(false);
578 #endif
579 
580  m_xExperimentalCB->set_active( aMiscOpt.IsExperimentalMode() );
581  m_xExperimentalCB->save_state();
582  m_xMacroCB->set_active(aMiscOpt.IsMacroRecorderMode());
583  m_xMacroCB->save_state();
584 
586 }
587 
588 
590 {
591  SetUserData( OUString() );
592 }
593 
594 // class SvxJavaParameterDlg ---------------------------------------------
595 
597  : GenericDialogController(pParent, "cui/ui/javastartparametersdialog.ui",
598  "JavaStartParameters")
599  , m_xParameterEdit(m_xBuilder->weld_entry("parameterfield"))
600  , m_xAssignBtn(m_xBuilder->weld_button("assignbtn"))
601  , m_xAssignedList(m_xBuilder->weld_tree_view("assignlist"))
602  , m_xRemoveBtn(m_xBuilder->weld_button("removebtn"))
603  , m_xEditBtn(m_xBuilder->weld_button("editbtn"))
604 {
605  m_xAssignedList->set_size_request(m_xAssignedList->get_approximate_digit_width() * 54,
606  m_xAssignedList->get_height_rows(6));
607  m_xParameterEdit->connect_changed( LINK( this, SvxJavaParameterDlg, ModifyHdl_Impl ) );
608  m_xAssignBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, AssignHdl_Impl ) );
609  m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, RemoveHdl_Impl ) );
610  m_xEditBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, EditHdl_Impl ) );
611  m_xAssignedList->connect_changed( LINK( this, SvxJavaParameterDlg, SelectHdl_Impl ) );
612  m_xAssignedList->connect_row_activated( LINK( this, SvxJavaParameterDlg, DblClickHdl_Impl ) );
613 
614  ModifyHdl_Impl(*m_xParameterEdit);
617 }
618 
620 {
621 }
622 
624 {
625  OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
626  m_xAssignBtn->set_sensitive(!sParam.isEmpty());
627 }
628 
630 {
631  OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
632  if (!sParam.isEmpty())
633  {
634  int nPos = m_xAssignedList->find_text(sParam);
635  if (nPos == -1)
636  {
637  m_xAssignedList->append_text(sParam);
638  m_xAssignedList->select(m_xAssignedList->n_children() - 1);
639  }
640  else
641  m_xAssignedList->select(nPos);
642  m_xParameterEdit->set_text(OUString());
643  ModifyHdl_Impl(*m_xParameterEdit);
644  EnableEditButton();
645  EnableRemoveButton();
646  }
647 }
648 
650 {
651  EditParameter();
652 }
653 
655 {
656  EnableEditButton();
657  EnableRemoveButton();
658 }
659 
661 {
662  EditParameter();
663  return true;
664 }
665 
667 {
668  int nPos = m_xAssignedList->get_selected_index();
669  if (nPos != -1)
670  {
671  m_xAssignedList->remove(nPos);
672  int nCount = m_xAssignedList->n_children();
673  if (nCount)
674  {
675  if (nPos >= nCount)
676  nPos = nCount - 1;
677  m_xAssignedList->select(nPos);
678  }
679  else
680  {
681  DisableEditButton();
682  }
683  }
684  EnableRemoveButton();
685 }
686 
688 {
689  int nPos = m_xAssignedList->get_selected_index();
690  m_xParameterEdit->set_text(OUString());
691 
692  if (nPos != -1)
693  {
694  InputDialog aParamEditDlg(m_xDialog.get(), CuiResId(RID_SVXSTR_JAVA_START_PARAM));
695  OUString editableClassPath = m_xAssignedList->get_selected_text();
696  aParamEditDlg.SetEntryText(editableClassPath);
697  aParamEditDlg.HideHelpBtn();
698 
699  if (!aParamEditDlg.run())
700  return;
701  OUString editedClassPath = comphelper::string::strip(aParamEditDlg.GetEntryText(), ' ');
702 
703  if ( !editedClassPath.isEmpty() && editableClassPath != editedClassPath )
704  {
705  m_xAssignedList->remove(nPos);
706  m_xAssignedList->insert_text(nPos, editedClassPath);
707  m_xAssignedList->select(nPos);
708  }
709  }
710 }
711 
713 {
714  m_xParameterEdit->grab_focus();
715  m_xAssignedList->select(-1);
716  return GenericDialogController::run();
717 }
718 
719 std::vector< OUString > SvxJavaParameterDlg::GetParameters() const
720 {
721  int nCount = m_xAssignedList->n_children();
722  std::vector< OUString > aParamList;
723  aParamList.reserve(nCount);
724  for (int i = 0; i < nCount; ++i)
725  aParamList.push_back(m_xAssignedList->get_text(i));
726  return aParamList;
727 }
728 
730 {
734 }
735 
736 void SvxJavaParameterDlg::SetParameters( std::vector< OUString > const & rParams )
737 {
738  m_xAssignedList->clear();
739  for (auto const & sParam: rParams)
740  {
741  m_xAssignedList->append_text(sParam);
742  }
745 }
746 
747 
748 // class SvxJavaClassPathDlg ---------------------------------------------
749 
751  : GenericDialogController(pParent, "cui/ui/javaclasspathdialog.ui", "JavaClassPath")
752  , m_xPathList(m_xBuilder->weld_tree_view("paths"))
753  , m_xAddArchiveBtn(m_xBuilder->weld_button("archive"))
754  , m_xAddPathBtn(m_xBuilder->weld_button("folder"))
755  , m_xRemoveBtn(m_xBuilder->weld_button("remove"))
756 {
757  m_xPathList->set_size_request(m_xPathList->get_approximate_digit_width() * 54,
758  m_xPathList->get_height_rows(8));
759  m_xAddArchiveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddArchiveHdl_Impl ) );
760  m_xAddPathBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddPathHdl_Impl ) );
761  m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, RemoveHdl_Impl ) );
762  m_xPathList->connect_changed( LINK( this, SvxJavaClassPathDlg, SelectHdl_Impl ) );
763 
764  // set initial focus to path list
765  m_xPathList->grab_focus();
766 }
767 
769 {
770 }
771 
773 {
774  sfx2::FileDialogHelper aDlg(TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, m_xDialog.get());
775  aDlg.SetTitle( CuiResId( RID_SVXSTR_ARCHIVE_TITLE ) );
776  aDlg.AddFilter( CuiResId( RID_SVXSTR_ARCHIVE_HEADLINE ), "*.jar;*.zip" );
777  OUString sFolder;
778  if (m_xPathList->count_selected_rows() > 0)
779  {
780  osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sFolder);
781  // best effort
782  }
783  if (sFolder.isEmpty())
784  sFolder = SvtPathOptions().GetWorkPath();
785  aDlg.SetDisplayDirectory( sFolder );
786  if ( aDlg.Execute() == ERRCODE_NONE )
787  {
788  OUString sURL = aDlg.GetPath();
789  OUString sFile;
790  if (osl::FileBase::getSystemPathFromFileURL(sURL, sFile) == osl::FileBase::E_None)
791  {
792  INetURLObject aURL( sURL );
793  if ( !IsPathDuplicate( sFile ) )
794  {
795  m_xPathList->append("", sFile, SvFileInformationManager::GetImageId(aURL));
796  m_xPathList->select(m_xPathList->n_children() - 1);
797  }
798  else
799  {
800  OUString sMsg( CuiResId( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
801  sMsg = sMsg.replaceFirst( "%1", sFile );
802  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
803  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
804  xBox->run();
805  }
806  }
807  else
808  {
809  OUString sMsg( CuiResId( RID_SVXSTR_CANNOTCONVERTURL_ERR ) );
810  sMsg = sMsg.replaceFirst( "%1", sURL );
811  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
812  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
813  xBox->run();
814  }
815  }
816  EnableRemoveButton();
817 }
818 
820 {
822  Reference < XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);
823 
824  OUString sOldFolder;
825  if (m_xPathList->count_selected_rows() > 0)
826  {
827  osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sOldFolder);
828  // best effort
829  }
830  if (sOldFolder.isEmpty())
831  sOldFolder = SvtPathOptions().GetWorkPath();
832  xFolderPicker->setDisplayDirectory( sOldFolder );
833  if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
834  {
835  OUString sFolderURL( xFolderPicker->getDirectory() );
836  INetURLObject aURL( sFolderURL );
837  OUString sNewFolder;
838  if (osl::FileBase::getSystemPathFromFileURL(sFolderURL, sNewFolder)
839  == osl::FileBase::E_None)
840  {
841  if ( !IsPathDuplicate( sNewFolder ) )
842  {
843  m_xPathList->append("", sNewFolder, SvFileInformationManager::GetImageId(aURL));
844  m_xPathList->select(m_xPathList->n_children() - 1);
845  }
846  else
847  {
848  OUString sMsg( CuiResId( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
849  sMsg = sMsg.replaceFirst( "%1", sNewFolder );
850  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
851  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
852  xBox->run();
853  }
854  }
855  else
856  {
857  OUString sMsg( CuiResId( RID_SVXSTR_CANNOTCONVERTURL_ERR ) );
858  sMsg = sMsg.replaceFirst( "%1", sFolderURL );
859  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
860  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
861  xBox->run();
862  }
863  }
864  EnableRemoveButton();
865 }
866 
868 {
869  int nPos = m_xPathList->get_selected_index();
870  if (nPos != -1)
871  {
872  m_xPathList->remove(nPos);
873  int nCount = m_xPathList->n_children();
874  if (nCount)
875  {
876  if (nPos >= nCount)
877  nPos = nCount - 1;
878  m_xPathList->select( nPos );
879  }
880  }
881 
882  EnableRemoveButton();
883 }
884 
886 {
887  EnableRemoveButton();
888 }
889 
890 bool SvxJavaClassPathDlg::IsPathDuplicate( const OUString& _rPath )
891 {
892  bool bRet = false;
893  int nCount = m_xPathList->n_children();
894  for (int i = 0; i < nCount; ++i)
895  {
896  if ( m_xPathList->get_text(i) == _rPath )
897  {
898  bRet = true;
899  break;
900  }
901  }
902 
903  return bRet;
904 }
905 
907 {
908  OUStringBuffer sPath;
909  int nCount = m_xPathList->n_children();
910  for (int i = 0; i < nCount; ++i)
911  {
912  if (!sPath.isEmpty())
913  sPath.append(CLASSPATH_DELIMITER);
914  sPath.append(m_xPathList->get_text(i));
915  }
916  return sPath.makeStringAndClear();
917 }
918 
919 void SvxJavaClassPathDlg::SetClassPath( const OUString& _rPath )
920 {
921  if ( m_sOldPath.isEmpty() )
922  m_sOldPath = _rPath;
923  m_xPathList->clear();
924  if (!_rPath.isEmpty())
925  {
926  sal_Int32 nIdx = 0;
927  do
928  {
929  OUString sToken = _rPath.getToken( 0, CLASSPATH_DELIMITER, nIdx );
930  OUString sURL;
931  osl::FileBase::getFileURLFromSystemPath(sToken, sURL); // best effort
932  INetURLObject aURL( sURL );
933  m_xPathList->append("", sToken, SvFileInformationManager::GetImageId(aURL));
934  }
935  while (nIdx>=0);
936  // select first entry
937  m_xPathList->select(0);
938  }
939  SelectHdl_Impl(*m_xPathList);
940 }
941 
942 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsExperimentalMode() const
std::shared_ptr< weld::Dialog > m_xDialog
javaFrameworkError jfw_getJavaInfoByPath(OUString const &pPath, std::unique_ptr< JavaInfo > *ppInfo)
OUString sVersion
void HandleCheckEntry(int nCheckedRow)
Definition: optjava.cxx:381
void SetUserData(const OUString &rString)
std::unique_ptr< weld::CheckButton > m_xMacroCB
Definition: optjava.hxx:79
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > xFolderPicker
Definition: optjava.hxx:65
OUString m_sOldPath
Definition: optjava.hxx:184
std::unique_ptr< weld::CheckButton > m_xExperimentalCB
Definition: optjava.hxx:78
bool jfw_isVMRunning()
std::unique_ptr< weld::Label > m_xAccessibilityText
Definition: optjava.hxx:81
std::unique_ptr< weld::Button > m_xAssignBtn
Definition: optjava.hxx:125
OUString m_sInstallText
Definition: optjava.hxx:57
std::unique_ptr< weld::Button > m_xRemoveBtn
Definition: optjava.hxx:127
#define CLASSPATH_DELIMITER
Definition: optjava.cxx:61
OUString GetClassPath() const
Definition: optjava.cxx:906
javaFrameworkError jfw_getVMParameters(std::vector< OUString > *parOptions)
std::unique_ptr< weld::Button > m_xEditBtn
Definition: optjava.hxx:128
SvxJavaClassPathDlg(weld::Window *pParent)
Definition: optjava.cxx:750
JFW_E_NOT_RECOGNIZED
#define JFW_REQUIRE_NEEDRESTART
bool IsMacroRecorderMode() const
javaFrameworkError jfw_setEnabled(bool bEnabled)
sal_uInt64 nFeatures
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
void AddFolder(const OUString &_rFolder)
Definition: optjava.cxx:391
javaFrameworkError jfw_setUserClassPath(OUString const &pCp)
std::unique_ptr< weld::Button > m_xExpertConfigBtn
Definition: optjava.hxx:73
TRISTATE_TRUE
std::unique_ptr< SvxJavaParameterDlg > m_xParamDlg
Definition: optjava.hxx:75
bool jfw_areEqualJavaInfo(JavaInfo const *pInfoA, JavaInfo const *pInfoB)
void RequestRestart(svtools::RestartReason eReason)
Definition: optjava.cxx:461
SvxJavaOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optjava.cxx:69
virtual void Start() override
std::unique_ptr< weld::TreeView > m_xPathList
Definition: optjava.hxx:179
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optjava.cxx:473
std::unique_ptr< weld::Widget > m_xJavaFrame
Definition: optjava.hxx:84
OString strip(const OString &rIn, sal_Char c)
std::unique_ptr< weld::Button > m_xAddBtn
Definition: optjava.hxx:70
std::unique_ptr< weld::Button > m_xRemoveBtn
Definition: optjava.hxx:182
JFW_E_INVALID_SETTINGS
OUString m_sAccessibilityText
Definition: optjava.hxx:58
javaFrameworkError jfw_addJRELocation(OUString const &sLocation)
bool IsPathDuplicate(const OUString &_rPath)
Definition: optjava.cxx:890
void SetExperimentalMode(bool bSet)
static SVT_DLLPUBLIC OUString GetImageId(const INetURLObject &rURL, bool bBig=false)
void ClearJavaList()
Definition: optjava.cxx:314
JFW_E_FAILED_VERSION
sal_uInt64 nRequirements
RESTART_REASON_EXP_FEATURES
javaFrameworkError jfw_findAllJREs(std::vector< std::unique_ptr< JavaInfo >> *pparInfo)
std::unique_ptr< weld::Button > m_xClassPathBtn
Definition: optjava.hxx:72
RESTART_REASON_ASSIGNING_JAVAPARAMETERS
OUString m_sAddDialogText
Definition: optjava.hxx:59
OUString getFSysPath(FSysStyle eStyle, sal_Unicode *pDelimiter=nullptr) const
#define TOOLS_WARN_EXCEPTION(area, stream)
void SetClassPath(const OUString &_rPath)
Definition: optjava.cxx:919
#define DBG_ASSERT(sCon, aError)
OUString sLocation
std::unique_ptr< weld::Button > m_xAddPathBtn
Definition: optjava.hxx:181
SvxJavaParameterDlg(weld::Window *pParent)
Definition: optjava.cxx:596
void jfw_unlock()
javaFrameworkError jfw_getUserClassPath(OUString *ppCP)
javaFrameworkError jfw_getSelectedJRE(std::unique_ptr< JavaInfo > *ppInfo)
int i
TRISTATE_FALSE
float u
javaFrameworkError jfw_setVMParameters(std::vector< OUString > const &arOptions)
void EnableEditButton()
Definition: optjava.hxx:142
rtl::Reference< ::svt::DialogClosedListener > xDialogListener
Definition: optjava.hxx:64
std::unique_ptr< SvxJavaClassPathDlg > m_xPathDlg
Definition: optjava.hxx:76
virtual ~SvxJavaParameterDlg() override
Definition: optjava.cxx:619
void SetParameters(std::vector< OUString > const &rParams)
Definition: optjava.cxx:736
#define JFW_FEATURE_ACCESSBRIDGE
javaFrameworkError jfw_setSelectedJRE(JavaInfo const *pInfo)
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
void SetTitle(const OUString &rNewTitle)
std::unique_ptr< weld::Label > m_xAddDialogText
Definition: optjava.hxx:82
void SetMacroRecorderMode(bool bSet)
void EnableRemoveButton()
Definition: optjava.hxx:137
const OUString & GetWorkPath() const
void jfw_lock()
RESTART_REASON_ASSIGNING_FOLDERS
virtual ~SvxJavaOptionsPage() override
Definition: optjava.cxx:131
weld::Window * GetFrameWeld() const
std::unique_ptr< weld::Button > m_xAddArchiveBtn
Definition: optjava.hxx:180
void SetNeedsRestart(svtools::RestartReason eReason)
Definition: treeopt.cxx:1900
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
OUString sVendor
virtual void Reset(const SfxItemSet *rSet) override
Definition: optjava.cxx:561
virtual void FillUserData() override
Definition: optjava.cxx:589
std::unique_ptr< weld::CheckButton > m_xJavaEnableCB
Definition: optjava.hxx:67
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: optjava.cxx:468
std::vector< OUString > GetParameters() const
Definition: optjava.cxx:719
void DisableRemoveButton()
Definition: optjava.hxx:152
RET_OK
RESTART_REASON_JAVA
virtual ~SvxJavaClassPathDlg() override
Definition: optjava.cxx:768
std::unique_ptr< weld::TreeView > m_xJavaList
Definition: optjava.hxx:68
virtual short run()
Reference< XComponentContext > getProcessComponentContext()
SfxOkDialogController * GetDialogController() const
void SetInvokeHandler(const Link< Timer *, void > &rLink)
void DisableAssignButton()
Definition: optjava.hxx:147
virtual short run() override
Definition: optjava.cxx:712
std::vector< std::unique_ptr< JavaInfo > > m_aAddedInfos
Definition: optjava.hxx:62
void AddJRE(JavaInfo const *_pInfo)
Definition: optjava.cxx:359
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
void ClearJavaInfo()
Definition: optjava.cxx:305
javaFrameworkError
JFW_E_NONE
IMPL_LINK_NOARG(SvxJavaOptionsPage, EnableHdl_Impl, weld::Button &, void)
Definition: optjava.cxx:141
std::unique_ptr< weld::Entry > m_xParameterEdit
Definition: optjava.hxx:124
sal_Int32 nPos
javaFrameworkError jfw_getEnabled(bool *pbEnabled)
std::unique_ptr< weld::Label > m_xJavaPathText
Definition: optjava.hxx:69
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
void DisableEditButton()
Definition: optjava.hxx:157
std::unique_ptr< weld::Button > m_xParameterBtn
Definition: optjava.hxx:71
IMPL_LINK(SvxJavaOptionsPage, CheckHdl_Impl, const row_col &, rRowCol, void)
Definition: optjava.cxx:147
std::unique_ptr< weld::TreeView > m_xAssignedList
Definition: optjava.hxx:126
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo