Author: sdzmitrovich
Date: 2009-05-09 07:22:20 -0400 (Sat, 09 May 2009)
New Revision: 15143
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4206
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java 2009-05-09
08:19:38 UTC (rev 15142)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java 2009-05-09
11:22:20 UTC (rev 15143)
@@ -11,6 +11,7 @@
package org.jboss.tools.jst.web.ui.wizards.css;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.dialogs.IPageChangedListener;
@@ -62,6 +63,17 @@
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.workbench = workbench;
this.selection = selection;
+
+ IResource selectedResource = (IResource) selection.getFirstElement();
+ if (selectedResource != null) {
+ if (selectedResource.getType() == IFile.FILE
+ && !WizardNewCssClassPage.CSS_FILE_EXTENSION
+ .equals(selectedResource.getFileExtension())) {
+ selectedResource = selectedResource.getParent();
+ }
+ classDescription.setCssFile(selectedResource);
+ }
+
}
/**
@@ -107,12 +119,12 @@
}
public class CSSClassDescription{
- private IFile cssFile;
+ private IResource cssFile;
private String cssClassName;
- public IFile getCssFile() {
+ public IResource getCssFile() {
return cssFile;
}
- public void setCssFile(IFile cssFile) {
+ public void setCssFile(IResource cssFile) {
this.cssFile = cssFile;
}
public String getCssClassName() {
@@ -138,7 +150,7 @@
* @param pageName
*/
public NewCSSClassWizardPage() {
- super("newCSSClassWizard");
+ super("newCSSClassWizard"); //$NON-NLS-1$
setTitle(WebUIMessages.WIZARD_TITLE);
setDescription(WebUIMessages.WIZARD_DESCRIPTION);
@@ -180,7 +192,7 @@
//set console configuration as treeViewer input
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == editFilePage){
- dialog.setCurrentFile(classDescription.getCssFile());
+ dialog.setCurrentFile((IFile) classDescription.getCssFile());
dialog.reinit();
dialog.addNewStyleClass(classDescription.cssClassName);
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java 2009-05-09
08:19:38 UTC (rev 15142)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java 2009-05-09
11:22:20 UTC (rev 15143)
@@ -16,7 +16,6 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
@@ -38,7 +37,6 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.common.FileExtensionFilter;
import org.jboss.tools.jst.web.ui.wizards.css.NewCSSClassWizard.CSSClassDescription;
import org.jboss.tools.jst.web.ui.wizards.messages.WebUIMessages;
-import org.w3c.dom.css.CSSFontFaceRule;
/**
* @author Sergey Dzmitrovich
@@ -47,10 +45,9 @@
public class WizardNewCssClassPage extends WizardPage implements ModifyListener {
private final static String REQUIRED_FIELD_SIGN = "*"; //$NON-NLS-1$
- private final static String CSS_FILE_EXTENSION = "css"; //$NON-NLS-1$
+ public final static String CSS_FILE_EXTENSION = "css"; //$NON-NLS-1$
private CSSClassDescription classDescription;
private final static String[] fileExtensions = { CSS_FILE_EXTENSION };
- private IFile currentFile;
private int numColumns = 3;
private Text selectFileText;
private Text classNameText;
@@ -104,30 +101,33 @@
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setAllowMultiple(false);
dialog.setDoubleClickSelects(true);
- dialog.setValidator(new ISelectionStatusValidator(){
+ dialog.setValidator(new ISelectionStatusValidator() {
public IStatus validate(Object[] selection) {
- if(selection!=null && selection.length==1) {
- if(selection[0] instanceof IFile) {
- return new Status(IStatus.OK, PlatformUI.PLUGIN_ID,
- IStatus.OK, "", //$NON-NLS-1$
- null);
+ if (selection != null && selection.length == 1) {
+ if (selection[0] instanceof IFile) {
+ return new Status(IStatus.OK,
+ PlatformUI.PLUGIN_ID, IStatus.OK, "", //$NON-NLS-1$
+ null);
}
}
return new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID,
- IStatus.ERROR, WebUIMessages.WIZARD_ERROR_FILE_SELECTION,
//$NON-NLS-1$
- null);
- }});
- if (currentFile != null) {
- dialog.setInitialSelection(currentFile);
+ IStatus.ERROR,
+ WebUIMessages.WIZARD_ERROR_FILE_SELECTION,
+ null);
+ }
+ });
+ if (classDescription.getCssFile() != null) {
+ dialog.setInitialSelection(classDescription.getCssFile());
}
dialog
.setEmptyListMessage(WebUIMessages.FILE_SELECT_DIALOG_EMPTY_MESSAGE);
if (dialog.open() == Window.OK) {
- currentFile = (IFile) dialog.getFirstResult();
- selectFileText
- .setText(currentFile.getFullPath().toString());
+ classDescription.setCssFile((IResource) dialog
+ .getFirstResult());
+ selectFileText.setText(classDescription.getCssFile()
+ .getFullPath().toString());
}
}
@@ -142,6 +142,10 @@
classNameText.setFont(parent.getFont());
classNameText.addModifyListener(this);
+ if (classDescription.getCssFile() != null)
+ selectFileText.setText(classDescription.getCssFile().getFullPath()
+ .toString());
+
setControl(container);
}
@@ -157,21 +161,27 @@
public void modifyText(ModifyEvent e) {
classDescription.setCssClassName(classNameText.getText());
- classDescription.setCssFile(getCssFile(selectFileText.getText()));
+ classDescription.setCssFile(getResource(selectFileText.getText()));
getContainer().updateButtons();
}
private IFile getCssFile(String path) {
+ IResource cssFile = getResource(path);
+ if ((cssFile != null)
+ && (CSS_FILE_EXTENSION.equals(cssFile.getFileExtension()))) {
+ return (IFile) cssFile;
+ }
+ return null;
+ }
+
+ private IResource getResource(String path) {
+ IResource resource = null;
if (path != null) {
- IResource cssFile = ResourcesPlugin.getWorkspace().getRoot()
+ resource = ResourcesPlugin.getWorkspace().getRoot()
.findMember(path);
- if ((cssFile != null)
- && (CSS_FILE_EXTENSION.equals(cssFile.getFileExtension()))) {
- return (IFile) cssFile;
- }
}
- return null;
+ return resource;
}
}