From: nakyoung2.choi Date: Thu, 22 May 2014 09:05:56 +0000 (+0900) Subject: PROP : Re-implementation remove selector. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F21519%2F1;p=sdk%2Fide%2Fweb-ui-builder-eplugin.git PROP : Re-implementation remove selector. Advanced Create/Remove/Change CssSelectorCommand. Change-Id: Ifd14f7b8fefa2b2c20ca8c28c058d5ec5d860bf4 Signed-off-by: nakyoung2.choi --- diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ChangeCssSelectorCommand.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ChangeCssSelectorCommand.java index 0a14baf..a1b7932 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ChangeCssSelectorCommand.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ChangeCssSelectorCommand.java @@ -40,23 +40,28 @@ abstract public class ChangeCssSelectorCommand extends Command { private Part model; private String selectorName; private PageData pageData; - private CssFile appliedCssFile; + private CssFile cssFile; private CssSelector newSelector = null; public ChangeCssSelectorCommand(Object model, PageData pageData, String selectorName) { - setModel(model); + this.model = (Part) model; this.pageData = pageData; this.selectorName = selectorName; } - - public void setModel(Object model) { - this.model = (Part) model; - } - abstract public void execute2(); - abstract public void undo2(); - + + + @Override + public boolean canExecute() { + if (pageData == null || model == null || selectorName == null || selectorName.isEmpty()) { + return false; + } else { + cssFile = pageData.getCurrentCssFile(); + return true; + } + } + /** * Do not override this method. You must override execute2(). */ @@ -69,37 +74,10 @@ abstract public class ChangeCssSelectorCommand extends Command { // create selector selector = new CssSelector(selectorName); selectorMap.put(selectorName, selector); - appliedCssFile = pageData.getCurrentCssFile(); - appliedCssFile.addCssSelector(selector); + cssFile.addCssSelector(selector); newSelector = selector; - } - - // Setting all selector of Part - // List appliedCssFileList = pageData.getAppliedCssFiles(); - // int index = appliedCssFileList.indexOf(appliedCssFile); - // int size = appliedCssFileList.size(); - // Map allMap = model.getAllSelectorMap(); - // boolean skip = false; - // CssSelector cloneSelector = selector.cloneCssSelector(selectorName); - // if (size - 1 == index) { - // allMap.put(selectorName, cloneSelector); - // } else { - // for (int i = index + 1; i <= size - 1; i++) { - // CssSelector targetSelector = allMap.get(selectorName); - // if (targetSelector != null) { - // for (CssStyle style : selector.getStyles()) { - // targetSelector.getStyleMap().put(style.getKey(), style); - // } - // skip = true; - // break; - // } - // } - // if (!skip) { - // allMap.put(selectorName, cloneSelector); - // } - // } - + execute2(); if (NScreenUtil.isLogEnabled()) { @@ -116,7 +94,7 @@ abstract public class ChangeCssSelectorCommand extends Command { if (newSelector != null) { model.getEditSelectorMap().remove(newSelector); model.getAllSelectorMap().remove(newSelector); - appliedCssFile.removeCssSelector(newSelector); + cssFile.removeCssSelector(newSelector); } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/CreateCssSelectorCommand.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/CreateCssSelectorCommand.java index a9635af..58199ac 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/CreateCssSelectorCommand.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/CreateCssSelectorCommand.java @@ -30,52 +30,45 @@ import org.tizen.webuibuilder.model.css.CssSelector; import org.tizen.webuibuilder.model.page.PageData; -public class CreateCssSelectorCommand extends ChangeCssSelectorCommand { +public class CreateCssSelectorCommand extends Command { - public CreateCssSelectorCommand(PageData pageData, Part model, String selectorName) { - super(model, pageData, selectorName); + private Part model; + private String selectorName; + private PageData pageData; + private CssSelector selector; + private CssFile cssFile; + + public CreateCssSelectorCommand(Part model, PageData pageData, String selectorName) { + this.pageData = pageData; + this.model = model; + this.selectorName = selectorName; } @Override public boolean canExecute() { - Part model = getModel(); - if (getSelectorName() != null && !getSelectorName().isEmpty() && model != null) { - return true; + if (selectorName != null && !selectorName.isEmpty() && model != null) { + if (model.getSelector(selectorName) == null) { + cssFile = pageData.getCurrentCssFile(); + return true; + } else { + return false; + } } else { return false; } } -// @Override -// public void execute() { -// if (selector == null) { -// selector = new CssSelector(selectorName); -// } -// -// cssFile.addCssSelector(selector); -// part.addSelector(selector.getSelectorName(), selector); -// } -// -// @Override -// public void undo() { -// cssFile.removeCssSelector(selector); -// part.removeSelector(selector.getSelectorName()); -// } - @Override - public void execute2() { - String selectorName = getSelectorName(); - CssSelector selector = new CssSelector(selectorName); - Part model = getModel(); + public void execute() { + selector = new CssSelector(selectorName); model.addSelector(selectorName, selector); + cssFile.addCssSelector(selector); } @Override - public void undo2() { - // TODO Auto-generated method stub - String selectorName = getSelectorName(); - Part model = getModel(); + public void undo() { model.removeSelector(selectorName); + cssFile.removeCssSelector(selector); } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/RemoveCssSelectorCommand.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/RemoveCssSelectorCommand.java index d9954d6..90d4fe9 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/RemoveCssSelectorCommand.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/RemoveCssSelectorCommand.java @@ -27,38 +27,34 @@ import org.eclipse.gef.commands.Command; import org.tizen.webuibuilder.model.Part; import org.tizen.webuibuilder.model.css.CssFile; import org.tizen.webuibuilder.model.css.CssSelector; +import org.tizen.webuibuilder.model.page.PageData; public class RemoveCssSelectorCommand extends Command { - private CssFile cssFile; - private CssSelector selector; + private Part model; private String selectorName; - private Part part; + private PageData pageData; + private CssSelector selector; + private CssFile cssFile; - public RemoveCssSelectorCommand(CssFile cssFile, Part part, CssSelector selector) { - this.cssFile = cssFile; - this.part = part; - this.selector = selector; - } - public RemoveCssSelectorCommand(CssFile cssFile, Part part, String selectorName) { - this.cssFile = cssFile; - this.part = part; + public RemoveCssSelectorCommand(Part part, PageData pageData, String selectorName) { + this.pageData = pageData; + this.model = part; this.selectorName = selectorName; } @Override public boolean canExecute() { - if (cssFile == null || part == null) { + if (pageData == null || model == null || selectorName == null || selectorName.isEmpty()) { return false; - } else if (selector != null) { - return true; } else { - selector = cssFile.getSelector(selectorName); + selector = model.getSelector(selectorName); if (selector == null) { return false; } else { + cssFile = pageData.getCurrentCssFile(); return true; } } @@ -66,15 +62,13 @@ public class RemoveCssSelectorCommand extends Command { @Override public void execute() { - if (selector != null) { - cssFile.removeCssSelector(selector); - part.removeSelector(selector.getSelectorName()); - } + cssFile.removeCssSelector(selector); + model.removeSelector(selectorName); } @Override public void undo() { cssFile.addCssSelector(selector); - part.addSelector(selector.getSelectorName(), selector); + model.addSelector(selectorName, selector); } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ResetCssSelectorCommand.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ResetCssSelectorCommand.java index 3984ae6..824a0ab 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ResetCssSelectorCommand.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/ResetCssSelectorCommand.java @@ -29,9 +29,11 @@ import org.tizen.webuibuilder.model.Part; import org.tizen.webuibuilder.model.css.CssFile; import org.tizen.webuibuilder.model.css.CssSelector; import org.tizen.webuibuilder.model.css.CssStyle; +import org.tizen.webuibuilder.model.page.PageData; public class ResetCssSelectorCommand extends Command { + private PageData pageData; private CssFile cssFile; private CssSelector selector; private String selectorName; @@ -39,48 +41,35 @@ public class ResetCssSelectorCommand extends Command { private Collection styles; - public ResetCssSelectorCommand(CssFile cssFile, Part part, CssSelector selector) { - this.cssFile = cssFile; - this.part = part; - this.selector = selector; - } - - public ResetCssSelectorCommand(CssFile cssFile, Part part, String selectorName) { - this.cssFile = cssFile; + public ResetCssSelectorCommand(Part part, PageData pageData, String selectorName) { + this.pageData = pageData; this.part = part; this.selectorName = selectorName; } @Override public boolean canExecute() { - if (cssFile == null || part == null) { + if (pageData == null || part == null || selectorName == null || selectorName.isEmpty()) { return false; - } else if (selector != null) { - selectorName = selector.getSelectorName(); - if (selectorName == null || selectorName.isEmpty()) { - return false; - } else { - return true; - } } else { - selector = cssFile.getSelector(selectorName); + selector = part.getSelector(selectorName); if (selector == null) { return false; - } else { - return true; } + cssFile = pageData.getCurrentCssFile(); + return true; } } @Override public void execute() { - styles = cssFile.resetCssSelector(selectorName); + CssSelector clonedSelector = selector.cloneCssSelector(selectorName); + styles = clonedSelector.getStyles(); part.resetSelector(selectorName); } @Override public void undo() { - selector.setStyles(styles); part.setSelectorStyles(selectorName, styles); } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/DesignerEditPart.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/DesignerEditPart.java index 2a62728..3b9df46 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/DesignerEditPart.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/DesignerEditPart.java @@ -191,6 +191,9 @@ public class DesignerEditPart extends HoverViewerEditPart { PageData pageData = ((HoverBrowserViewer) getViewer()).getPageData(); Part model = (Part) getModel(); CssSelector selector = model.getSelector(selectorName); + if (selector == null) { + return; + } List appliedCssFileList = pageData.getAppliedCssFiles(); int index = appliedCssFileList.indexOf(pageData.getCurrentCssFile()); int size = appliedCssFileList.size(); diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java index f974604..8443c9f 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java @@ -56,7 +56,10 @@ import org.tizen.webuibuilder.model.IPartListener; import org.tizen.webuibuilder.model.Part; import org.tizen.webuibuilder.model.PartEvent; import org.tizen.webuibuilder.model.css.CssEvent; +import org.tizen.webuibuilder.model.css.CssFile; +import org.tizen.webuibuilder.model.css.CssSelector; import org.tizen.webuibuilder.model.css.ICssListener; +import org.tizen.webuibuilder.model.page.PageData; import org.tizen.webuibuilder.ui.editor.ruler.DesignerGuide; @@ -232,6 +235,24 @@ public class HoverViewerEditPart extends AbstractGraphicalEditPart implements IP @Override public void cssSelectorRemoved(CssEvent event) { + String selectorName = event.getSelectorName(); + if (selectorName == null || selectorName.isEmpty()) { + return; + } else { + PageData pageData = ((HoverBrowserViewer) getViewer()).getPageData(); + Part model = (Part) getModel(); + + model.getAllSelectorMap().remove(selectorName); + + List appliedCssFileList = pageData.getAppliedCssFiles(); + for (int i = 0; i < appliedCssFileList.size(); i++) { + CssFile cssFile = appliedCssFileList.get(i); + CssSelector selector = cssFile.getSelector(selectorName); + if (selector != null) { + model.addSelectorWhenReadCss(selector); + } + } + } ((HoverBrowserViewer) getViewer()).updateStyle(); } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/Part.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/Part.java index d853647..95f9f7a 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/Part.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/Part.java @@ -1584,7 +1584,6 @@ public class Part implements ISerializer { CssSelector cssSelector = getSelector(selectorName); editSelectorMap.remove(selectorName); - allSelectorMap.remove(selectorName); fireEvent(new CssEvent(EventType.CSS_SELECTOR_REMOVED, this, cssSelector.getSelectorName(), null, null)); @@ -1608,7 +1607,6 @@ public class Part implements ISerializer { removeSelector(selectorName); } else { editSelectorMap.remove(selectorName); - allSelectorMap.remove(selectorName); } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/pagetemplate/action/CssSelecotrAction.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/pagetemplate/action/CssSelecotrAction.java index 3828ec4..4dbdf6c 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/pagetemplate/action/CssSelecotrAction.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/pagetemplate/action/CssSelecotrAction.java @@ -95,8 +95,7 @@ public class CssSelecotrAction extends SelectionAction { CommandStack commandStack = designEditPartViewer.getEditDomain().getCommandStack(); Command command = - new CreateCssSelectorCommand(designEditPartViewer.getPageData(), - part, result); + new CreateCssSelectorCommand(part, designEditPartViewer.getPageData(), result); commandStack.execute(command); } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java index cc98825..6ac05b7 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssSelectorCategoryComposite.java @@ -53,6 +53,7 @@ import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.webuibuilder.BuilderConstants; +import org.tizen.webuibuilder.bridge.DesignerGoingBridge; import org.tizen.webuibuilder.model.css.CssFile; import org.tizen.webuibuilder.model.css.CssSelector; import org.tizen.webuibuilder.model.css.ICssSelectorListener; @@ -74,6 +75,7 @@ public class CssSelectorCategoryComposite extends CategoryComposite implements I private List currentSelectors; private Map> selectorMap = new HashMap>(); private Composite buttons; + private DesignerGoingBridge goingBridge; private ExpansionAdapter expansionListener = new ExpansionAdapter() { @Override @@ -91,13 +93,14 @@ public class CssSelectorCategoryComposite extends CategoryComposite implements I }; public CssSelectorCategoryComposite(Composite parent, String name, CssFile cssFile, - CssStyleEventDelegater delegater) { + CssStyleEventDelegater delegater, DesignerGoingBridge goingBridge) { super(parent, name, BuilderConstants.EMPTY, null); this.cssFile = cssFile; if (cssFile != null) { this.cssFile.addCssSelectorListener(this); } this.delegater = delegater; + this.goingBridge = goingBridge; createListBox(); } @@ -267,13 +270,8 @@ public class CssSelectorCategoryComposite extends CategoryComposite implements I return; } - PageDesigner pageDesigner = getPageDesigner(); - if (pageDesigner == null) { - return; - } - CSSSelectorDialog dialog = new CSSSelectorDialog(getShell(), widgetId); - dialog.setGoingBridge(pageDesigner.getViewer().getGoingBridge()); + dialog.setGoingBridge(goingBridge); Rectangle rect = listBox.getBounds(); Point pt = listBox.toDisplay(rect.x, rect.y); @@ -294,17 +292,6 @@ public class CssSelectorCategoryComposite extends CategoryComposite implements I } - private PageDesigner getPageDesigner() { - IEditorPart editor = - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() - .getActiveEditor(); - if (editor != null && editor instanceof PageDesigner) { - return (PageDesigner) editor; - } else { - return null; - } - } - public String getDefaultSelectorName() { return currentSelectors.get(0); } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleEventDelegater.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleEventDelegater.java index 0fb24ea..15766e5 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleEventDelegater.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleEventDelegater.java @@ -235,28 +235,18 @@ public class CssStyleEventDelegater implements ICssSelectorListener, IValueChang return; } else { CreateCssSelectorCommand command = - new CreateCssSelectorCommand(pageData, styleTab.getModel(), selectorName); + new CreateCssSelectorCommand(styleTab.getModel(), pageData, selectorName); commandStack.execute(command); } } - public void removeCssSelector(CssSelector selector) { - if (selector == null) { - return; - } else { - RemoveCssSelectorCommand command = - new RemoveCssSelectorCommand(cssFile, styleTab.getModel(), selector); - commandStack.execute(command); - } - } - public void removeCssSelector(String selectorName) { if (selectorName == null || selectorName.isEmpty()) { return; } else { RemoveCssSelectorCommand command = - new RemoveCssSelectorCommand(cssFile, styleTab.getModel(), selectorName); + new RemoveCssSelectorCommand(styleTab.getModel(), pageData, selectorName); commandStack.execute(command); } } @@ -265,7 +255,7 @@ public class CssStyleEventDelegater implements ICssSelectorListener, IValueChang if (selectorName == null || selectorName.isEmpty()) { return; } else { - ResetCssSelectorCommand command = new ResetCssSelectorCommand(cssFile, styleTab.getModel(), selectorName); + ResetCssSelectorCommand command = new ResetCssSelectorCommand(styleTab.getModel(), pageData, selectorName); commandStack.execute(command); } } @@ -324,14 +314,14 @@ public class CssStyleEventDelegater implements ICssSelectorListener, IValueChang @Override public void cssSelectorRemoved(CssEvent event) { - // TODO Auto-generated method stub - + styleTab.setDefaultSelector(); + refreshStyleTab(); } @Override public void cssPropertyChanged(CssEvent event) { String key = event.getPropertyKey(); - if (key != null) { + if (key != null && !key.isEmpty()) { String value = event.getPropertyValue(); refreshStyleTab(key, value); } @@ -339,5 +329,6 @@ public class CssStyleEventDelegater implements ICssSelectorListener, IValueChang @Override public void needRefresh(CssEvent event) { + refreshStyleTab(); } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java index 583c1a3..603d165 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/properties/style/CssStyleTab.java @@ -95,8 +95,9 @@ import org.tizen.webuibuilder.utility.ResourceManager; */ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener { - // CommandStack private CommandStack commandStack; + private DesignerGoingBridge goingBridge; + // CSS Model private CssDescriptor cssDescriptor; @@ -119,7 +120,7 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener TableItem item = (TableItem) e.item; String selectorName = item.getText(); if (setSelector(selectorName)) { - refresh(); + refresh(); } } @@ -169,6 +170,7 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener setText(PropertiesConstant.STYLE); this.commandStack = commandStack; this.cssDescriptor = cssDescriptor; + this.goingBridge = goingBridge; cssDelegater = new CssStyleEventDelegater(commandStack, cssDescriptor, this, pageData, goingBridge); animDelegater = new CssStyleAnimationEventDelegater(commandStack, this); @@ -272,9 +274,12 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener } private void createCssSelectorCategory() { - cssCategory = new CssSelectorCategoryComposite(categoryContainer, "CSS Selector", cssFile, cssDelegater); + cssCategory = + new CssSelectorCategoryComposite(categoryContainer, "CSS Selector", cssFile, + cssDelegater, goingBridge); cssCategory.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - + + cssCategory.addSelectorSelectionListener(selectorSelectionListener); cssCategory.addExpansionListener(new ExpansionAdapter() { @Override @@ -285,7 +290,7 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener } }); } - + /** * createStyleContents */ @@ -351,20 +356,25 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener /** * Sets a current {@link CssFile}. * - * @param cssFile + * @param inputCssFile * a current {@link CssFile} * @return true if this class set CssFile, and false otherwise */ - public boolean setCssFile(CssFile cssFile) { - if (this.cssFile == null || (cssFile != null && !this.cssFile.equals(cssFile))) { - this.cssFile = cssFile; - /* TODO Log */ - cssDelegater.setCssFile(cssFile); - setDefaultSelector(); - return true; - } else { + public boolean setCssFile(CssFile inputCssFile) { + if (inputCssFile == null || inputCssFile.equals(cssFile)) { return false; + } else if (cssFile != null) { + cssFile.removeCssSelectorListener(cssDelegater); + cssFile.removeCssSelectorListener(cssCategory); } + + cssFile = inputCssFile; + cssFile.addCssSelectorListener(cssDelegater); + cssFile.addCssSelectorListener(cssCategory); + + cssDelegater.setCssFile(inputCssFile); + setDefaultSelector(); + return true; } @@ -386,26 +396,15 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener } } - /** - * addCssListener + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.custom.CTabItem#dispose() */ - private void addCssListener() { - if (cssFile != null) { - cssFile.addCssSelectorListener(cssDelegater); - } - if (currentSelector != null) { - currentSelector.addCssSelectorListener(cssDelegater); - } + @Override + public void dispose() { + removeModelListener(); - if (cssCategory != null) { - cssCategory.addSelectorSelectionListener(selectorSelectionListener); - } - } - - /** - * removeCssListener - */ - private void removeCssListener() { if (cssFile != null) { cssFile.removeCssSelectorListener(cssDelegater); } @@ -413,21 +412,9 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener if (currentSelector != null) { currentSelector.removeCssSelectorListener(cssDelegater); } - if (cssCategory != null) { cssCategory.removeSelectorSelectionListener(selectorSelectionListener); } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.swt.custom.CTabItem#dispose() - */ - @Override - public void dispose() { - removeModelListener(); - removeCssListener(); clear(); noContent.dispose(); multiContent.dispose(); @@ -468,7 +455,7 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener /** * Sets default selector. */ - private void setDefaultSelector() { + public void setDefaultSelector() { Part model = getModel(); if (model == null || model.isDocumentPart() || cssFile == null) { return; @@ -488,17 +475,21 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener private boolean setSelector(String selectorName) { CssSelector cssSelector = cssFile.getSelector(selectorName); - - if (cssSelector != null) { - if (currentSelector != null && currentSelector.equals(cssSelector)) { - return false; - } else { - currentSelector = cssSelector; - } - } else { + if (cssSelector == null) { currentSelector = new CssSelector(selectorName); + } else if (cssSelector.equals(currentSelector)) { + return false; + } else if (currentSelector != null) { + currentSelector.removeCssSelectorListener(cssDelegater); + currentSelector = cssSelector; + } else { + // currentSelector == null + currentSelector = cssSelector; } - + + + currentSelector.addCssSelectorListener(cssDelegater); + if (customCss != null && !customCss.isDisposed()) { customCss.setCssSelector(currentSelector); } @@ -508,9 +499,6 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener // CSS Delegater cssDelegater.setCssSelector(currentSelector); -// if (cssCategory != null && !cssCategory.isDisposed()) { -// cssCategory.setSelector(selectorName); -// } return true; } @@ -1474,10 +1462,8 @@ public class CssStyleTab extends PropertiesTabItem implements IPageDataListener @Override public void pageChanged(PageDataEvent e) { if (setCssFile(e.getPage().getCurrentCssFile())) { + setDefaultSelector(); refresh(); - removeCssListener(); - addCssListener(); -// addListeners(); } }