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  {
299  aExpertConfigDlg.Reset();//initialize and reset function
300  }
301 
302  if (RET_OK == aExpertConfigDlg.run())
303  {
304  aExpertConfigDlg.FillItemSet();//save changes if there are any
305  }
306 }
307 
309 {
310 #if HAVE_FEATURE_JAVA
311  m_parJavaInfo.clear();
312 #else
313  (void) this;
314 #endif
315 }
316 
318 {
319 #if HAVE_FEATURE_JAVA
320  weld::WaitObject aWaitObj(GetFrameWeld());
321  javaFrameworkError eErr = jfw_findAllJREs( &m_parJavaInfo );
322  if ( JFW_E_NONE == eErr )
323  {
324  for (auto const & pInfo: m_parJavaInfo)
325  {
326  AddJRE( pInfo.get() );
327  }
328  }
329 
330  for (auto const & pInfo: m_aAddedInfos)
331  {
332  AddJRE( pInfo.get() );
333  }
334 
335  std::unique_ptr<JavaInfo> pSelectedJava;
336  eErr = jfw_getSelectedJRE( &pSelectedJava );
337  if ( !(JFW_E_NONE == eErr && pSelectedJava) )
338  return;
339 
340  sal_Int32 i = 0;
341  for (auto const & pCmpInfo: m_parJavaInfo)
342  {
343  if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pSelectedJava.get() ) )
344  {
345  HandleCheckEntry(i);
346  break;
347  }
348  ++i;
349  }
350 #else
351  (void) this;
352 #endif
353 }
354 
355 
356 void SvxJavaOptionsPage::AddJRE( JavaInfo const * _pInfo )
357 {
358 #if HAVE_FEATURE_JAVA
359  int nPos = m_xJavaList->n_children();
360  m_xJavaList->append();
361  m_xJavaList->set_toggle(nPos, TRISTATE_FALSE, 0);
362  m_xJavaList->set_text(nPos, _pInfo->sVendor, 1);
363  m_xJavaList->set_text(nPos, _pInfo->sVersion, 2);
364  OUString sFeature;
366  sFeature = m_sAccessibilityText;
367  m_xJavaList->set_text(nPos, sFeature, 3);
368 
369  INetURLObject aLocObj(_pInfo->sLocation);
370  OUString sLocation = aLocObj.getFSysPath(FSysStyle::Detect);
371  m_xJavaList->set_id(nPos, sLocation);
372 #else
373  (void) this;
374  (void)_pInfo;
375 #endif
376 }
377 
379 {
380  m_xJavaList->select(nCheckedRow);
381  for (int i = 0, nCount = m_xJavaList->n_children(); i < nCount; ++i)
382  {
383  // we have radio button behavior -> so uncheck the other entries
384  m_xJavaList->set_toggle(i, i == nCheckedRow ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
385  }
386 }
387 
388 void SvxJavaOptionsPage::AddFolder( const OUString& _rFolder )
389 {
390 #if HAVE_FEATURE_JAVA
391  bool bStartAgain = true;
392  std::unique_ptr<JavaInfo> pInfo;
393  javaFrameworkError eErr = jfw_getJavaInfoByPath( _rFolder, &pInfo );
394  if ( JFW_E_NONE == eErr && pInfo )
395  {
396  sal_Int32 nPos = 0;
397  bool bFound = false;
398  for (auto const & pCmpInfo: m_parJavaInfo)
399  {
400  if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pInfo.get() ) )
401  {
402  bFound = true;
403  break;
404  }
405  ++nPos;
406  }
407 
408  if ( !bFound )
409  {
410  for (auto const & pCmpInfo: m_aAddedInfos)
411  {
412  if ( jfw_areEqualJavaInfo( pCmpInfo.get(), pInfo.get() ) )
413  {
414  bFound = true;
415  break;
416  }
417  ++nPos;
418  }
419  }
420 
421  if ( !bFound )
422  {
423  jfw_addJRELocation( pInfo->sLocation );
424  AddJRE( pInfo.get() );
425  m_aAddedInfos.push_back( std::move(pInfo) );
426  nPos = m_xJavaList->n_children() - 1;
427  }
428 
429  HandleCheckEntry(nPos);
430  bStartAgain = false;
431  }
432  else if ( JFW_E_NOT_RECOGNIZED == eErr )
433  {
434  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
435  VclMessageType::Warning, VclButtonsType::Ok,
436  CuiResId(RID_SVXSTR_JRE_NOT_RECOGNIZED)));
437  xBox->run();
438  }
439  else if ( JFW_E_FAILED_VERSION == eErr )
440  {
441  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
442  VclMessageType::Warning, VclButtonsType::Ok,
443  CuiResId(RID_SVXSTR_JRE_FAILED_VERSION)));
444  xBox->run();
445  }
446 
447  if ( bStartAgain )
448  {
449  xFolderPicker->setDisplayDirectory( _rFolder );
450  Application::PostUserEvent( LINK( this, SvxJavaOptionsPage, StartFolderPickerHdl ) );
451  }
452 #else
453  (void) this;
454  (void)_rFolder;
455 #endif
456 }
457 
459 {
460  OfaTreeOptionsDialog* pParentDlg(static_cast<OfaTreeOptionsDialog*>(GetDialogController()));
461  if (pParentDlg)
462  pParentDlg->SetNeedsRestart(eReason);
463 }
464 
465 std::unique_ptr<SfxTabPage> SvxJavaOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
466 {
467  return std::make_unique<SvxJavaOptionsPage>(pPage, pController, *rAttrSet);
468 }
469 
471 {
472  bool bModified = false;
473 
474  if ( m_xExperimentalCB->get_state_changed_from_saved() )
475  {
476  SvtMiscOptions aMiscOpt;
477  aMiscOpt.SetExperimentalMode( m_xExperimentalCB->get_active() );
478  bModified = true;
480  }
481 
482  if ( m_xMacroCB->get_state_changed_from_saved() )
483  {
484  SvtMiscOptions aMiscOpt;
485  aMiscOpt.SetMacroRecorderMode(m_xMacroCB->get_active());
486  bModified = true;
487  }
488 
489 #if HAVE_FEATURE_JAVA
491  if (m_xParamDlg)
492  {
493  eErr = jfw_setVMParameters(m_xParamDlg->GetParameters());
494  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setVMParameters");
495  bModified = true;
496  }
497 
498  if (m_xPathDlg)
499  {
500  OUString sPath(m_xPathDlg->GetClassPath());
501  if (m_xPathDlg->GetOldPath() != sPath)
502  {
503  eErr = jfw_setUserClassPath( sPath );
504  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setUserClassPath");
505  bModified = true;
506  }
507  }
508 
509  sal_uInt32 nCount = m_xJavaList->n_children();
510  for (sal_uInt32 i = 0; i < nCount; ++i)
511  {
512  if (m_xJavaList->get_toggle(i, 0) == TRISTATE_TRUE)
513  {
514  JavaInfo const * pInfo;
515  if ( i < m_parJavaInfo.size() )
516  pInfo = m_parJavaInfo[i].get();
517  else
518  pInfo = m_aAddedInfos[ i - m_parJavaInfo.size() ].get();
519 
520  std::unique_ptr<JavaInfo> pSelectedJava;
521  eErr = jfw_getSelectedJRE( &pSelectedJava );
522  if ( JFW_E_NONE == eErr || JFW_E_INVALID_SETTINGS == eErr )
523  {
524  if (!pSelectedJava || !jfw_areEqualJavaInfo( pInfo, pSelectedJava.get() ) )
525  {
526  if ( jfw_isVMRunning() ||
528  {
530  }
531 
532  eErr = jfw_setSelectedJRE( pInfo );
533  SAL_WARN_IF(JFW_E_NONE != eErr, "cui.options", "SvxJavaOptionsPage::FillItemSet(): error in jfw_setSelectedJRE");
534  bModified = true;
535  }
536  }
537  break;
538  }
539  }
540 
541  bool bEnabled = false;
542  eErr = jfw_getEnabled( &bEnabled );
543  DBG_ASSERT( JFW_E_NONE == eErr,
544  "SvxJavaOptionsPage::FillItemSet(): error in jfw_getEnabled" );
545  if ( bEnabled != m_xJavaEnableCB->get_active() )
546  {
547  eErr = jfw_setEnabled( m_xJavaEnableCB->get_active() );
548  DBG_ASSERT( JFW_E_NONE == eErr,
549  "SvxJavaOptionsPage::FillItemSet(): error in jfw_setEnabled" );
550  bModified = true;
551  }
552 #endif
553 
554  return bModified;
555 }
556 
557 
558 void SvxJavaOptionsPage::Reset( const SfxItemSet* /*rSet*/ )
559 {
560  ClearJavaInfo();
561  m_xJavaList->clear();
562 
563  SvtMiscOptions aMiscOpt;
564 
565 #if HAVE_FEATURE_JAVA
566  bool bEnabled = false;
567  javaFrameworkError eErr = jfw_getEnabled( &bEnabled );
568  if ( eErr != JFW_E_NONE )
569  bEnabled = false;
570  m_xJavaEnableCB->set_active(bEnabled);
571  EnableHdl_Impl(*m_xJavaEnableCB);
572 #else
573  m_xJavaEnableCB->set_active(false);
574  m_xJavaEnableCB->set_sensitive(false);
575 #endif
576 
577  m_xExperimentalCB->set_active( aMiscOpt.IsExperimentalMode() );
578  m_xExperimentalCB->save_state();
579  m_xMacroCB->set_active(aMiscOpt.IsMacroRecorderMode());
580  m_xMacroCB->save_state();
581 
583 }
584 
585 
587 {
588  SetUserData( OUString() );
589 }
590 
591 // class SvxJavaParameterDlg ---------------------------------------------
592 
594  : GenericDialogController(pParent, "cui/ui/javastartparametersdialog.ui",
595  "JavaStartParameters")
596  , m_xParameterEdit(m_xBuilder->weld_entry("parameterfield"))
597  , m_xAssignBtn(m_xBuilder->weld_button("assignbtn"))
598  , m_xAssignedList(m_xBuilder->weld_tree_view("assignlist"))
599  , m_xRemoveBtn(m_xBuilder->weld_button("removebtn"))
600  , m_xEditBtn(m_xBuilder->weld_button("editbtn"))
601 {
602  m_xAssignedList->set_size_request(m_xAssignedList->get_approximate_digit_width() * 54,
603  m_xAssignedList->get_height_rows(6));
604  m_xParameterEdit->connect_changed( LINK( this, SvxJavaParameterDlg, ModifyHdl_Impl ) );
605  m_xAssignBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, AssignHdl_Impl ) );
606  m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, RemoveHdl_Impl ) );
607  m_xEditBtn->connect_clicked( LINK( this, SvxJavaParameterDlg, EditHdl_Impl ) );
608  m_xAssignedList->connect_changed( LINK( this, SvxJavaParameterDlg, SelectHdl_Impl ) );
609  m_xAssignedList->connect_row_activated( LINK( this, SvxJavaParameterDlg, DblClickHdl_Impl ) );
610 
611  ModifyHdl_Impl(*m_xParameterEdit);
614 }
615 
617 {
618 }
619 
621 {
622  OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
623  m_xAssignBtn->set_sensitive(!sParam.isEmpty());
624 }
625 
627 {
628  OUString sParam = comphelper::string::strip(m_xParameterEdit->get_text(), ' ');
629  if (sParam.isEmpty())
630  return;
631 
632  int nPos = m_xAssignedList->find_text(sParam);
633  if (nPos == -1)
634  {
635  m_xAssignedList->append_text(sParam);
636  m_xAssignedList->select(m_xAssignedList->n_children() - 1);
637  }
638  else
639  m_xAssignedList->select(nPos);
640  m_xParameterEdit->set_text(OUString());
641  ModifyHdl_Impl(*m_xParameterEdit);
642  EnableEditButton();
643  EnableRemoveButton();
644 }
645 
647 {
648  EditParameter();
649 }
650 
652 {
653  EnableEditButton();
654  EnableRemoveButton();
655 }
656 
658 {
659  EditParameter();
660  return true;
661 }
662 
664 {
665  int nPos = m_xAssignedList->get_selected_index();
666  if (nPos != -1)
667  {
668  m_xAssignedList->remove(nPos);
669  int nCount = m_xAssignedList->n_children();
670  if (nCount)
671  {
672  if (nPos >= nCount)
673  nPos = nCount - 1;
674  m_xAssignedList->select(nPos);
675  }
676  else
677  {
678  DisableEditButton();
679  }
680  }
681  EnableRemoveButton();
682 }
683 
685 {
686  int nPos = m_xAssignedList->get_selected_index();
687  m_xParameterEdit->set_text(OUString());
688 
689  if (nPos == -1)
690  return;
691 
692  InputDialog aParamEditDlg(m_xDialog.get(), CuiResId(RID_SVXSTR_JAVA_START_PARAM));
693  OUString editableClassPath = m_xAssignedList->get_selected_text();
694  aParamEditDlg.SetEntryText(editableClassPath);
695  aParamEditDlg.HideHelpBtn();
696 
697  if (!aParamEditDlg.run())
698  return;
699  OUString editedClassPath = comphelper::string::strip(aParamEditDlg.GetEntryText(), ' ');
700 
701  if ( !editedClassPath.isEmpty() && editableClassPath != editedClassPath )
702  {
703  m_xAssignedList->remove(nPos);
704  m_xAssignedList->insert_text(nPos, editedClassPath);
705  m_xAssignedList->select(nPos);
706  }
707 }
708 
710 {
711  m_xParameterEdit->grab_focus();
712  m_xAssignedList->select(-1);
713  return GenericDialogController::run();
714 }
715 
716 std::vector< OUString > SvxJavaParameterDlg::GetParameters() const
717 {
718  int nCount = m_xAssignedList->n_children();
719  std::vector< OUString > aParamList;
720  aParamList.reserve(nCount);
721  for (int i = 0; i < nCount; ++i)
722  aParamList.push_back(m_xAssignedList->get_text(i));
723  return aParamList;
724 }
725 
727 {
731 }
732 
733 void SvxJavaParameterDlg::SetParameters( std::vector< OUString > const & rParams )
734 {
735  m_xAssignedList->clear();
736  for (auto const & sParam: rParams)
737  {
738  m_xAssignedList->append_text(sParam);
739  }
742 }
743 
744 
745 // class SvxJavaClassPathDlg ---------------------------------------------
746 
748  : GenericDialogController(pParent, "cui/ui/javaclasspathdialog.ui", "JavaClassPath")
749  , m_xPathList(m_xBuilder->weld_tree_view("paths"))
750  , m_xAddArchiveBtn(m_xBuilder->weld_button("archive"))
751  , m_xAddPathBtn(m_xBuilder->weld_button("folder"))
752  , m_xRemoveBtn(m_xBuilder->weld_button("remove"))
753 {
754  m_xPathList->set_size_request(m_xPathList->get_approximate_digit_width() * 54,
755  m_xPathList->get_height_rows(8));
756  m_xAddArchiveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddArchiveHdl_Impl ) );
757  m_xAddPathBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, AddPathHdl_Impl ) );
758  m_xRemoveBtn->connect_clicked( LINK( this, SvxJavaClassPathDlg, RemoveHdl_Impl ) );
759  m_xPathList->connect_changed( LINK( this, SvxJavaClassPathDlg, SelectHdl_Impl ) );
760 
761  // set initial focus to path list
762  m_xPathList->grab_focus();
763 }
764 
766 {
767 }
768 
770 {
771  sfx2::FileDialogHelper aDlg(TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, m_xDialog.get());
772  aDlg.SetTitle( CuiResId( RID_SVXSTR_ARCHIVE_TITLE ) );
773  aDlg.AddFilter( CuiResId( RID_SVXSTR_ARCHIVE_HEADLINE ), "*.jar;*.zip" );
774  OUString sFolder;
775  if (m_xPathList->count_selected_rows() > 0)
776  {
777  osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sFolder);
778  // best effort
779  }
780  if (sFolder.isEmpty())
781  sFolder = SvtPathOptions().GetWorkPath();
782  aDlg.SetDisplayDirectory( sFolder );
783  if ( aDlg.Execute() == ERRCODE_NONE )
784  {
785  OUString sURL = aDlg.GetPath();
786  OUString sFile;
787  if (osl::FileBase::getSystemPathFromFileURL(sURL, sFile) == osl::FileBase::E_None)
788  {
789  INetURLObject aURL( sURL );
790  if ( !IsPathDuplicate( sFile ) )
791  {
792  m_xPathList->append("", sFile, SvFileInformationManager::GetImageId(aURL));
793  m_xPathList->select(m_xPathList->n_children() - 1);
794  }
795  else
796  {
797  OUString sMsg( CuiResId( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
798  sMsg = sMsg.replaceFirst( "%1", sFile );
799  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
800  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
801  xBox->run();
802  }
803  }
804  else
805  {
806  OUString sMsg( CuiResId( RID_SVXSTR_CANNOTCONVERTURL_ERR ) );
807  sMsg = sMsg.replaceFirst( "%1", sURL );
808  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
809  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
810  xBox->run();
811  }
812  }
813  EnableRemoveButton();
814 }
815 
817 {
819  Reference < XFolderPicker2 > xFolderPicker = FolderPicker::create(xContext);
820 
821  OUString sOldFolder;
822  if (m_xPathList->count_selected_rows() > 0)
823  {
824  osl::FileBase::getFileURLFromSystemPath(m_xPathList->get_selected_text(), sOldFolder);
825  // best effort
826  }
827  if (sOldFolder.isEmpty())
828  sOldFolder = SvtPathOptions().GetWorkPath();
829  xFolderPicker->setDisplayDirectory( sOldFolder );
830  if ( xFolderPicker->execute() == ExecutableDialogResults::OK )
831  {
832  OUString sFolderURL( xFolderPicker->getDirectory() );
833  INetURLObject aURL( sFolderURL );
834  OUString sNewFolder;
835  if (osl::FileBase::getSystemPathFromFileURL(sFolderURL, sNewFolder)
836  == osl::FileBase::E_None)
837  {
838  if ( !IsPathDuplicate( sNewFolder ) )
839  {
840  m_xPathList->append("", sNewFolder, SvFileInformationManager::GetImageId(aURL));
841  m_xPathList->select(m_xPathList->n_children() - 1);
842  }
843  else
844  {
845  OUString sMsg( CuiResId( RID_SVXSTR_MULTIFILE_DBL_ERR ) );
846  sMsg = sMsg.replaceFirst( "%1", sNewFolder );
847  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
848  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
849  xBox->run();
850  }
851  }
852  else
853  {
854  OUString sMsg( CuiResId( RID_SVXSTR_CANNOTCONVERTURL_ERR ) );
855  sMsg = sMsg.replaceFirst( "%1", sFolderURL );
856  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
857  VclMessageType::Warning, VclButtonsType::Ok, sMsg));
858  xBox->run();
859  }
860  }
861  EnableRemoveButton();
862 }
863 
865 {
866  int nPos = m_xPathList->get_selected_index();
867  if (nPos != -1)
868  {
869  m_xPathList->remove(nPos);
870  int nCount = m_xPathList->n_children();
871  if (nCount)
872  {
873  if (nPos >= nCount)
874  nPos = nCount - 1;
875  m_xPathList->select( nPos );
876  }
877  }
878 
879  EnableRemoveButton();
880 }
881 
883 {
884  EnableRemoveButton();
885 }
886 
887 bool SvxJavaClassPathDlg::IsPathDuplicate( const OUString& _rPath )
888 {
889  bool bRet = false;
890  int nCount = m_xPathList->n_children();
891  for (int i = 0; i < nCount; ++i)
892  {
893  if ( m_xPathList->get_text(i) == _rPath )
894  {
895  bRet = true;
896  break;
897  }
898  }
899 
900  return bRet;
901 }
902 
904 {
905  OUStringBuffer sPath;
906  int nCount = m_xPathList->n_children();
907  for (int i = 0; i < nCount; ++i)
908  {
909  if (!sPath.isEmpty())
910  sPath.append(CLASSPATH_DELIMITER);
911  sPath.append(m_xPathList->get_text(i));
912  }
913  return sPath.makeStringAndClear();
914 }
915 
916 void SvxJavaClassPathDlg::SetClassPath( const OUString& _rPath )
917 {
918  if ( m_sOldPath.isEmpty() )
919  m_sOldPath = _rPath;
920  m_xPathList->clear();
921  if (!_rPath.isEmpty())
922  {
923  sal_Int32 nIdx = 0;
924  do
925  {
926  OUString sToken = _rPath.getToken( 0, CLASSPATH_DELIMITER, nIdx );
927  OUString sURL;
928  osl::FileBase::getFileURLFromSystemPath(sToken, sURL); // best effort
929  INetURLObject aURL( sURL );
930  m_xPathList->append("", sToken, SvFileInformationManager::GetImageId(aURL));
931  }
932  while (nIdx>=0);
933  // select first entry
934  m_xPathList->select(0);
935  }
936  SelectHdl_Impl(*m_xPathList);
937 }
938 
939 /* 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)
URL aURL
OUString sVersion
void HandleCheckEntry(int nCheckedRow)
Definition: optjava.cxx:378
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:183
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:124
OUString m_sInstallText
Definition: optjava.hxx:57
std::unique_ptr< weld::Button > m_xRemoveBtn
Definition: optjava.hxx:126
#define CLASSPATH_DELIMITER
Definition: optjava.cxx:61
OUString GetClassPath() const
Definition: optjava.cxx:903
javaFrameworkError jfw_getVMParameters(std::vector< OUString > *parOptions)
std::unique_ptr< weld::Button > m_xEditBtn
Definition: optjava.hxx:127
SvxJavaClassPathDlg(weld::Window *pParent)
Definition: optjava.cxx:747
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:388
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:458
SvxJavaOptionsPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optjava.cxx:69
int nCount
virtual void Start() override
std::unique_ptr< weld::TreeView > m_xPathList
Definition: optjava.hxx:178
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optjava.cxx:470
std::unique_ptr< weld::Widget > m_xJavaFrame
Definition: optjava.hxx:84
std::unique_ptr< weld::Button > m_xAddBtn
Definition: optjava.hxx:70
std::unique_ptr< weld::Button > m_xRemoveBtn
Definition: optjava.hxx:181
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:887
void SetExperimentalMode(bool bSet)
static SVT_DLLPUBLIC OUString GetImageId(const INetURLObject &rURL, bool bBig=false)
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:916
#define DBG_ASSERT(sCon, aError)
OUString sLocation
int i
std::unique_ptr< weld::Button > m_xAddPathBtn
Definition: optjava.hxx:180
SvxJavaParameterDlg(weld::Window *pParent)
Definition: optjava.cxx:593
void jfw_unlock()
javaFrameworkError jfw_getUserClassPath(OUString *ppCP)
javaFrameworkError jfw_getSelectedJRE(std::unique_ptr< JavaInfo > *ppInfo)
TRISTATE_FALSE
float u
javaFrameworkError jfw_setVMParameters(std::vector< OUString > const &arOptions)
void EnableEditButton()
Definition: optjava.hxx:141
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:616
void SetParameters(std::vector< OUString > const &rParams)
Definition: optjava.cxx:733
#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:136
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:179
void SetNeedsRestart(svtools::RestartReason eReason)
Definition: treeopt.cxx:1921
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
OUString sVendor
virtual void Reset(const SfxItemSet *rSet) override
Definition: optjava.cxx:558
virtual void FillUserData() override
Definition: optjava.cxx:586
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:465
std::vector< OUString > GetParameters() const
Definition: optjava.cxx:716
void DisableRemoveButton()
Definition: optjava.hxx:151
RET_OK
OString strip(const OString &rIn, char c)
RESTART_REASON_JAVA
virtual ~SvxJavaClassPathDlg() override
Definition: optjava.cxx:765
Reference< XExecutableDialog > m_xDialog
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:146
virtual short run() override
Definition: optjava.cxx:709
std::vector< std::unique_ptr< JavaInfo > > m_aAddedInfos
Definition: optjava.hxx:62
void AddJRE(JavaInfo const *_pInfo)
Definition: optjava.cxx:356
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
void ClearJavaInfo()
Definition: optjava.cxx:308
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:123
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:156
std::unique_ptr< weld::Button > m_xParameterBtn
Definition: optjava.hxx:71
sal_uInt16 nPos
IMPL_LINK(SvxJavaOptionsPage, CheckHdl_Impl, const row_col &, rRowCol, void)
Definition: optjava.cxx:147
std::unique_ptr< weld::TreeView > m_xAssignedList
Definition: optjava.hxx:125
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo