This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 129472 - New API Request for CSS Stylebuilder to be used in VisualWeb
Summary: New API Request for CSS Stylebuilder to be used in VisualWeb
Status: RESOLVED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: CSS Visual Tools (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Marek Fukala
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-06 21:57 UTC by Winston Prakash
Modified: 2008-04-28 13:37 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Winston Prakash 2008-03-06 21:57:44 UTC
For the new Visual Web Next HTML Designer the following API are requested

- To get the StyleBuilder Panel
   - Create RuleItem  (Constructor CssRuleItem(String key, String value) )  
   - Create RuleContent (Constructor CssRuleContent(List<CssuleItem) ruleItems) )
   - Set RuleContent to StyleBuilder  (styleBuilder.setContent(CssRuleContent) ) 
   - Set Base Path to StyleBuilder ( styleBuilder.setBasePath(File basePath) )
      To be used by dialogs like Background image to select or copy background images 
- API to get the StyleBuilderPanel Top Component


Suggested API to hide implementation

    public interface StyleBuilder{
       public void setContent(CssRuleContent content);
       public void setBasePath(File basePath);
       public JPanel getPanel();
    }

    public interface StyleBuilderTopComponent{
       public void setContent(CssRuleContent content);
       public void setBasePath(File basePath);
       public void open();
    }

    public class StyleBuilderFactory(){

          public static StyleBuilderFactory getInstance(){
              // Return a static instance of the Factory
          }
          public StyleBuilder getStyleBuilder(){
              //Create and return implementation of StyleBuilder  
          } 
          public StyleBuilderTopComponent getStyleBuilderTopComponent(){
              //return the StyleBuilder TopComponent Singleton  
          } 
    } 


Implementation

   public class StyleBuilderImpl extends JPanel implements StyleBuilder{
      public JPanel getComponent(){
        return this;
     }
 

   public class StyleBuilderTopComponentImpl extends TopComponent implements  StyleBuilderTopComponent{
Comment 1 Marek Fukala 2008-03-07 08:58:42 UTC
I have done just minimal changes required by your usecases. The API now looks like:

package org.netbeans.modules.css.visual.api;

JUST A LITTLE UPDATE of the base() method. Now it represents the file base, not the file itself.
public final class CssRuleContext {

    /** @param  a selected css rule from the list of rules held by the css model. */
    public CssRule selectedRule() {}

    /** @param return an instance of CssModel which is this CssRuleContext based on. */
    public CssModel model() {}

    /** @return a File representing a base of the css file. Used to resolve relative links.*/
    public File base() {}

    /** @return source editor document for the css model or null if the model was created from a reader.*/
    public Document document()

}

NO CHANGE IN FOLLOWING CLASS:
public final class StyleBuilderPanel {
    public static StyleBuilderPanel createInstance()
    public void setContent(CssRuleContext content)
}

I MOVED THE SB TC to the api package:
public final class StyleBuilderTopComponent {
    public static synchronized StyleBuilderTopComponent findInstance()

    public void setContent(CssRuleContext content)
    public void setPanelMode(int mode) //allow you to se error or no content status to the SB TC - see the code for more
details.
}

In the SBTC instead of setContent(CssRuleCntext) there could be a set of the SBPanel itself, but this is minor issue IMHO.

As for the workflow:

String yourRules;

String code = " xxx { " + yourRules + " } "; //make the parser happy

CssModel model = CssModel.get(new StringReader(yourCSSCode));

CssRule rule = model.rules().get(0); //or find a rule you want if there are more

File base =  new File("/winston/coolproject/"); //base folder

CssRuleContext context = new CssRuleContext(rule, model, null, base);

StyleBuilder panel = new StyleBuilder();
panel.setContent(context);

//enjoy the panel

...or...

StyleBuilderTopComponent sbtc = StyleBuilderTopComponent.findInstance();
sbtc.setContent(context);

//enjoy the window

you can also do 

sbtc.setPanelMode(int mode);

where mode can be:

    MODEL_UPDATING = 1;
    /** Model OK, UI works.*/
    public static final int MODEL_OK = 2;
    /** Model broken, error panel shown. */
    public static final int MODEL_ERROR = 3;
    /** Model OK, but no rule selected, show warning panel */
    public static final int OUT_OF_RULE = 4;
    

I hope this fulfills your wishes. Let me know what else you need if there is still something, I'll do that asap.

Regards,
Marek
Comment 2 Winston Prakash 2008-03-07 14:53:13 UTC
This sounds great. I suggested the interface because you sounded little concerned about exposing the TopComponent UI
directly. I'm perfectly OK with your implementation.  I'll test with these and let you know. Thanks for the quick turn
around.