Show simple classes in Visual Editor [message #143475] |
Sat, 12 January 2008 18:32 |
Eclipse User |
|
|
|
Originally posted by: bla.nix.de
Hi all,
can somebody give me a hint to show following classes in VE?
I use:
Eclipse 3.2.2
Visual Editor 1.2.1
GEF 3.2.2
EMF 2.2.3
1. How can I pass a object, e.g. the owner, to the constructor of a visual
class
so that the visual editor works?
Here a simple example:
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
public class MyVisualEditorMain extends JPanel {
private static final long serialVersionUID = 1L;
private JButton btnMyButton = null;
private TestClass lblMyLabel = null;
private JRootPane owner = null;
public MyVisualEditorMain(JRootPane owner) {
super();
this.owner = owner;
initialize();
}
private void initialize() {
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 1;
gridBagConstraints1.gridy = 0;
lblMyLabel = new TestClass(this.owner);
// lblMyLabel = new TestClass(owner);
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
this.setSize(300, 200);
this.setLayout(new GridBagLayout());
this.add(getBtnMyButton(), gridBagConstraints);
this.add(lblMyLabel, gridBagConstraints1);
}
public class TestClass extends JLabel{
public TestClass(JRootPane owner){
super("hallo");
}
}
private JButton getBtnMyButton() {
if (btnMyButton == null) {
btnMyButton = new JButton();
btnMyButton.setText("Close");
}
return btnMyButton;
}
}
My second question:
How can I view the visual components from a extended abstract class?
Here a simple example again:
public abstract class AbstractVisualEditor extends JToolBar{
private JPanel pnlRoot = null;
private JButton btnEnd = null;
private JButton btnHelp = null;
public abstract void end();
public abstract void help();
public AbstractVisualEditor() {
super();
initialize();
}
protected final void initialize() {
this.setFloatable(false);
this.add(getPnlRoot());
}
private JPanel getPnlRoot() {
if (pnlRoot == null) {
pnlRoot = new JPanel();
pnlRoot.setLayout(new GridBagLayout());
pnlRoot.add(getBtnEnd(), new GridBagConstraints());
pnlRoot.add(getBtnHelp(), new GridBagConstraints());
}
return pnlRoot;
}
private JButton getBtnEnd() {
if (btnEnd == null) {
btnEnd = new JButton();
btnEnd.setText("End");
btnEnd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
end();
}
});
}
return btnEnd;
}
private JButton getBtnHelp() {
if (btnHelp == null) {
btnHelp = new JButton();
btnHelp.setText("Help");
btnHelp.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
help();
}
});
}
return btnHelp;
}
}
public class MyAbstractVisualEditor extends AbstractVisualEditor{
private JButton btnNew = null;
public MyAbstractVisualEditor(){
super();
initComponents();
}
public void initComponents() {
this.add(getBtnNew());
}
@Override
public void end() {
// TODO Auto-generated method stub
}
@Override
public void help() {
// TODO Auto-generated method stub
}
private JButton getBtnNew() {
if (btnNew == null) {
btnNew = new JButton();
btnNew.setText("New");
}
return btnNew;
}
} // @jve:decl-index=0:visual-constraint="10,10"
If I want to open MyAbstractVisualEditor .java with the visual editor I
can't see
the visual components of AbstractVisualEditor. Can someone give me a hint
how
to make this components visible?
Thank you very much for every help!
Marco
|
|
|
Re: Show simple classes in Visual Editor [message #143804 is a reply to message #143475] |
Wed, 06 February 2008 17:42 |
Eclipse User |
|
|
|
Originally posted by: bla.nix.de
Here another small example I can't show in my ve.
I just want to see the MyArrayListTest class in my ve with
the label text = "My Label".
Every answers for my three requests/questions are very appreciated.
public class MyArrayListTest extends JPanel{
private MyTestPane testPane = null;
public MyArrayListTest(){
initialize();
}
public void initialize(){
this.add(getTestPreferredSize());
}
private MyTestPane getTestPreferredSize() {
if (testPane == null) {
ArrayList alColSize = new ArrayList();
alColSize.add("80");
alColSize.add("60");
alColSize.add("40");
alColSize.add("100");
testPane = new MyTestPane(alColSize);
}
return testPane;
}
}
public class MyTestPane extends JPanel{
private JLabel myLabel = null;
private List alColumns = null;
public MyTestPane(List alColumns){
this.alColumns = alColumns;
initialize();
}
public void initialize(){
this.add(getMyLabel());
}
private JLabel getMyLabel() {
if (myLabel == null) {
myLabel = new JLabel();
if(this.alColumns.size() > 2)
myLabel.setText("My Label");
else
myLabel.setText("too small");
}
return myLabel;
}
}
"Marco" <bla@nix.de> schrieb im Newsbeitrag
news:fmb0da$j2p$1@build.eclipse.org...
> Hi all,
> can somebody give me a hint to show following classes in VE?
> I use:
> Eclipse 3.2.2
> Visual Editor 1.2.1
> GEF 3.2.2
> EMF 2.2.3
>
> 1. How can I pass a object, e.g. the owner, to the constructor of a visual
> class
> so that the visual editor works?
> Here a simple example:
>
> import java.awt.GridBagConstraints;
> import java.awt.GridBagLayout;
> import javax.swing.JButton;
> import javax.swing.JLabel;
> import javax.swing.JPanel;
> import javax.swing.JRootPane;
>
>
> public class MyVisualEditorMain extends JPanel {
>
>
> private static final long serialVersionUID = 1L;
>
> private JButton btnMyButton = null;
> private TestClass lblMyLabel = null;
> private JRootPane owner = null;
>
> public MyVisualEditorMain(JRootPane owner) {
>
> super();
>
> this.owner = owner;
>
>
> initialize();
>
> }
>
>
>
>
> private void initialize() {
>
> GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
>
> gridBagConstraints1.gridx = 1;
>
> gridBagConstraints1.gridy = 0;
>
> lblMyLabel = new TestClass(this.owner);
>
> // lblMyLabel = new TestClass(owner);
>
>
> GridBagConstraints gridBagConstraints = new GridBagConstraints();
>
> gridBagConstraints.gridx = 0;
>
> gridBagConstraints.gridy = 0;
>
> this.setSize(300, 200);
>
> this.setLayout(new GridBagLayout());
>
> this.add(getBtnMyButton(), gridBagConstraints);
>
> this.add(lblMyLabel, gridBagConstraints1);
>
> }
>
>
>
> public class TestClass extends JLabel{
>
>
> public TestClass(JRootPane owner){
>
> super("hallo");
> }
>
> }
>
>
>
>
> private JButton getBtnMyButton() {
>
> if (btnMyButton == null) {
>
> btnMyButton = new JButton();
>
> btnMyButton.setText("Close");
>
> }
>
> return btnMyButton;
>
> }
>
> }
>
>
>
> My second question:
> How can I view the visual components from a extended abstract class?
> Here a simple example again:
>
> public abstract class AbstractVisualEditor extends JToolBar{
>
>
> private JPanel pnlRoot = null;
>
> private JButton btnEnd = null;
>
> private JButton btnHelp = null;
>
> public abstract void end();
>
> public abstract void help();
>
>
> public AbstractVisualEditor() {
>
> super();
>
>
> initialize();
>
> }
>
>
>
>
> protected final void initialize() {
>
> this.setFloatable(false);
>
> this.add(getPnlRoot());
>
>
> }
>
>
>
>
> private JPanel getPnlRoot() {
>
> if (pnlRoot == null) {
>
> pnlRoot = new JPanel();
>
> pnlRoot.setLayout(new GridBagLayout());
>
> pnlRoot.add(getBtnEnd(), new GridBagConstraints());
>
> pnlRoot.add(getBtnHelp(), new GridBagConstraints());
>
> }
>
> return pnlRoot;
>
> }
>
>
>
>
> private JButton getBtnEnd() {
>
> if (btnEnd == null) {
>
> btnEnd = new JButton();
>
> btnEnd.setText("End");
>
> btnEnd.addActionListener(new java.awt.event.ActionListener() {
>
> public void actionPerformed(java.awt.event.ActionEvent e) {
>
>
> end();
>
> }
>
> });
>
> }
>
> return btnEnd;
>
> }
>
>
>
>
> private JButton getBtnHelp() {
>
> if (btnHelp == null) {
>
> btnHelp = new JButton();
>
> btnHelp.setText("Help");
>
> btnHelp.addActionListener(new java.awt.event.ActionListener() {
>
> public void actionPerformed(java.awt.event.ActionEvent e) {
>
>
> help();
>
> }
>
> });
>
> }
>
> return btnHelp;
>
> }
>
>
> }
>
>
>
> public class MyAbstractVisualEditor extends AbstractVisualEditor{
>
>
> private JButton btnNew = null;
>
>
> public MyAbstractVisualEditor(){
>
> super();
>
> initComponents();
>
> }
>
>
> public void initComponents() {
>
> this.add(getBtnNew());
>
>
> }
>
>
>
> @Override
>
> public void end() {
>
> // TODO Auto-generated method stub
>
>
> }
>
>
> @Override
>
> public void help() {
>
> // TODO Auto-generated method stub
>
>
> }
>
>
>
>
> private JButton getBtnNew() {
>
> if (btnNew == null) {
>
> btnNew = new JButton();
>
> btnNew.setText("New");
>
> }
>
> return btnNew;
>
> }
>
>
> } // @jve:decl-index=0:visual-constraint="10,10"
>
>
>
> If I want to open MyAbstractVisualEditor .java with the visual editor I
> can't see
> the visual components of AbstractVisualEditor. Can someone give me a hint
> how
> to make this components visible?
>
> Thank you very much for every help!
> Marco
>
>
>
>
>
>
>
>
|
|
|
|
|
Re: Show simple classes in Visual Editor [message #143825 is a reply to message #143821] |
Fri, 08 February 2008 16:38 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Primitives, strings, new XYZ(...), and setXYZ() methods are evaluated.
It does not do evaluation of non-standard bean methods (like add()) on
the objects. So the arraylist may of been created but it won't have any
content.
You didn't say what actually showed up so I don't know what really happened.
--
Thanks,
Rich Kulp
|
|
|
Re: Show simple classes in Visual Editor [message #143839 is a reply to message #143825] |
Mon, 11 February 2008 18:02 |
Eclipse User |
|
|
|
Originally posted by: bla.nix.de
Ahhh... ok. Thanks for clarifying but
can you please explain me why the following is working anyway?
public class MyTestPane extends JPanel{
private JLabel myLabel = null;
private ArrayList alName = null;
public MyTestPane(ArrayList list){
//alName = list; <-- this is not working!!
alName = new ArrayList();
alName.add("peter");
alName.add("sarah");
initialize();
}
public void initialize(){
this.add(getMyLabel());
}
private JLabel getMyLabel() {
if (myLabel == null) {
myLabel = new JLabel();
if(this.alName.size() > 0)
myLabel.setText("My Label");
else
myLabel.setText("too small");
}
return myLabel;
}
}
Greetings
Marco
"Rich Kulp" <richkulp@us.NO_SPAM.ibm.com> schrieb im Newsbeitrag
news:foi0iq$di1$1@build.eclipse.org...
> Primitives, strings, new XYZ(...), and setXYZ() methods are evaluated. It
> does not do evaluation of non-standard bean methods (like add()) on the
> objects. So the arraylist may of been created but it won't have any
> content.
>
> You didn't say what actually showed up so I don't know what really
> happened.
>
> --
> Thanks,
> Rich Kulp
|
|
|
Re: Show simple classes in Visual Editor [message #143848 is a reply to message #143839] |
Mon, 11 February 2008 22:53 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
That is because it is being passed in as an argument to the constructor.
Arguments are not usable because since we don't actually run the code on
a class being edited, but instead interpret what we can, there is no way
for us to know what value "list" would have. When you do alName = new
ArrayList(); we know exactly what that value is, a new array list.
> public MyTestPane(ArrayList list){
>
>
> //alName = list; <-- this is not working!!
> alName = new ArrayList();
> alName.add("peter");
> alName.add("sarah");
>
> initialize();
> }
But we don't execute "add" methods on things like array list, so the
array list will be created but it is empty. So what happens in the next
piece of code is that we assume the if() statements are always true, so
we then evaluate the if clause. We ignore anything in an else clause. So
the "My Label" settext would happen because we know what myLabel is, and
we know what setText is and we know what "My Label" is.
if(this.alName.size() > 0)
myLabel.setText("My Label");
else
myLabel.setText("too small");
--
Thanks,
Rich Kulp
|
|
|
Re: Show simple classes in Visual Editor [message #616958 is a reply to message #143475] |
Wed, 06 February 2008 17:42 |
Marco Messages: 27 Registered: July 2009 |
Junior Member |
|
|
Here another small example I can't show in my ve.
I just want to see the MyArrayListTest class in my ve with
the label text = "My Label".
Every answers for my three requests/questions are very appreciated.
public class MyArrayListTest extends JPanel{
private MyTestPane testPane = null;
public MyArrayListTest(){
initialize();
}
public void initialize(){
this.add(getTestPreferredSize());
}
private MyTestPane getTestPreferredSize() {
if (testPane == null) {
ArrayList alColSize = new ArrayList();
alColSize.add("80");
alColSize.add("60");
alColSize.add("40");
alColSize.add("100");
testPane = new MyTestPane(alColSize);
}
return testPane;
}
}
public class MyTestPane extends JPanel{
private JLabel myLabel = null;
private List alColumns = null;
public MyTestPane(List alColumns){
this.alColumns = alColumns;
initialize();
}
public void initialize(){
this.add(getMyLabel());
}
private JLabel getMyLabel() {
if (myLabel == null) {
myLabel = new JLabel();
if(this.alColumns.size() > 2)
myLabel.setText("My Label");
else
myLabel.setText("too small");
}
return myLabel;
}
}
"Marco" <bla@nix.de> schrieb im Newsbeitrag
news:fmb0da$j2p$1@build.eclipse.org...
> Hi all,
> can somebody give me a hint to show following classes in VE?
> I use:
> Eclipse 3.2.2
> Visual Editor 1.2.1
> GEF 3.2.2
> EMF 2.2.3
>
> 1. How can I pass a object, e.g. the owner, to the constructor of a visual
> class
> so that the visual editor works?
> Here a simple example:
>
> import java.awt.GridBagConstraints;
> import java.awt.GridBagLayout;
> import javax.swing.JButton;
> import javax.swing.JLabel;
> import javax.swing.JPanel;
> import javax.swing.JRootPane;
>
>
> public class MyVisualEditorMain extends JPanel {
>
>
> private static final long serialVersionUID = 1L;
>
> private JButton btnMyButton = null;
> private TestClass lblMyLabel = null;
> private JRootPane owner = null;
>
> public MyVisualEditorMain(JRootPane owner) {
>
> super();
>
> this.owner = owner;
>
>
> initialize();
>
> }
>
>
>
>
> private void initialize() {
>
> GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
>
> gridBagConstraints1.gridx = 1;
>
> gridBagConstraints1.gridy = 0;
>
> lblMyLabel = new TestClass(this.owner);
>
> // lblMyLabel = new TestClass(owner);
>
>
> GridBagConstraints gridBagConstraints = new GridBagConstraints();
>
> gridBagConstraints.gridx = 0;
>
> gridBagConstraints.gridy = 0;
>
> this.setSize(300, 200);
>
> this.setLayout(new GridBagLayout());
>
> this.add(getBtnMyButton(), gridBagConstraints);
>
> this.add(lblMyLabel, gridBagConstraints1);
>
> }
>
>
>
> public class TestClass extends JLabel{
>
>
> public TestClass(JRootPane owner){
>
> super("hallo");
> }
>
> }
>
>
>
>
> private JButton getBtnMyButton() {
>
> if (btnMyButton == null) {
>
> btnMyButton = new JButton();
>
> btnMyButton.setText("Close");
>
> }
>
> return btnMyButton;
>
> }
>
> }
>
>
>
> My second question:
> How can I view the visual components from a extended abstract class?
> Here a simple example again:
>
> public abstract class AbstractVisualEditor extends JToolBar{
>
>
> private JPanel pnlRoot = null;
>
> private JButton btnEnd = null;
>
> private JButton btnHelp = null;
>
> public abstract void end();
>
> public abstract void help();
>
>
> public AbstractVisualEditor() {
>
> super();
>
>
> initialize();
>
> }
>
>
>
>
> protected final void initialize() {
>
> this.setFloatable(false);
>
> this.add(getPnlRoot());
>
>
> }
>
>
>
>
> private JPanel getPnlRoot() {
>
> if (pnlRoot == null) {
>
> pnlRoot = new JPanel();
>
> pnlRoot.setLayout(new GridBagLayout());
>
> pnlRoot.add(getBtnEnd(), new GridBagConstraints());
>
> pnlRoot.add(getBtnHelp(), new GridBagConstraints());
>
> }
>
> return pnlRoot;
>
> }
>
>
>
>
> private JButton getBtnEnd() {
>
> if (btnEnd == null) {
>
> btnEnd = new JButton();
>
> btnEnd.setText("End");
>
> btnEnd.addActionListener(new java.awt.event.ActionListener() {
>
> public void actionPerformed(java.awt.event.ActionEvent e) {
>
>
> end();
>
> }
>
> });
>
> }
>
> return btnEnd;
>
> }
>
>
>
>
> private JButton getBtnHelp() {
>
> if (btnHelp == null) {
>
> btnHelp = new JButton();
>
> btnHelp.setText("Help");
>
> btnHelp.addActionListener(new java.awt.event.ActionListener() {
>
> public void actionPerformed(java.awt.event.ActionEvent e) {
>
>
> help();
>
> }
>
> });
>
> }
>
> return btnHelp;
>
> }
>
>
> }
>
>
>
> public class MyAbstractVisualEditor extends AbstractVisualEditor{
>
>
> private JButton btnNew = null;
>
>
> public MyAbstractVisualEditor(){
>
> super();
>
> initComponents();
>
> }
>
>
> public void initComponents() {
>
> this.add(getBtnNew());
>
>
> }
>
>
>
> @Override
>
> public void end() {
>
> // TODO Auto-generated method stub
>
>
> }
>
>
> @Override
>
> public void help() {
>
> // TODO Auto-generated method stub
>
>
> }
>
>
>
>
> private JButton getBtnNew() {
>
> if (btnNew == null) {
>
> btnNew = new JButton();
>
> btnNew.setText("New");
>
> }
>
> return btnNew;
>
> }
>
>
> } // @jve:decl-index=0:visual-constraint="10,10"
>
>
>
> If I want to open MyAbstractVisualEditor .java with the visual editor I
> can't see
> the visual components of AbstractVisualEditor. Can someone give me a hint
> how
> to make this components visible?
>
> Thank you very much for every help!
> Marco
>
>
>
>
>
>
>
>
|
|
|
|
|
Re: Show simple classes in Visual Editor [message #616962 is a reply to message #143821] |
Fri, 08 February 2008 16:38 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Primitives, strings, new XYZ(...), and setXYZ() methods are evaluated.
It does not do evaluation of non-standard bean methods (like add()) on
the objects. So the arraylist may of been created but it won't have any
content.
You didn't say what actually showed up so I don't know what really happened.
--
Thanks,
Rich Kulp
|
|
|
|
Re: Show simple classes in Visual Editor [message #616967 is a reply to message #143839] |
Mon, 11 February 2008 22:53 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
That is because it is being passed in as an argument to the constructor.
Arguments are not usable because since we don't actually run the code on
a class being edited, but instead interpret what we can, there is no way
for us to know what value "list" would have. When you do alName = new
ArrayList(); we know exactly what that value is, a new array list.
> public MyTestPane(ArrayList list){
>
>
> //alName = list; <-- this is not working!!
> alName = new ArrayList();
> alName.add("peter");
> alName.add("sarah");
>
> initialize();
> }
But we don't execute "add" methods on things like array list, so the
array list will be created but it is empty. So what happens in the next
piece of code is that we assume the if() statements are always true, so
we then evaluate the if clause. We ignore anything in an else clause. So
the "My Label" settext would happen because we know what myLabel is, and
we know what setText is and we know what "My Label" is.
if(this.alName.size() > 0)
myLabel.setText("My Label");
else
myLabel.setText("too small");
--
Thanks,
Rich Kulp
|
|
|
Powered by
FUDForum. Page generated in 0.04369 seconds