1 package org
.argeo
.slc
.client
.ui
.wizards
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.argeo
.slc
.SlcException
;
8 import org
.argeo
.slc
.client
.ui
.ClientUiPlugin
;
9 import org
.argeo
.slc
.client
.ui
.SlcUiConstants
;
10 import org
.argeo
.slc
.jcr
.SlcJcrResultUtils
;
11 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
12 import org
.eclipse
.jface
.wizard
.Wizard
;
13 import org
.eclipse
.jface
.wizard
.WizardPage
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.ModifyEvent
;
16 import org
.eclipse
.swt
.events
.ModifyListener
;
17 import org
.eclipse
.swt
.events
.SelectionAdapter
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.layout
.GridData
;
20 import org
.eclipse
.swt
.layout
.GridLayout
;
21 import org
.eclipse
.swt
.widgets
.Button
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Display
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.swt
.widgets
.Text
;
26 import org
.eclipse
.ui
.ISharedImages
;
28 public class ConfirmOverwriteWizard
extends Wizard
{
30 // Define widget here to simplify getters
31 private Button overwriteBtn
, renameBtn
;
32 private Text newNameTxt
;
33 private Label newNameLbl
;
36 private String sourceNodeName
;
37 private Node targetParentNode
;
39 private String newName
;
40 private String parentRelPath
;
41 private boolean overwrite
;
43 public ConfirmOverwriteWizard(String sourceNodeName
, Node targetParentNode
) {
44 setWindowTitle("Confirm overwrite or define a new name");
45 this.sourceNodeName
= sourceNodeName
;
46 this.targetParentNode
= targetParentNode
;
50 public void addPages() {
52 addPage(new MyPage());
53 } catch (Exception e
) {
54 throw new SlcException("Cannot add page to wizard ", e
);
57 ClientUiPlugin
.getDefault().getWorkbench().getSharedImages()
58 .getImageDescriptor(ISharedImages
.IMG_LCL_LINKTO_HELP
)
62 // Expose info to the calling view
63 public boolean overwrite() {
67 public String
newName() {
72 public boolean performFinish() {
73 boolean doFinish
= false;
76 if (overwriteBtn
.getSelection())
77 doFinish
= MessageDialog
.openConfirm(Display
.getDefault()
78 .getActiveShell(), "CAUTION", "All data contained in ["
79 + (parentRelPath
!= null ? parentRelPath
: "")
81 + "] are about to be definitively destroyed. \n "
82 + "Are you sure you want to proceed ?");
88 overwrite
= overwriteBtn
.getSelection();
89 newName
= newNameTxt
.getText();
94 class MyPage
extends WizardPage
implements ModifyListener
{
98 String msg
= "An object with same name (" + sourceNodeName
99 + ") already exists at chosen target path";
101 // Add target rel path to the message
105 session
= targetParentNode
.getSession();
106 relPath
= targetParentNode
.getPath();
107 String basePath
= SlcJcrResultUtils
108 .getMyResultsBasePath(session
);
109 if (relPath
.startsWith(basePath
))
110 relPath
= relPath
.substring(basePath
.length());
111 // FIXME currently add the default base label
112 parentRelPath
= SlcUiConstants
.DEFAULT_MY_RESULTS_FOLDER_LABEL
114 } catch (RepositoryException e
) {
115 throw new SlcException("Unexpected error while defining "
116 + "target parent node rel path", e
);
118 msg
= msg
+ (parentRelPath
== null ?
"." : ": \n" + parentRelPath
);
124 public void createControl(Composite parent
) {
125 Composite composite
= new Composite(parent
, SWT
.NONE
);
126 composite
.setLayout(new GridLayout(2, false));
128 // choose between overwrite and rename
129 overwriteBtn
= new Button(composite
, SWT
.RADIO
);
130 overwriteBtn
.setText("Overwrite");
131 GridData gd
= new GridData();
132 gd
.horizontalIndent
= 30;
133 gd
.horizontalSpan
= 2;
134 overwriteBtn
.setLayoutData(gd
);
135 overwriteBtn
.setSelection(true);
137 renameBtn
= new Button(composite
, SWT
.RADIO
);
138 renameBtn
.setText("Rename");
139 renameBtn
.setSelection(false);
140 renameBtn
.setText("Rename");
142 gd
.horizontalIndent
= 30;
143 gd
.horizontalSpan
= 2;
144 renameBtn
.setLayoutData(gd
);
146 newNameLbl
= new Label(composite
, SWT
.LEAD
);
147 newNameLbl
.setText("New name");
148 newNameLbl
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false,
150 newNameLbl
.setEnabled(false);
152 newNameTxt
= new Text(composite
, SWT
.LEAD
| SWT
.BORDER
);
153 newNameTxt
.setText(sourceNodeName
);
154 newNameTxt
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true,
156 if (newNameTxt
!= null)
157 newNameTxt
.addModifyListener(this);
158 newNameTxt
.setEnabled(false);
160 SelectionAdapter sa
= new SelectionAdapter() {
161 public void widgetSelected(SelectionEvent e
) {
162 updateSelection(overwriteBtn
.getSelection());
165 overwriteBtn
.addSelectionListener(sa
);
166 renameBtn
.addSelectionListener(sa
);
169 setControl(composite
);
172 private void updateSelection(boolean overwrite
) {
173 newNameLbl
.setEnabled(!overwrite
);
174 newNameTxt
.setEnabled(!overwrite
);
176 setPageComplete(true);
181 protected String
getTechName() {
182 return newNameTxt
.getText();
185 public void modifyText(ModifyEvent event
) {
189 private void checkComplete() {
192 String newName
= newNameTxt
.getText();
193 if (newName
== null || "".equals(newName
.trim())) {
194 setMessage("Name cannot be blank or empty",
196 setPageComplete(false);
197 } else if (targetParentNode
.hasNode(newName
)) {
198 setMessage("An object with the same name already exists.",
200 setPageComplete(false);
202 setMessage("Complete", WizardPage
.INFORMATION
);
203 setPageComplete(true);
205 } catch (RepositoryException e
) {
206 throw new SlcException("Unexpected error while checking "
207 + "children node with same name", e
);