Changeset 7355

Show
Ignore:
Timestamp:
04/29/08 13:12:32 (5 years ago)
Author:
stedwar2
Message:

Added display of component's base name ("Kind"). Added listeners to
update component properties based on text field values.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/editors/ComponentEditor.java

    r7345 r7355  
    88import org.eclipse.swt.SWT; 
    99import org.eclipse.swt.custom.ScrolledComposite; 
     10import org.eclipse.swt.events.ModifyEvent; 
     11import org.eclipse.swt.events.ModifyListener; 
    1012import org.eclipse.swt.graphics.Image; 
    1113import org.eclipse.swt.layout.FillLayout; 
     
    2628import org.eclipse.ui.IEditorSite; 
    2729import org.eclipse.ui.IFileEditorInput; 
     30import org.eclipse.ui.IReusableEditor; 
    2831import org.eclipse.ui.PartInitException; 
    2932import org.eclipse.ui.PlatformUI; 
    3033import org.eclipse.ui.part.EditorPart; 
     34import edu.vt.ossie.wavedev.Component; 
    3135 
    3236//------------------------------------------------------------------------- 
     
    3943public class ComponentEditor 
    4044    extends EditorPart 
     45    implements IReusableEditor 
    4146{ 
    4247    //~ Constructor ........................................................... 
     
    7580    { 
    7681        setSite(site); 
    77         setInput(input); 
     82        setInputWithNotify(input); 
    7883    } 
    7984 
     
    129134        { 
    130135            Label componentNameLabel = new Label(mainWindow, SWT.NONE); 
    131             componentNameLabel.setText("Component"); 
     136            componentNameLabel.setText("Name:"); 
    132137            componentNameLabel.setBounds(12, 12, 92, 19); 
     138        } 
     139        { 
     140            Label componentKindLabel = new Label(mainWindow, SWT.NONE); 
     141            componentKindLabel.setText("Kind:"); 
     142            componentKindLabel.setBounds(12, 43, 92, 19); 
     143        } 
     144        { 
     145            componentBaseName = new Label(mainWindow, SWT.BORDER); 
     146            componentBaseName.setText("Type"); 
     147            componentBaseName.setBounds(108, 43, 92, 19); 
    133148        } 
    134149        { 
    135150            componentNameInputField = new Text(mainWindow, SWT.BORDER); 
    136151            componentNameInputField.setBounds(104, 11, 137, 30); 
     152            componentNameInputField.addModifyListener(new ModifyListener() 
     153            { 
     154                public void modifyText(ModifyEvent e) 
     155                { 
     156                    if (fillingControls) return; 
     157                    String newName =  componentNameInputField.getText(); 
     158                    if (!newName.equals(component.getName())) 
     159                    { 
     160                        System.out.println("name changed to " + newName); 
     161                        component.setName(newName); 
     162                        setIsDirty(true); 
     163                    } 
     164                } 
     165            }); 
    137166        } 
    138167        { 
    139168            Label descriptionLabel = new Label(mainWindow, SWT.NONE); 
    140             descriptionLabel.setText("Description"); 
    141             descriptionLabel.setBounds(12, 37, 91, 19); 
     169            descriptionLabel.setText("Description:"); 
     170            descriptionLabel.setBounds(12, 62, 91, 19); 
    142171        } 
    143172        { 
    144173            descriptionInputField = 
    145174                new Text(mainWindow, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); 
    146             descriptionInputField.setBounds(104, 37, 137, 60); 
     175            descriptionInputField.setBounds(104, 62, 137, 60); 
     176            descriptionInputField.addModifyListener(new ModifyListener() 
     177            { 
     178                public void modifyText(ModifyEvent e) 
     179                { 
     180                    if (fillingControls) return; 
     181                    String newDescription =  descriptionInputField.getText(); 
     182                    if (!newDescription.equals(component.getDescription())) 
     183                    { 
     184                        System.out.println( 
     185                            "description changed to " + newDescription); 
     186                        component.setDescription(newDescription); 
     187                        setIsDirty(true); 
     188                    } 
     189                } 
     190            }); 
    147191        } 
    148192        { 
    149193            Label portsLabel = new Label(mainWindow, SWT.NONE); 
    150194            portsLabel.setText("Ports"); 
    151             portsLabel.setBounds(12, 81, 54, 18); 
     195            portsLabel.setBounds(12, 106, 54, 18); 
    152196        } 
    153197        { 
    154198            portsTree = new Tree(mainWindow, SWT.BORDER); 
    155             portsTree.setBounds(18, 101, 222, 130); 
     199            portsTree.setBounds(12, 126, 228, 136); 
    156200 
    157201        } 
    158202        { 
    159203            propertiesTable = new Table(mainWindow, SWT.BORDER); 
    160             propertiesTable.setBounds(18, 241, 223, 136); 
     204            propertiesTable.setBounds(12, 266, 228, 136); 
    161205        } 
    162206        { 
     
    244288        scroller.setMinSize(mainWindow.getSize()); 
    245289        scroller.setContent(mainWindow); 
     290 
     291        if (getEditorInput() != null) 
     292        { 
     293            loadControlsFromNewInput(); 
     294        } 
    246295    } 
    247296 
     
    264313        System.out.println("ComponentEditor.setInput(): " + input.getName()); 
    265314        setInputWithNotify(input); 
     315        loadControlsFromNewInput(); 
    266316    } 
    267317 
     
    285335            } 
    286336        }); 
     337    } 
     338 
     339 
     340    // ---------------------------------------------------------- 
     341    public boolean isConnectedToFile() 
     342    { 
     343        return getEditorInput() instanceof IFileEditorInput; 
     344    } 
     345 
     346 
     347    // ---------------------------------------------------------- 
     348    public IFileEditorInput getFileInput() 
     349    { 
     350        return isConnectedToFile() 
     351            ? (IFileEditorInput)getEditorInput() 
     352            : null; 
     353    } 
     354 
     355 
     356    // ---------------------------------------------------------- 
     357    public ComponentEditorInput getComponentInput() 
     358    { 
     359        return isConnectedToFile() 
     360            ? null 
     361            : (ComponentEditorInput)getEditorInput(); 
    287362    } 
    288363 
     
    350425        { 
    351426            close(isConnectedToFile() && isSaveOnCloseNeeded()); 
     427            component = null; 
    352428        } 
    353429        else 
     
    356432            // need to load the project 
    357433            initializeTitle(input); 
    358  
    359             // TODO: refresh controls 
    360         } 
    361     } 
    362  
    363  
     434        } 
     435    } 
     436 
     437 
     438    // ---------------------------------------------------------- 
     439    protected void loadControlsFromNewInput() 
     440    { 
     441        fillingControls = true; 
     442        if (!isConnectedToFile()) 
     443        { 
     444            component = getComponentInput().getComponent(); 
     445        } 
     446        clearComponentControls(component != null); 
     447        if (component != null) 
     448        { 
     449            refreshControlsFromComponent(); 
     450        } 
     451        fillingControls = false; 
     452    } 
     453 
     454 
     455    // ---------------------------------------------------------- 
     456    protected void refreshControlsFromComponent() 
     457    { 
     458        descriptionInputField.setText(guiString(component.getDescription())); 
     459        componentNameInputField.setText(guiString(component.getName())); 
     460        componentBaseName.setText(guiString(component.getBaseName())); 
     461    } 
     462 
     463 
     464    // ---------------------------------------------------------- 
     465    protected void clearComponentControls(boolean enable) 
     466    { 
     467        boolean wasFillingControls = fillingControls; 
     468        fillingControls = true; 
     469        descriptionInputField.setText(""); 
     470        descriptionInputField.setEnabled(enable); 
     471 
     472        componentNameInputField.setText(""); 
     473        componentNameInputField.setEnabled(enable); 
     474 
     475        componentBaseName.setText(""); 
     476        componentBaseName.setEnabled(enable); 
     477 
     478//        private Combo  deviceSelectorCombo; 
     479//        private Combo  templateSelectorCombo; 
     480//        private Combo  nodeSelectorCombo; 
     481// 
     482//        private Table  propertiesTable; 
     483//        private Tree   portsTree; 
     484 
     485        fillingControls = wasFillingControls; 
     486    } 
     487 
     488 
     489    // ---------------------------------------------------------- 
     490    public String guiString(String str) 
     491    { 
     492        return str == null ? "" : str; 
     493    } 
    364494    //~ Private Methods ....................................................... 
    365495 
     
    403533 
    404534 
    405     // ---------------------------------------------------------- 
    406     public boolean isConnectedToFile() 
    407     { 
    408         return getEditorInput() instanceof IFileEditorInput; 
    409     } 
    410  
    411  
    412     // ---------------------------------------------------------- 
    413     public IFileEditorInput getFileInput() 
    414     { 
    415         return isConnectedToFile() 
    416             ? (IFileEditorInput)getEditorInput() 
    417             : null; 
    418     } 
    419  
    420  
    421     // ---------------------------------------------------------- 
    422     public ComponentEditorInput getComponentInput() 
    423     { 
    424         return isConnectedToFile() 
    425             ? null 
    426             : (ComponentEditorInput)getEditorInput(); 
    427     } 
    428  
    429  
    430535    //~ Instance/static variables ............................................. 
    431536 
    432537    private Text   descriptionInputField; 
    433538    private Text   componentNameInputField; 
     539    private Label  componentBaseName; 
    434540 
    435541    private Button ACESupportCheckBox; 
     
    450556    private boolean dirty; 
    451557    private Image   titleImage; 
     558 
     559    private Component component; 
     560    private boolean   fillingControls; 
    452561}