View | Details | Raw Unified | Return to bug 246787 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mtj/internal/core/util/Utils.java (-3 / +37 lines)
Lines 25-30 Link Here
25
 *     David Marques (Motorola) - Adding getSourceFolders method.
25
 *     David Marques (Motorola) - Adding getSourceFolders method.
26
 *     David Marques (Motorola) - Adding isAutobuilding
26
 *     David Marques (Motorola) - Adding isAutobuilding
27
 *     David Arag�o (Motorola)  - Add isValidFolderName
27
 *     David Arag�o (Motorola)  - Add isValidFolderName
28
 *     Fernando Rocha(Motorola) - Refactor in isValidFolderName and add methods
29
 *                                for marker management
28
 */
30
 */
29
package org.eclipse.mtj.internal.core.util;
31
package org.eclipse.mtj.internal.core.util;
30
32
Lines 53-58 Link Here
53
import org.eclipse.core.resources.IContainer;
55
import org.eclipse.core.resources.IContainer;
54
import org.eclipse.core.resources.IFile;
56
import org.eclipse.core.resources.IFile;
55
import org.eclipse.core.resources.IFolder;
57
import org.eclipse.core.resources.IFolder;
58
import org.eclipse.core.resources.IMarker;
56
import org.eclipse.core.resources.IProject;
59
import org.eclipse.core.resources.IProject;
57
import org.eclipse.core.resources.IResource;
60
import org.eclipse.core.resources.IResource;
58
import org.eclipse.core.resources.IWorkspace;
61
import org.eclipse.core.resources.IWorkspace;
Lines 1366-1375 Link Here
1366
     * @return
1369
     * @return
1367
     */
1370
     */
1368
    public static boolean isValidFolderName(String folderName) {
1371
    public static boolean isValidFolderName(String folderName) {
1369
		String property = System.getProperty("java.io.tmpdir");
1372
                IWorkspace workspace = MTJCore.getWorkspace();
1370
		File folder = new File(property, folderName);
1373
                IStatus result = workspace.validateName(folderName, IResource.FOLDER);
1371
		return (folder.exists() || folder.mkdir());
1374
		return result.isOK();
1372
	}
1375
	}
1376
    
1377
    /**
1378
     * Verifies if a file name is valid.
1379
     * @param fileName
1380
     * @return
1381
     */
1382
    public static boolean isValidFileName(String fileName) {
1383
        IWorkspace workspace = MTJCore.getWorkspace();
1384
        IStatus result = workspace.validateName(fileName, IResource.FOLDER);
1385
        return result.isOK();
1386
    }
1373
1387
1388
    /**
1389
     * Create an error marker in a resource 
1390
     * @param resource
1391
     * @param message
1392
     * @throws CoreException
1393
     */
1394
    public static void createErrorMarker(IResource resource, String message) throws CoreException {
1395
        IMarker marker = resource.createMarker(IMTJCoreConstants.JAVAME_PROBLEM_MARKER);
1396
        marker.setAttribute(IMarker.MESSAGE, message);
1397
        marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
1398
    }
1399
    
1400
    /**
1401
     * Remove all the error markers
1402
     * @param resource
1403
     * @throws CoreException
1404
     */
1405
    public static void removeAllErrorMarkers(IResource resource) throws CoreException {
1406
        resource.deleteMarkers(IMTJCoreConstants.JAVAME_PROBLEM_MARKER, false, IResource.DEPTH_ZERO);
1407
    }
1374
    
1408
    
1375
}
1409
}
(-)src/org/eclipse/mtj/internal/ui/editors/jad/form/pages/OverviewEditorPage.java (-15 / +72 lines)
Lines 13-23 Link Here
13
 *                               Configuration Manager, for Multi-configs support.
13
 *                               Configuration Manager, for Multi-configs support.
14
 *     Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874]
14
 *     Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874]
15
 *     Fernando Rocha(Motorola)- Add validation to JAR URL.
15
 *     Fernando Rocha(Motorola)- Add validation to JAR URL.
16
 *     Fernando Rocha(Motorola)- Problem marker for the description file.
16
 */
17
 */
17
package org.eclipse.mtj.internal.ui.editors.jad.form.pages;
18
package org.eclipse.mtj.internal.ui.editors.jad.form.pages;
18
19
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IWorkspace;
21
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.IExtensionRegistry;
Lines 22-28 Link Here
22
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.IExtensionRegistry;
24
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.core.runtime.Platform;
27
import org.eclipse.debug.ui.ILaunchShortcut;
26
import org.eclipse.debug.ui.ILaunchShortcut;
28
import org.eclipse.jdt.core.IJavaProject;
27
import org.eclipse.jdt.core.IJavaProject;
Lines 34-40 Link Here
34
import org.eclipse.jface.util.IPropertyChangeListener;
33
import org.eclipse.jface.util.IPropertyChangeListener;
35
import org.eclipse.jface.util.PropertyChangeEvent;
34
import org.eclipse.jface.util.PropertyChangeEvent;
36
import org.eclipse.jface.viewers.StructuredSelection;
35
import org.eclipse.jface.viewers.StructuredSelection;
37
import org.eclipse.mtj.core.MTJCore;
38
import org.eclipse.mtj.core.project.midp.IMidletSuiteProject;
36
import org.eclipse.mtj.core.project.midp.IMidletSuiteProject;
39
import org.eclipse.mtj.core.project.runtime.event.AddMTJRuntimeEvent;
37
import org.eclipse.mtj.core.project.runtime.event.AddMTJRuntimeEvent;
40
import org.eclipse.mtj.core.project.runtime.event.IMTJRuntimeChangeListener;
38
import org.eclipse.mtj.core.project.runtime.event.IMTJRuntimeChangeListener;
Lines 61-66 Link Here
61
import org.eclipse.mtj.ui.editors.jad.JADPropertiesEditorPage;
59
import org.eclipse.mtj.ui.editors.jad.JADPropertiesEditorPage;
62
import org.eclipse.swt.widgets.Composite;
60
import org.eclipse.swt.widgets.Composite;
63
import org.eclipse.swt.widgets.Control;
61
import org.eclipse.swt.widgets.Control;
62
import org.eclipse.swt.widgets.Text;
64
import org.eclipse.ui.IEditorInput;
63
import org.eclipse.ui.IEditorInput;
65
import org.eclipse.ui.IWorkbenchPart;
64
import org.eclipse.ui.IWorkbenchPart;
66
import org.eclipse.ui.PlatformUI;
65
import org.eclipse.ui.PlatformUI;
Lines 157-171 Link Here
157
    public void doSave(IProgressMonitor monitor) {
156
    public void doSave(IProgressMonitor monitor) {
158
        super.doSave(monitor);
157
        super.doSave(monitor);
159
158
159
        validateFields();
160
160
        String currentJarUrl = getPreferenceStore().getString(
161
        String currentJarUrl = getPreferenceStore().getString(
161
                IJADConstants.JAD_MIDLET_JAR_URL);
162
                IJADConstants.JAD_MIDLET_JAR_URL);
162
        
163
163
        IWorkspace workspace = MTJCore.getWorkspace();
164
        Control jarURLControl = null;
164
        IStatus result = workspace.validateName(currentJarUrl, IResource.FILE);
165
        for (FieldEditor field : fieldEditors) {
165
        if (!result.isOK()) {
166
            if (field instanceof ExtendedStringFieldEditor) {
167
                String fieldEditorLabel = field.getLabelText();
168
                if (fieldEditorLabel
169
                        .equals(MTJUIMessages.RequiredJADDesciptorsProvider_midlet_jar_url)) {
170
                    jarURLControl = ((ExtendedStringFieldEditor) field)
171
                            .getFieldEditorTextControl();
172
                    break;
173
                }
174
            }
175
        }
176
177
        if (!Utils.isValidFileName(currentJarUrl)) {
166
            getPreferenceStore().putValue(IJADConstants.JAD_MIDLET_JAR_URL,
178
            getPreferenceStore().putValue(IJADConstants.JAD_MIDLET_JAR_URL,
167
                    loadedJarUrl);
179
                    loadedJarUrl);
168
            getErrorMessageManager().removeAllMessages();
180
            getErrorMessageManager()
181
                    .removeMessage(
182
                            "textLength_" + MTJUIMessages.RequiredJADDesciptorsProvider_midlet_jar_url, jarURLControl); //$NON-NLS-1$
169
        } else if (!currentJarUrl.substring(currentJarUrl.length() - 4)
183
        } else if (!currentJarUrl.substring(currentJarUrl.length() - 4)
170
                .equalsIgnoreCase(".jar")) { //$NON-NLS-1$
184
                .equalsIgnoreCase(".jar")) { //$NON-NLS-1$
171
            getPreferenceStore().putValue(IJADConstants.JAD_MIDLET_JAR_URL,
185
            getPreferenceStore().putValue(IJADConstants.JAD_MIDLET_JAR_URL,
Lines 170-178 Link Here
170
                .equalsIgnoreCase(".jar")) { //$NON-NLS-1$
184
                .equalsIgnoreCase(".jar")) { //$NON-NLS-1$
171
            getPreferenceStore().putValue(IJADConstants.JAD_MIDLET_JAR_URL,
185
            getPreferenceStore().putValue(IJADConstants.JAD_MIDLET_JAR_URL,
172
                    loadedJarUrl);
186
                    loadedJarUrl);
173
            getErrorMessageManager().removeAllMessages();
187
            getErrorMessageManager()
188
                    .removeMessage(
189
                            "textLength_" + MTJUIMessages.RequiredJADDesciptorsProvider_midlet_jar_url, jarURLControl); //$NON-NLS-1$
174
        }
190
        }
175
        
191
176
        if (!currentJarUrl.equals(loadedJarUrl)) {
192
        if (!currentJarUrl.equals(loadedJarUrl)) {
177
            ((JADFormEditor) getEditor()).setCleanRequired(true);
193
            ((JADFormEditor) getEditor()).setCleanRequired(true);
178
        }
194
        }
Lines 188-193 Link Here
188
        }
204
        }
189
205
190
    }
206
    }
207
    
208
    /**
209
     * Validate editor fields
210
     */
211
    public void validateFields() {
212
        IFile applicationDescriptorFile = midletProject
213
                .getApplicationDescriptorFile();
214
        try {
215
            Utils.removeAllErrorMarkers(applicationDescriptorFile);
216
        } catch (CoreException e) {
217
            e.printStackTrace();
218
        }
219
220
        for (FieldEditor field : fieldEditors) {
221
            if (field instanceof ExtendedStringFieldEditor) {
222
                String fieldEditorLabel = field.getLabelText();
223
                Text control = ((ExtendedStringFieldEditor) field)
224
                        .getFieldEditorTextControl();
225
                if (!fieldEditorLabel
226
                        .equals(MTJUIMessages.RequiredJADDesciptorsProvider_midlet_jar_url)) {
227
                    if (control.getText().equals(Utils.EMPTY_STRING)) {
228
                        getErrorMessageManager()
229
                                .addMessage(
230
                                        "textLength_" + fieldEditorLabel, //$NON-NLS-1$
231
                                        MTJUIMessages.OverviewEditorPage_empty_field_error_msg,
232
                                        null, IMessageProvider.ERROR, control);
233
234
                        try {
235
                            Utils
236
                                    .createErrorMarker(
237
                                            applicationDescriptorFile,
238
                                            fieldEditorLabel
239
                                                    + ":" //$NON-NLS-1$
240
                                                    + MTJUIMessages.OverviewEditorPage_empty_field_error_msg);
241
                        } catch (CoreException e) {
242
                            e.printStackTrace();
243
                        }
244
                    }
245
                }
246
            }
247
        }
248
    }
191
249
192
    /* (non-Javadoc)
250
    /* (non-Javadoc)
193
     * @see org.eclipse.mtj.ui.editors.jad.AbstractJADEditorPage#getTitle()
251
     * @see org.eclipse.mtj.ui.editors.jad.AbstractJADEditorPage#getTitle()
Lines 248-256 Link Here
248
                        .getPreferenceName().equals(
306
                        .getPreferenceName().equals(
249
                                IJADConstants.JAD_MIDLET_JAR_URL)) {
307
                                IJADConstants.JAD_MIDLET_JAR_URL)) {
250
                    String jarFileName = (String) event.getNewValue();
308
                    String jarFileName = (String) event.getNewValue();
251
                    IWorkspace workspace = MTJCore.getWorkspace();
252
                    IStatus result = workspace.validateName(jarFileName,
253
                            IResource.FILE);
254
                    if (!jarFileName.substring(jarFileName.length() - 4)
309
                    if (!jarFileName.substring(jarFileName.length() - 4)
255
                            .equalsIgnoreCase(".jar")) { //$NON-NLS-1$
310
                            .equalsIgnoreCase(".jar")) { //$NON-NLS-1$
256
                        getErrorMessageManager()
311
                        getErrorMessageManager()
Lines 258-264 Link Here
258
                                        "textLength_" + fieldEditorLabel, //$NON-NLS-1$
313
                                        "textLength_" + fieldEditorLabel, //$NON-NLS-1$
259
                                        MTJUIMessages.J2MEProjectPropertiesPage_validatePage_jar_error,
314
                                        MTJUIMessages.J2MEProjectPropertiesPage_validatePage_jar_error,
260
                                        null, IMessageProvider.ERROR, c);
315
                                        null, IMessageProvider.ERROR, c);
261
                    } else if (!result.isOK()) {
316
                    } else if (!Utils.isValidFileName(jarFileName)) {
262
                        getErrorMessageManager()
317
                        getErrorMessageManager()
263
                                .addMessage(
318
                                .addMessage(
264
                                        "textLength_" + fieldEditorLabel, //$NON-NLS-1$
319
                                        "textLength_" + fieldEditorLabel, //$NON-NLS-1$
Lines 568-573 Link Here
568
        form.updateToolBar();
623
        form.updateToolBar();
569
624
570
        fillEditorPageBody(managedForm);
625
        fillEditorPageBody(managedForm);
626
        
627
        validateFields();
571
    }
628
    }
572
629
573
    /* (non-Javadoc)
630
    /* (non-Javadoc)

Return to bug 246787