0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
package com.symbian.smt.gui.smtwidgets.resources;
|
|
17 |
|
|
18 |
import java.util.HashMap;
|
|
19 |
import java.util.List;
|
|
20 |
|
|
21 |
import org.eclipse.jface.dialogs.Dialog;
|
|
22 |
import org.eclipse.jface.viewers.ISelectionProvider;
|
|
23 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
24 |
import org.eclipse.jface.viewers.ListViewer;
|
|
25 |
import org.eclipse.swt.widgets.Button;
|
|
26 |
import org.eclipse.swt.widgets.Shell;
|
|
27 |
import org.eclipse.ui.PlatformUI;
|
|
28 |
|
|
29 |
import com.symbian.smt.gui.ResourcesEnums;
|
|
30 |
import com.symbian.smt.gui.smtwidgets.AbstractMultipleEntriesWidgetAction;
|
|
31 |
import com.symbian.smt.gui.smtwidgets.XmlFileSelectionDialog;
|
|
32 |
|
|
33 |
/**
|
|
34 |
* This is the action that adds a new command line option to the list of
|
|
35 |
* assigned options.
|
|
36 |
*
|
|
37 |
* @author barbararosi-schwartz
|
|
38 |
*
|
|
39 |
*/
|
|
40 |
class AddResourceFileAction extends AbstractMultipleEntriesWidgetAction {
|
|
41 |
|
|
42 |
private HashMap<ResourcesEnums, List<CheckableResourceFilename>> resourceFilesMap;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* The option that has been entered by the user or null if the user
|
|
46 |
* cancelled the operation.
|
|
47 |
*/
|
|
48 |
private String newFileLocation = null;
|
|
49 |
|
|
50 |
AddResourceFileAction(
|
|
51 |
Button button,
|
|
52 |
ISelectionProvider filesViewer,
|
|
53 |
HashMap<ResourcesEnums, List<CheckableResourceFilename>> resourceFilesMap,
|
|
54 |
ListViewer resourceTypesViewer) {
|
|
55 |
super(resourceTypesViewer, "Add...", button);
|
|
56 |
|
|
57 |
this.resourceFilesMap = resourceFilesMap;
|
|
58 |
|
|
59 |
setEnabled(false);
|
|
60 |
}
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Returns the option that was entered by the user.
|
|
64 |
*
|
|
65 |
* @return the option that was entered by the user (or null if the user
|
|
66 |
* cancelled the operation)
|
|
67 |
*/
|
|
68 |
String getNewFileLocation() {
|
|
69 |
return newFileLocation;
|
|
70 |
}
|
|
71 |
|
|
72 |
/**
|
|
73 |
* Creates and displays an InputDialogWithWarning that collects the new
|
|
74 |
* option entered by the user. The dialog is equipped with a
|
|
75 |
* DialogInputValidator object that automatically performs validation on the
|
|
76 |
* user's input.
|
|
77 |
* <p>
|
|
78 |
* When the dialog is dismissed, the action changes the model to reflect the
|
|
79 |
* new addition.
|
|
80 |
* </p>
|
|
81 |
*/
|
|
82 |
@Override
|
|
83 |
public void run() {
|
|
84 |
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
|
85 |
.getShell();
|
|
86 |
String dialogTitle = "New Resource File";
|
|
87 |
String dialogMessage = "Enter the path or URL to the resource file";
|
|
88 |
String initialPath = "";
|
|
89 |
String[] filterNames = { "*.xml" };
|
|
90 |
ResourcesEnums selectedResourceType = ResourcesWidgetHelper
|
|
91 |
.getSelectedResourceType((ListViewer) selectionProvider);
|
|
92 |
List<CheckableResourceFilename> checkableFilenames = ResourcesWidgetHelper
|
|
93 |
.getCheckableResourceFilenames(selectedResourceType,
|
|
94 |
resourceFilesMap);
|
|
95 |
|
|
96 |
ResourceFileSelectionValidator validator = new ResourceFileSelectionValidator(
|
|
97 |
selectedResourceType, checkableFilenames);
|
|
98 |
XmlFileSelectionDialog dialog = new XmlFileSelectionDialog(shell,
|
|
99 |
dialogTitle, dialogMessage, initialPath, filterNames, validator);
|
|
100 |
|
|
101 |
dialog.open();
|
|
102 |
|
|
103 |
if (dialog.getReturnCode() == Dialog.CANCEL) {
|
|
104 |
newFileLocation = null;
|
|
105 |
return;
|
|
106 |
}
|
|
107 |
|
|
108 |
newFileLocation = dialog.getValue();
|
|
109 |
|
|
110 |
// Adding the newly added file to the resource files
|
|
111 |
// map.
|
|
112 |
// Automatic checking of the related checkbox and
|
|
113 |
// addition
|
|
114 |
// to the selected resource files map is handled by the
|
|
115 |
// <code>handleMultipleCheckRules()</code> method in the ResourcesWidget
|
|
116 |
// class,
|
|
117 |
// which is also used for user checks/unchecks.
|
|
118 |
if (newFileLocation.length() != 0) {
|
|
119 |
checkableFilenames.add(new CheckableResourceFilename(
|
|
120 |
newFileLocation));
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
/**
|
|
125 |
* This action is enabled if a resource type has been selected by the user.
|
|
126 |
*/
|
|
127 |
@Override
|
|
128 |
public void selectionChanged(IStructuredSelection selection) {
|
|
129 |
ResourcesEnums selectedResourceType = ResourcesWidgetHelper
|
|
130 |
.getSelectedResourceType((ListViewer) selectionProvider);
|
|
131 |
|
|
132 |
if (selectedResourceType == null) {
|
|
133 |
setEnabled(false);
|
|
134 |
} else {
|
|
135 |
setEnabled(true);
|
|
136 |
}
|
|
137 |
}
|
|
138 |
|
|
139 |
}
|