Changeset 7355
- Timestamp:
- 04/29/08 13:12:32 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
ossiedev/branches/jsnyder/ComponentProject/src/edu/vt/ossie/editors/ComponentEditor.java
r7345 r7355 8 8 import org.eclipse.swt.SWT; 9 9 import org.eclipse.swt.custom.ScrolledComposite; 10 import org.eclipse.swt.events.ModifyEvent; 11 import org.eclipse.swt.events.ModifyListener; 10 12 import org.eclipse.swt.graphics.Image; 11 13 import org.eclipse.swt.layout.FillLayout; … … 26 28 import org.eclipse.ui.IEditorSite; 27 29 import org.eclipse.ui.IFileEditorInput; 30 import org.eclipse.ui.IReusableEditor; 28 31 import org.eclipse.ui.PartInitException; 29 32 import org.eclipse.ui.PlatformUI; 30 33 import org.eclipse.ui.part.EditorPart; 34 import edu.vt.ossie.wavedev.Component; 31 35 32 36 //------------------------------------------------------------------------- … … 39 43 public class ComponentEditor 40 44 extends EditorPart 45 implements IReusableEditor 41 46 { 42 47 //~ Constructor ........................................................... … … 75 80 { 76 81 setSite(site); 77 setInput (input);82 setInputWithNotify(input); 78 83 } 79 84 … … 129 134 { 130 135 Label componentNameLabel = new Label(mainWindow, SWT.NONE); 131 componentNameLabel.setText(" Component");136 componentNameLabel.setText("Name:"); 132 137 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); 133 148 } 134 149 { 135 150 componentNameInputField = new Text(mainWindow, SWT.BORDER); 136 151 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 }); 137 166 } 138 167 { 139 168 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); 142 171 } 143 172 { 144 173 descriptionInputField = 145 174 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 }); 147 191 } 148 192 { 149 193 Label portsLabel = new Label(mainWindow, SWT.NONE); 150 194 portsLabel.setText("Ports"); 151 portsLabel.setBounds(12, 81, 54, 18);195 portsLabel.setBounds(12, 106, 54, 18); 152 196 } 153 197 { 154 198 portsTree = new Tree(mainWindow, SWT.BORDER); 155 portsTree.setBounds(1 8, 101, 222, 130);199 portsTree.setBounds(12, 126, 228, 136); 156 200 157 201 } 158 202 { 159 203 propertiesTable = new Table(mainWindow, SWT.BORDER); 160 propertiesTable.setBounds(1 8, 241, 223, 136);204 propertiesTable.setBounds(12, 266, 228, 136); 161 205 } 162 206 { … … 244 288 scroller.setMinSize(mainWindow.getSize()); 245 289 scroller.setContent(mainWindow); 290 291 if (getEditorInput() != null) 292 { 293 loadControlsFromNewInput(); 294 } 246 295 } 247 296 … … 264 313 System.out.println("ComponentEditor.setInput(): " + input.getName()); 265 314 setInputWithNotify(input); 315 loadControlsFromNewInput(); 266 316 } 267 317 … … 285 335 } 286 336 }); 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(); 287 362 } 288 363 … … 350 425 { 351 426 close(isConnectedToFile() && isSaveOnCloseNeeded()); 427 component = null; 352 428 } 353 429 else … … 356 432 // need to load the project 357 433 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 } 364 494 //~ Private Methods ....................................................... 365 495 … … 403 533 404 534 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 ? null426 : (ComponentEditorInput)getEditorInput();427 }428 429 430 535 //~ Instance/static variables ............................................. 431 536 432 537 private Text descriptionInputField; 433 538 private Text componentNameInputField; 539 private Label componentBaseName; 434 540 435 541 private Button ACESupportCheckBox; … … 450 556 private boolean dirty; 451 557 private Image titleImage; 558 559 private Component component; 560 private boolean fillingControls; 452 561 }