Author: sdzmitrovich
Date: 2009-03-02 10:45:31 -0500 (Mon, 02 Mar 2009)
New Revision: 13914
Added:
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/messages/
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3869
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2009-03-02
15:43:43 UTC (rev 13913)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/cssdialog/CSSClassDialog.java 2009-03-02
15:45:31 UTC (rev 13914)
@@ -164,7 +164,7 @@
if (currentFile == null) {
currentFile = Util.getActiveCssFile();
}
- currentClassStyle = Util.getActivePageCSSSelectorIfAny();
+// currentClassStyle = Util.getActivePageCSSSelectorIfAny();
}
/**
@@ -484,7 +484,7 @@
* Add New Class to CSS Class Dialog
* @param styleClassName - name of new style class
*/
- protected void addNewStyleClass(String styleClassName) {
+ public void addNewStyleClass(String styleClassName) {
applyButton.setEnabled(true);
styleChanged = true;
currentClassStyle = styleClassName;
@@ -649,8 +649,9 @@
if (file != null) {
// create CSS Model
cssModel = new CSSModel(file);
+ currentClassStyle = null;
+ classCombo.removeAll();
classCombo.setEnabled(true);
- classCombo.removeAll();
// set file path to corresponding text field
if (useRelativePathPath) {
text.setText(file.getProjectRelativePath().toOSString());
@@ -665,19 +666,19 @@
// fill in ComboBox component with CSS model selectors
// List<Selector> selectors = cssModel.getSelectors();
List<String> selectors = cssModel.getSelectorLabels();
- int selectedIndex = -1;
for (int i = 0; i < selectors.size(); i++) {
// Selector value = selectors.get(i);
String label = selectors.get(i);
classCombo.add(/*value.getValue()*/ label);
- if (currentClassStyle != null &&
currentClassStyle.equals(/*value.getValue()*/label)) {
- selectedIndex = i;
- }
+
}
- if (currentClassStyle != null && selectedIndex == -1) {
+ /*
+ *
+ */
+ if (currentClassStyle != null) {
classCombo.setText(currentClassStyle);
} else {
- classCombo.select(selectedIndex);
+ classCombo.select(0);
}
classCombo.setToolTipText(cssModel.getCSSText(currentClassStyle));
@@ -790,8 +791,10 @@
public void releaseResources() {
- if (cssModel != null)
+ if (cssModel != null){
cssModel.releaseModel();
+ cssModel = null;
+ }
}
/**
@@ -920,4 +923,13 @@
}
}
}
+
+ public void reinit(){
+ releaseResources();
+ initCSSModel(currentFile, true,true);
+ }
+
+ public void setCurrentFile(IFile currentFile) {
+ this.currentFile = currentFile;
+ }
}
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-03-02
15:43:43 UTC (rev 13913)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/NewCSSClassWizard.java 2009-03-02
15:45:31 UTC (rev 13914)
@@ -10,10 +10,14 @@
******************************************************************************/
package org.jboss.tools.jst.web.ui.wizards.css;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.IDialogPage;
+import org.eclipse.jface.dialogs.IPageChangedListener;
+import org.eclipse.jface.dialogs.PageChangedEvent;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
@@ -24,13 +28,14 @@
import org.jboss.tools.jst.jsp.outline.cssdialog.CSSClassDialog;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogEvent;
import org.jboss.tools.jst.jsp.outline.cssdialog.events.MessageDialogListener;
+import org.jboss.tools.jst.web.ui.wizards.messages.WebUIMessages;
/**
* New CSS class wizard.
*/
public class NewCSSClassWizard extends Wizard implements INewWizard {
- private static final String WIZARD_WINDOW_TITLE = "CSS Style Class
Editor";
+ private CSSClassDescription classDescription = new CSSClassDescription();
// workbench selection when the wizard was started
protected IStructuredSelection selection;
@@ -38,18 +43,20 @@
protected IWorkbench workbench;
// wizard contains only one page
- private NewCSSClassWizardPage page;
+ private NewCSSClassWizardPage editFilePage;
- /**
- * Constructor for SampleNewWizard.
- */
- public NewCSSClassWizard() {
- super();
- setWindowTitle(WIZARD_WINDOW_TITLE);
-
- }
+ private WizardNewCssClassPage selectFilePage;
/**
+ * Constructor for SampleNewWizard.
+ */
+ public NewCSSClassWizard() {
+ super();
+ setWindowTitle(WebUIMessages.WIZARD_WINDOW_TITLE);
+ }
+
+
+ /**
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
@@ -57,138 +64,174 @@
this.selection = selection;
}
- /**
- * Adding the page to the wizard.
- */
- @Override
+ /**
+ * Adding the page to the wizard.
+ */
+ @Override
public void addPages() {
- page = new NewCSSClassWizardPage();
- addPage(page);
- }
- /**
- * This method is called when 'Finish' button is pressed in the wizard. We
- * will create an operation and run it using wizard as execution context.
- */
- @Override
+ selectFilePage = new WizardNewCssClassPage(classDescription);
+ editFilePage = new NewCSSClassWizardPage();
+ addPage(selectFilePage);
+ addPage(editFilePage);
+ }
+
+ /**
+ * This method is called when 'Finish' button is pressed in the wizard. We
+ * will create an operation and run it using wizard as execution context.
+ */
+ @Override
public boolean performFinish() {
- page.saveChanges();
+ editFilePage.saveChanges();
- return true;
- }
+ return true;
+ }
- /**
- * @see org.eclipse.jface.wizard.IWizard#canFinish()
- */
- @Override
+ /**
+ * @see org.eclipse.jface.wizard.IWizard#canFinish()
+ */
+ @Override
public boolean canFinish() {
- return page.canFinish;
+ return selectFilePage.canFlipToNextPage()
+ && getContainer().getCurrentPage() == editFilePage
+ && editFilePage.canFinish;
}
- /**
- * @see org.eclipse.jface.wizard.IWizard#performCancel()
- */
- @Override
- public boolean performCancel() {
- page.cancel();
- return true;
- }
+ /**
+ * @see org.eclipse.jface.wizard.IWizard#performCancel()
+ */
+ @Override
+ public boolean performCancel() {
+ editFilePage.cancel();
+ return true;
+ }
+
+ public class CSSClassDescription{
+ private IFile cssFile;
+ private String cssClassName;
+ public IFile getCssFile() {
+ return cssFile;
+ }
+ public void setCssFile(IFile cssFile) {
+ this.cssFile = cssFile;
+ }
+ public String getCssClassName() {
+ return cssClassName;
+ }
+ public void setCssClassName(String cssClassName) {
+ this.cssClassName = cssClassName;
+ }
+ }
- /**
- * Class representing the first page of the wizard.
- */
- private class NewCSSClassWizardPage extends WizardPage {
+ /**
+ * Class representing the first page of the wizard.
+ */
+ private class NewCSSClassWizardPage extends WizardPage {
- // TODO: take out to the property manager file
- final static String WIZARD_TITLE = "CSS Class";
- final static String WIZARD_DESCRIPTION = "Create New CSS Class";
+ private CSSClassDialog dialog;
- private CSSClassDialog dialog;
+ boolean canFinish = false;
- boolean canFinish = false;
+ /**
+ * Constructor for SampleNewWizardPage.
+ *
+ * @param pageName
+ */
+ public NewCSSClassWizardPage() {
+ super("newCSSClassWizard");
+ setTitle(WebUIMessages.WIZARD_TITLE);
+ setDescription(WebUIMessages.WIZARD_DESCRIPTION);
+
+ }
- /**
- * Constructor for SampleNewWizardPage.
- *
- * @param pageName
- */
- public NewCSSClassWizardPage() {
- super("newCSSClassWizard");
- setTitle(WIZARD_TITLE);
- setDescription(WIZARD_DESCRIPTION);
- }
+ /**
+ * @see IDialogPage#createControl(Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ container.setLayout(layout);
- /**
- * @see IDialogPage#createControl(Composite)
- */
- public void createControl(Composite parent) {
- Composite container = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
-
- // Initialize CSS dialog that is integrated to CSS wizard.
- // Also it can be used separately without integration to wizard component.
- dialog = new CSSClassDialog(getShell(), selection, true);
- dialog.addMessageDialogListener(new MessageDialogListener() {
+ // Initialize CSS dialog that is integrated to CSS wizard.
+ // Also it can be used separately without integration to wizard
+ // component.
+ dialog = new CSSClassDialog(getShell(), selection, true);
+ dialog.addMessageDialogListener(new MessageDialogListener() {
public void throwMessage(MessageDialogEvent event) {
if (event != null) {
IStatus status = event.getOperationStatus();
if (status != null) {
applyToStatusLine(status);
}
- getWizard().getContainer().updateButtons();
+ getWizard().getContainer().updateButtons();
}
}
- });
- dialog.createDialog(container);
- setControl(container);
+ });
- }
+ dialog.createDialog(container);
+ setControl(container);
+
+ if (getWizard().getContainer() instanceof WizardDialog){
+ WizardDialog wd = (WizardDialog) getWizard().getContainer();
+ wd.addPageChangedListener(new IPageChangedListener(){
- /**
- * Save page model.
- */
- public void saveChanges() {
- dialog.saveChanges(true);
- }
+ //set console configuration as treeViewer input
+ public void pageChanged(PageChangedEvent event) {
+ if (event.getSelectedPage() == NewCSSClassWizardPage.this){
+ dialog.setCurrentFile(classDescription.getCssFile());
+ dialog.reinit();
+ dialog.addNewStyleClass(classDescription.cssClassName);
+ }
+ }});
+ }
- /**
- * Handle cancel operation correctly.
- */
- public void cancel() {
- dialog.closeDialog();
- }
+ }
- /**
- * Applies the status to the status line of a dialog page.
- */
- private void applyToStatusLine(IStatus status) {
- String message= status.getMessage();
- if (message.length() == 0) {
- message = null;
- }
- switch (status.getSeverity()) {
- case IStatus.OK:
- setErrorMessage(null);
- setMessage(message);
- canFinish = true;
- break;
- case IStatus.WARNING:
- setErrorMessage(null);
- canFinish = true;
- setMessage(message, WizardPage.WARNING);
- break;
- case IStatus.INFO:
- setErrorMessage(null);
- canFinish = true;
- setMessage(message, WizardPage.INFORMATION);
- break;
- default:
- setErrorMessage(message);
- setMessage(null);
- canFinish = false;
- break;
- }
- }
- }
+ /**
+ * Save page model.
+ */
+ public void saveChanges() {
+ dialog.saveChanges(true);
+ }
+
+ /**
+ * Handle cancel operation correctly.
+ */
+ public void cancel() {
+ dialog.closeDialog();
+ }
+
+ /**
+ * Applies the status to the status line of a dialog page.
+ */
+ private void applyToStatusLine(IStatus status) {
+ String message = status.getMessage();
+ if (message.length() == 0) {
+ message = null;
+ }
+ switch (status.getSeverity()) {
+ case IStatus.OK:
+ setErrorMessage(null);
+ setMessage(message);
+ canFinish = true;
+ break;
+ case IStatus.WARNING:
+ setErrorMessage(null);
+ canFinish = true;
+ setMessage(message, WizardPage.WARNING);
+ break;
+ case IStatus.INFO:
+ setErrorMessage(null);
+ canFinish = true;
+ setMessage(message, WizardPage.INFORMATION);
+ break;
+ default:
+ setErrorMessage(message);
+ setMessage(null);
+ canFinish = false;
+ break;
+ }
+ }
+ }
+
}
Added:
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
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/css/WizardNewCssClassPage.java 2009-03-02
15:45:31 UTC (rev 13914)
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+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.resources.ResourcesPlugin;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.model.BaseWorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+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
+ *
+ */
+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$
+ private CSSClassDescription classDescription;
+ private final static String[] fileExtensions = { CSS_FILE_EXTENSION };
+ private IFile currentFile;
+ private int numColumns = 3;
+ private Text selectFileText;
+ private Text classNameText;
+
+ /**
+ * @param pageName
+ */
+ public WizardNewCssClassPage(CSSClassDescription classDescription) {
+ super("WizardNewCssClassPage"); //$NON-NLS-1$
+ this.classDescription = classDescription;
+ setTitle(WebUIMessages.WIZARD_TITLE);
+ setDescription(WebUIMessages.WIZARD_DESCRIPTION);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
+ * .Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = numColumns;
+ layout.makeColumnsEqualWidth = false;
+ container.setLayout(layout);
+
+ Label selectFileLabel = new Label(container, SWT.NONE);
+ selectFileLabel.setText(WebUIMessages.FILE_SELECT_LABEL
+ + REQUIRED_FIELD_SIGN);
+
+ selectFileText = new Text(container, SWT.SINGLE | SWT.BORDER);
+ selectFileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ selectFileText.setFont(parent.getFont());
+ selectFileText.addModifyListener(this);
+
+ Button selectFileButton = new Button(container, SWT.NONE);
+ selectFileButton.setText(WebUIMessages.FILE_SELECT_BUTTON);
+ selectFileButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
+ getShell(), new WorkbenchLabelProvider(),
+ new BaseWorkbenchContentProvider());
+ dialog.addFilter(new FileExtensionFilter(fileExtensions));
+ dialog.setTitle(WebUIMessages.FILE_SELECT_DIALOG_TITLE);
+ dialog.setMessage(WebUIMessages.FILE_SELECT_DIALOG_MESSAGE);
+ dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+ dialog.setAllowMultiple(false);
+ dialog.setDoubleClickSelects(true);
+ if (currentFile != null) {
+ dialog.setInitialSelection(currentFile);
+ }
+ dialog
+ .setEmptyListMessage(WebUIMessages.FILE_SELECT_DIALOG_EMPTY_MESSAGE);
+
+ if (dialog.open() == Window.OK) {
+ currentFile = (IFile) dialog.getFirstResult();
+ selectFileText
+ .setText(currentFile.getFullPath().toString());
+ }
+
+ }
+ });
+
+ Label classNameLabel = new Label(container, SWT.NONE);
+ classNameLabel.setText(WebUIMessages.CSS_CLASS_NAME_LABEL
+ + REQUIRED_FIELD_SIGN);
+
+ classNameText = new Text(container, SWT.SINGLE | SWT.BORDER);
+ classNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ classNameText.setFont(parent.getFont());
+ classNameText.addModifyListener(this);
+
+ setControl(container);
+ }
+
+ @Override
+ public boolean canFlipToNextPage() {
+ if ((classNameText.getText().length() != 0)
+ && (getCssFile(selectFileText.getText()) != null)) {
+ return true;
+ }
+ return false;
+ }
+
+ public void modifyText(ModifyEvent e) {
+
+ classDescription.setCssClassName(classNameText.getText());
+ classDescription.setCssFile(getCssFile(selectFileText.getText()));
+ getContainer().updateButtons();
+
+ }
+
+ private IFile getCssFile(String path) {
+ if (path != null) {
+ IResource cssFile = ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(path);
+ if ((cssFile != null)
+ && (CSS_FILE_EXTENSION.equals(cssFile.getFileExtension()))) {
+ return (IFile) cssFile;
+ }
+ }
+ return null;
+ }
+
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/WebUIMessages.java 2009-03-02
15:45:31 UTC (rev 13914)
@@ -0,0 +1,23 @@
+package org.jboss.tools.jst.web.ui.wizards.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class WebUIMessages extends NLS {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.jst.web.ui.wizards.messages.messages"; //$NON-NLS-1$
+ public static String FILE_SELECT_DIALOG_EMPTY_MESSAGE;
+ public static String FILE_SELECT_DIALOG_MESSAGE;
+ public static String FILE_SELECT_DIALOG_TITLE;
+ public static String FILE_SELECT_LABEL;
+ public static String FILE_SELECT_BUTTON;
+ public static String CSS_CLASS_NAME_LABEL;
+ public static String WIZARD_WINDOW_TITLE;
+ public static String WIZARD_TITLE;
+ public static String WIZARD_DESCRIPTION;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, WebUIMessages.class);
+ }
+
+ private WebUIMessages() {
+ }
+}
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/messages/messages.properties 2009-03-02
15:45:31 UTC (rev 13914)
@@ -0,0 +1,10 @@
+FILE_SELECT_DIALOG_EMPTY_MESSAGE=No CSS file in the current project
+FILE_SELECT_DIALOG_MESSAGE=Select CSS file from the tree:
+FILE_SELECT_DIALOG_TITLE=CSS File Selection
+FILE_SELECT_LABEL=CSS File
+FILE_SELECT_BUTTON=Browse
+CSS_CLASS_NAME_LABEL=CSS Class
+WIZARD_WINDOW_TITLE=CSS Style Class Editor
+WIZARD_TITLE=CSS Class
+WIZARD_DESCRIPTION=Create New CSS Class
+