private TableEditor initTableEditor(TableEditor editor, Table table) { if (null != editor) { Control lastCtrl = editor.getEditor(); if (null != lastCtrl) { lastCtrl.dispose(); } } editor = new TableEditor(table); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; return editor; }
@Override public void createPartControl(Composite parent) { // TODO Auto-generated method stub toolkit = new FormToolkit(parent.getDisplay()); form = toolkit.createForm(parent); form.setText("MetaData Editor:"); toolkit.decorateFormHeading(form); GridData gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.minimumWidth = 200; // FormLayout gridLayout = new FormLayout(); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; gridLayout.horizontalSpacing = 5; form.getBody().setLayout(gridLayout); FormData formDate = new FormData(); formDate.height = 250; formDate.width = 300; FormData formDate0 = new FormData(); formDate0.height = 150; formDate0.width = 300; FormData formDate2 = new FormData(); formDate2.height = 550; formDate2.width = 550; Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR); section.setText("Attribute Modifier"); Composite sectionClient = toolkit.createComposite(section); sectionClient.setLayout(new FormLayout()); section.setClient(sectionClient); GridData gridData2 = new GridData(); gridData2.verticalSpan = 2; section.setLayoutData(gridData2); Section section2 = toolkit.createSection(form.getBody(), Section.TITLE_BAR); section2.setText("Collector"); Composite sectionClient2 = toolkit.createComposite(section2); sectionClient2.setLayout(new FormLayout()); section2.setClient(sectionClient2); Section section3 = toolkit.createSection(form.getBody(), Section.TITLE_BAR); // printStackTrace section3.setText("Collection Code"); Composite sectionClient3 = toolkit.createComposite(section3); sectionClient3.setLayout(new FormLayout()); section3.setClient(sectionClient3); final Table table2 = toolkit.createTable( sectionClient2, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.NONE); table2.setHeaderVisible(true); final Button submitCollectionCode = toolkit.createButton(sectionClient2, "submit", SWT.None); TableColumn column01 = new TableColumn(table2, SWT.NONE); column01.setWidth(25); column01.setText("#"); TableColumn column02 = new TableColumn(table2, SWT.NONE); column02.setWidth(100); column02.setText("Name"); TableColumn column03 = new TableColumn(table2, SWT.NONE); column03.setWidth(100); column03.setText("Collection No"); table2.setLayoutData(formDate); int index = 1; for (SpecCollectorMap map : spec.getSpecCollectorMaps()) { Collector c = map.getCollector(); TableItem item = new TableItem(table2, SWT.FULL_SELECTION); item.setData("collector", c); item.setText(0, index + ""); index++; item.setText(1, c.getCollectorFullName()); // c.exe if (spec.getRecordNumber() == null) { item.setText(2, ""); } else item.setText(2, spec.getRecordNumber()); table2.setSelection(index); } table2.addListener( SWT.MouseDoubleClick, new Listener() { @Override public void handleEvent(Event arg0) { Point pt = new Point(arg0.x, arg0.y); int ret; for (final TableItem item : table2.getItems()) { for (int i = 0; i < table2.getColumnCount(); i++) { Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { Collector c = (Collector) item.getData("collector"); CollectorModDialog dialog = new CollectorModDialog(Display.getDefault().getActiveShell(), c); ret = dialog.open(); } } } } }); final Table table3 = toolkit.createTable( sectionClient3, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.NONE); table3.setHeaderVisible(true); TableColumn column31 = new TableColumn(table3, SWT.NONE); column31.setWidth(25); column31.setText("#"); TableColumn column32 = new TableColumn(table3, SWT.NONE); column32.setWidth(50); column32.setText("Collection Code"); TableColumn column33 = new TableColumn(table3, SWT.NONE); column33.setWidth(150); column33.setText("Collection Info"); table3.setLayoutData(formDate0); Collection ccc = this.spec.getCollection(); TableItem item31 = new TableItem(table3, SWT.NONE); item31.setText(0, "1"); if (ccc != null) { if (ccc.getCollectionCode() == null) ccc.setCollectionCode(""); if (ccc.getCollectionInfo() == null) ccc.setCollectionInfo(""); item31.setText(1, ccc.getCollectionCode()); item31.setText(2, ccc.getCollectionInfo()); } final TableEditor collectionEditor = new TableEditor(table3); collectionEditor.horizontalAlignment = SWT.LEFT; collectionEditor.grabHorizontal = true; collectionEditor.minimumWidth = 50; collectionSelectionListener = new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } @Override public void widgetSelected(SelectionEvent arg0) { // TODO Auto-generated method stub Control oldEditor = collectionEditor.getEditor(); if (oldEditor != null) oldEditor.dispose(); } }; table3.addSelectionListener(collectionSelectionListener); tableListener2 = new Listener() { @Override public void handleEvent(Event arg0) { // TODO Auto-generated method stub Point pt = new Point(arg0.x, arg0.y); for (final TableItem item : table.getItems()) { String editable = (String) item.getData("editable"); if (editable.equals("true")) {} } } }; tableListener2 = new Listener() { @Override public void handleEvent(Event arg0) { Point pt = new Point(arg0.x, arg0.y); for (final TableItem item : table3.getItems()) { for (int i = 0; i < table3.getColumnCount(); i++) { Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { Control oldEditor = collectionEditor.getEditor(); if (oldEditor != null) oldEditor.dispose(); final Combo newEditor = new Combo(table3, SWT.NONE); DataUtilsService service = new DataUtilsService(); DataUtilsDelegate delegate = service.getDataUtilsPort(); final List<Collection> collections = delegate.getCollections(); for (Collection col : collections) { newEditor.add(col.getCollectionCode()); } newEditor.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { // TODO Auto-generated method stub Combo combo = (Combo) collectionEditor.getEditor(); Collection collection = collections.get(combo.getSelectionIndex()); collectionEditor.getItem().setText(1, collection.getCollectionCode()); collectionEditor.getItem().setText(2, collection.getCollectionInfo()); collectionEditor .getItem() .setBackground(new Color(Display.getCurrent(), 255, 250, 160)); String methodName = (String) item.getData(); } }); newEditor.setFocus(); collectionEditor.setEditor(newEditor, item, 1); } } } } }; table3.addListener(SWT.MouseDoubleClick, tableListener2); final Table table = toolkit.createTable(sectionClient, SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setLayoutData(formDate2); TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(200); column.setText("Name"); TableColumn column2 = new TableColumn(table, SWT.NONE); column2.setWidth(250); column2.setText("Data"); TableColumn column3 = new TableColumn(table, SWT.NONE); column3.setWidth(100); // table.setLayoutData(gridData); /* final TableItem itemName = new TableItem(table,SWT.NONE); itemName.setText(0,"Scientific Name:"); final TableItem itemFamily = new TableItem(table, SWT.NONE); itemFamily.setText(0, "Family:"); itemFamily.setData("setFamily"); final TableItem itemGenus = new TableItem(table, SWT.NONE); itemGenus.setText(0, "Genus:"); itemGenus.setData("setGenus"); final TableItem itemSpecies = new TableItem(table, SWT.NONE); itemSpecies.setText(0, "Species:"); itemSpecies.setData("setSpecies"); final TableItem itemCollectAt = new TableItem(table, SWT.NONE); itemCollectAt.setText(0, "Collect At:"); itemCollectAt.setData("setCountry"); final TableItem itemCollectAtDarwin = new TableItem(table, SWT.NONE); itemCollectAtDarwin.setText(0, "Name in Darwin's time:"); itemCollectAtDarwin.setData("setDcountry"); final TableItem itemSheetNote = new TableItem(table, SWT.NONE); itemSheetNote.setText(0, "Sheet Notes:"); itemSheetNote.setData("setSheetNotes"); final TableItem itemState = new TableItem(table, SWT.NONE); itemState.setText(0, "State:"); itemState.setData("setStateProvince"); final TableItem itemTown = new TableItem(table, SWT.NONE); itemTown.setText(0, "Town:"); itemTown.setData("setTown"); itemName.setText(1,spec.getScientificName()); itemFamily.setText(1, spec.getFamily()); itemGenus.setText(1, spec.getGenus()); itemSpecies.setText(1, spec.getSpecificEpithet()); itemCollectAt.setText(1, spec.getCountry()); itemCollectAtDarwin.setText(1, spec.getDarwinCountry()); itemSheetNote.setText(1, spec.getSheetNotes()); itemState.setText(1, spec.getStateProvince()); itemTown.setText(1, spec.getTown()); */ try { Element root = this.configXml.selectElement("system/editor"); for (int i = 0; i < root.getChildNodes().getLength(); i++) { if (root.getChildNodes().item(i).getNodeType() == Element.ELEMENT_NODE) { Element child = (Element) root.getChildNodes().item(i); System.out.println("child name = " + child.getAttribute("field")); if (child.getAttribute("display").equals("true")) { final TableItem itemName = new TableItem(table, SWT.NONE); System.out.println(itemName); itemName.setData("set" + child.getAttribute("field")); itemName.setData("editable", child.getAttribute("editable")); itemName.setData("type", child.getAttribute("type")); itemName.setText(0, child.getAttribute("name")); if (child.getAttribute("field").equals("RecordNumber")) { System.out.println(child.getAttribute("editable")); } Method m; try { m = spec.getClass().getMethod("get" + child.getAttribute("field")); System.out.println("function name = " + m.getName()); if (child.getAttribute("type").equals("date")) { XMLGregorianCalendar cal = (XMLGregorianCalendar) m.invoke(spec); String calstr = ""; if (cal != null) { calstr = cal.toString(); itemName.setText(1, calstr); itemName.setData("date", cal); } } else if (child.getAttribute("type").equals("string")) { String str = (String) m.invoke(spec); if (str == null) { str = ""; } itemName.setText(1, str); } else if (child.getAttribute("type").equals("int")) { Integer inte = (Integer) m.invoke(spec); itemName.setText(1, inte + ""); } } catch (NoSuchMethodException e) { // TODO Auto-generated catch block System.out.println("field==" + child.getAttribute("field")); // e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } catch (XmlToolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } final TableEditor editor = new TableEditor(table); // The editor must have the same size as the cell and must // not be any smaller than 50 pixels. editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; editor.minimumWidth = 50; // editing the second column final int EDITABLECOLUMN = 1; tableSelectionListener = new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } @Override public void widgetSelected(SelectionEvent arg0) { // TODO Auto-generated method stub Control oldEditor = editor.getEditor(); if (oldEditor != null) oldEditor.dispose(); } }; final Button submitButton = toolkit.createButton(form.getBody(), "submit", SWT.None); submitButton.setEnabled(false); final Label label2 = new Label(form.getBody(), SWT.NONE); label2.setData("name", "label2"); label2.setText("Modification Save Successfully"); label2.setFont(new Font(Display.getCurrent(), "Arial", 10, SWT.BOLD)); label2.setForeground(new Color(Display.getCurrent(), 0, 128, 64)); label2.setVisible(false); final Label label3 = new Label(form.getBody(), SWT.NONE); label3.setData("name", "label2"); label3.setText("Modification Save Error!"); label3.setFont(new Font(Display.getCurrent(), "Arial", 10, SWT.BOLD)); label3.setForeground(new Color(Display.getCurrent(), 128, 0, 0)); label3.setVisible(false); final Label label4 = new Label(form.getBody(), SWT.NONE); label4.setData("name", "label4"); label4.setFont(new Font(Display.getCurrent(), "Arial", 10, SWT.BOLD)); label4.setForeground(new Color(Display.getCurrent(), 200, 0, 0)); label4.setVisible(false); final TableEditor edit = new TableEditor(table); // The editor must have the same size as the cell and must // not be any smaller than 50 pixels. edit.horizontalAlignment = SWT.LEFT; edit.grabHorizontal = true; edit.minimumWidth = 50; // editing the second column tableSelectionListener = new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } @Override public void widgetSelected(SelectionEvent arg0) { // TODO Auto-generated method stub Control oldEditor = editor.getEditor(); if (oldEditor != null) oldEditor.dispose(); } }; table.addSelectionListener(tableSelectionListener); tableListener = new Listener() { @Override public void handleEvent(Event arg0) { // TODO Auto-generated method stub Point pt = new Point(arg0.x, arg0.y); for (final TableItem item : table.getItems()) { String editable = (String) item.getData("editable"); if (editable.equals("true")) { for (int i = 0; i < table.getColumnCount(); i++) { Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { Control oldEditor = editor.getEditor(); if (oldEditor != null) oldEditor.dispose(); if (item.getData("type").equals("int")) { Text newEditor = new Text(table, SWT.NONE); newEditor.setText(item.getText(EDITABLECOLUMN)); newEditor.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent arg0) { // TODO Auto-generated method stub Text text = (Text) editor.getEditor(); editor.getItem().setText(EDITABLECOLUMN, text.getText()); String methodName = (String) item.getData(); for (Method m : spec.getClass().getMethods()) { if (m.getName().equals(methodName)) { try { m.invoke(spec, new Object[] {Integer.parseInt(text.getText())}); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } item.setBackground(new Color(Display.getCurrent(), 255, 250, 160)); item.setData("modified", "true"); submitButton.setEnabled(true); } }); newEditor.selectAll(); newEditor.setFocus(); editor.setEditor(newEditor, item, EDITABLECOLUMN); break; } if (item.getData("type").equals("string")) { Text newEditor = new Text(table, SWT.NONE); newEditor.setText(item.getText(EDITABLECOLUMN)); newEditor.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent arg0) { // TODO Auto-generated method stub Text text = (Text) editor.getEditor(); editor.getItem().setText(EDITABLECOLUMN, text.getText()); String methodName = (String) item.getData(); for (Method m : spec.getClass().getMethods()) { if (m.getName().equals(methodName)) { try { m.invoke(spec, new Object[] {text.getText()}); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } item.setBackground(new Color(Display.getCurrent(), 255, 250, 160)); item.setData("modified", "true"); submitButton.setEnabled(true); } }); newEditor.selectAll(); newEditor.setFocus(); editor.setEditor(newEditor, item, EDITABLECOLUMN); break; } else if (item.getData("type").equals("date")) { CalendarCombo calendar = new CalendarCombo(table, SWT.CALENDAR); XMLGregorianCalendar cal = (XMLGregorianCalendar) item.getData("date"); if (cal == null) { calendar.setDate(new Date(System.currentTimeMillis())); } else { GregorianCalendar ca = cal.toGregorianCalendar(); calendar.setDate(ca.getTime()); } // calendar.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent arg0) { // TODO Auto-generated method stub CalendarCombo cc = (CalendarCombo) editor.getEditor(); editor.getItem().setText(EDITABLECOLUMN, cc.getDateAsString()); String methodName = (String) item.getData(); for (Method m : spec.getClass().getMethods()) { if (m.getName().equals(methodName)) { try { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(cc.getDate().getTime()); XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); m.invoke(spec, new Object[] {date2}); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DatatypeConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; } } item.setBackground(new Color(Display.getCurrent(), 255, 250, 160)); item.setData("modified", "true"); submitButton.setEnabled(true); } }); calendar.setFocus(); editor.setEditor(calendar, item, EDITABLECOLUMN); break; } } } // for } } } }; table.addListener(SWT.MouseDoubleClick, tableListener); submitButton.setLayoutData(gridData); buttonSelectionListener = new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent arg0) { // TODO Auto-generated method stub } @Override public void widgetSelected(SelectionEvent arg0) { // TODO Auto-generated method stub try { // Specimen speca = null; // for(IWorkbenchPage p : pages){ // IViewReference ivrs [] = p.getViewReferences(); // for(IViewReference ivr : ivrs){ // if(ivr.getId().equals("TestView.view")){ // View v = (View)ivr.getView(true); // speca = v.getGallery().getSelection()[0].getData("spec", spec); // if(spec.getMissingInfo()==0){ // v.getGallery().getSelection()[0].setBackground(new // Color(Display.getCurrent(), 255,255,255)); // } // break; // } // } // } DataUtilsService service = new DataUtilsService(); // Missing DataUtilsDelegate delegate = service.getDataUtilsPort(); // Specimen ss = delegate.getSpecimenById(spec.getSpecimenId());//getView List<SpecCollectorMap> scms = delegate.getScms(spec.getSpecimenId()); // System.out.println(ss.getSpecimenId()+"***"+scms.size()); if (spec == null) { System.out.println("NULL ID!"); } if (scms == null) { System.out.println("NULL SCMS!"); } String scmIds = ""; int index = 0; for (SpecCollectorMap scm : scms) { if (index == 0) { scmIds += scm.getSpecCollectorMapId(); } else { scmIds += ("-" + scm.getSpecCollectorMapId()); } index++; } System.out.println("scmIds = " + scmIds); System.out.println("specimen Id = " + spec.getSpecimenId()); if (scmIds.equals("")) scmIds = "0"; Specimen updatedSpecimen = delegate.updateSpecimen(spec, scmIds); for (TableItem item : table.getItems()) { item.setBackground(new Color(Display.getCurrent(), 255, 255, 255)); submitButton.setEnabled(false); } IWorkbenchPage pages[] = getEditorSite().getWorkbenchWindow().getPages(); for (IWorkbenchPage p : pages) { IViewReference ivrs[] = p.getViewReferences(); for (IViewReference ivr : ivrs) { if (ivr.getId().equals("TestView.view")) { View v = (View) ivr.getView(true); v.getGallery().getSelection()[0].setData(updatedSpecimen); if (spec.getMissingInfo() == 0) { v.getGallery() .getSelection()[0] .setBackground(new Color(Display.getCurrent(), 255, 255, 255)); } spec = updatedSpecimen; break; } } } label2.setVisible(true); label3.setVisible(false); label4.setVisible(false); } catch (Exception e) { label2.setVisible(false); label3.setVisible(true); // label4.setText(e.getMessage()); label4.setVisible(true); e.printStackTrace(); } } }; // scientific name inserting submitButton.addSelectionListener(buttonSelectionListener); System.out.println(Platform.getInstallLocation().getURL().getPath()); System.out.println(Platform.getInstanceLocation().getURL().getPath()); Image image = ImageFactory.loadImage(Display.getCurrent(), ImageFactory.ACTION_SYNC); IStatusLineManager manager = this.getEditorSite().getActionBars().getStatusLineManager(); Action toggleBotton = new SyncIDropAction("Sync with iDrop", ImageDescriptor.createFromImage(image), manager); if (spec.getIdropSync() == null || spec.getIdropSync() == 0) { toggleBotton.setEnabled(true); } else toggleBotton.setEnabled(true); form.getToolBarManager().add(toggleBotton); form.getToolBarManager().update(true); }
/* * Verify the input table and according the vector amount of each input port * the signals are inserted into the sensors list specification */ public void populateActuatorsTable(Table inputTable, ArrayList<SystemFunction> functions) { // If table have data clear it if (table.getItemCount() > 0) clearData(); Device actuator; TableItem item; TableEditor teEditor; Button preWriting; // Button bperiodic; Combo cActuator; // Insert the inputs that not need of pre-writing for (int i = 0; i < inputTable.getItemCount(); i++) { preWriting = (Button) inputTable.getItem(i).getData("PreWcheck"); cActuator = (Combo) inputTable.getItem(i).getData("actuator"); if (!preWriting.getSelection()) { Label port = (Label) inputTable.getItem(i).getData("port"); Text size = (Text) inputTable.getItem(i).getData("size"); for (int z = 0; z < Integer.valueOf(size.getText()); z++) { item = new TableItem(table, SWT.NONE); item.setText(0, port.getText() + (z + 1)); if (!cActuator.getText().isEmpty()) item.setText(1, cActuator.getText()); // insert item components teEditor = new TableEditor(table); Button bperiodic = new Button(table, SWT.CHECK); bperiodic.setEnabled(false); bperiodic.pack(); teEditor.minimumWidth = bperiodic.getSize().x; teEditor.horizontalAlignment = SWT.LEFT; teEditor.setEditor(bperiodic, item, 4); item.setData("periodic", bperiodic); } } } // insert the inputs that are specified in the pre-writing process for (int i = 0; i < functions.size(); i++) { for (int z = 0; z < functions.get(i).getOutputs().size(); z++) { item = new TableItem(table, SWT.NONE); item.setText(0, functions.get(i).getOutputs().get(z)); teEditor = new TableEditor(table); Button bperiodic = new Button(table, SWT.CHECK); bperiodic.setEnabled(false); bperiodic.pack(); teEditor.minimumWidth = bperiodic.getSize().x; teEditor.horizontalAlignment = SWT.LEFT; teEditor.setEditor(bperiodic, item, 4); item.setData("periodic", bperiodic); } } // populate Array of actuators for (int i = 0; i < table.getItemCount(); i++) { actuator = new Device(ACTUATION); actuator.setIndex(i); actuator.inputs.add(table.getItem(i).getText(0)); if (table.getItem(i).getText(1).isEmpty()) actuator.setName(table.getItem(i).getText(1)); actuators.add(actuator); } checkSpecified(); }
/** Open. */ public void open() { try { attribute2Value = new HashMap<EAttribute, String>(); Shell parent = getParent(); dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialogShell.setLayout(new FormLayout()); { button2 = new Button(dialogShell, SWT.PUSH | SWT.CENTER); FormData button2LData = new FormData(); button2LData.left = new FormAttachment(0, 1000, 330); button2LData.top = new FormAttachment(0, 1000, 310); button2LData.width = 99; button2LData.height = 25; button2.setLayoutData(button2LData); button2.setText("Cancel"); button2.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { cancel = true; dialogShell.close(); } }); } { button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER); FormData button1LData = new FormData(); button1LData.left = new FormAttachment(0, 1000, 229); button1LData.top = new FormAttachment(0, 1000, 310); button1LData.width = 95; button1LData.height = 25; button1.setLayoutData(button1LData); button1.setText("Ok"); button1.setEnabled(true); button1.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { cancel = false; for (int i = 0, n = table1.getItemCount(); i < n; i++) { TableItem item = table1.getItem(i); if (item.getChecked()) { EAttribute attribut = attributeTypen.get(i); attribute2Value.put(attribut, item.getText(2)); } } dialogShell.close(); } }); } { FormData table1LData = new FormData(); table1LData.left = new FormAttachment(0, 1000, 12); table1LData.top = new FormAttachment(0, 1000, 12); table1LData.width = 400; table1LData.height = 269; table1 = new Table( dialogShell, SWT.CHECK | SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.VIRTUAL); table1.setLayoutData(table1LData); table1.setHeaderVisible(true); table1.setLinesVisible(true); { tableColumn1 = new TableColumn(table1, SWT.CENTER); tableColumn1.setText("Create"); tableColumn1.setWidth(60); } { tableColumn2 = new TableColumn(table1, SWT.LEFT); tableColumn2.setText("Attribute"); tableColumn2.setWidth(200); } { tableColumn3 = new TableColumn(table1, SWT.LEFT); tableColumn3.setText("Value"); tableColumn3.setWidth(140); } vavueCorect = new HashMap<TypeEditorValidator, Boolean>(); typeEditorValidators = new ArrayList<TypeEditorValidator>(); for (EAttribute attr : attributeTypen) { TableItem tableItem = new TableItem(table1, SWT.NONE); TypeEditorValidator typeEditorValidator = new TypeEditorValidator(node, attr); tableItem.setText(1, attr.getName()); tableItem.setText(2, typeEditorValidator.getDefaultValue()); table1.addListener( SWT.Selection, new Listener() { @Override public void handleEvent(Event event) { if (event.detail == SWT.CHECK) { TableItem tItem = (TableItem) event.item; corectValueTest(tItem, tItem.getText(2)); refreshOkButton(); } } }); typeEditorValidators.add(typeEditorValidator); /* * if (typeEditorValidator.isValid(typeEditorValidator * .getDefaultValue()) == null) { * vavueCorect.put(typeEditorValidator, corect); } else { * vavueCorect.put(typeEditorValidator, incorect); * button1.setEnabled(false); } */ } final TableEditor editor = new TableEditor(table1); editor.horizontalAlignment = SWT.LEFT; editor.grabHorizontal = true; table1.addMouseListener( new MouseAdapter() { @Override public void mouseDown(MouseEvent event) { // Dispose any existing editor Control old = editor.getEditor(); if (old != null) old.dispose(); // Determine where the mouse was clicked Point pt = new Point(event.x, event.y); // Determine which row was selected final TableItem item = table1.getItem(pt); if (item != null) { // Determine which column was selected int column = -1; for (int i = 0, n = table1.getColumnCount(); i < n; i++) { Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { // This is the selected column column = i; break; } } // Column 2 holds dropdowns if (column == 2) { // Create the Text object for our editor final Text text = new Text(table1, SWT.NONE); text.setForeground(item.getForeground()); // Transfer any text from the cell to the Text // control, // set the color to match this row, select the // text, // and set focus to the control text.setText(item.getText(column)); text.setForeground(item.getForeground()); text.selectAll(); text.setFocus(); // Recalculate the minimum width for the editor editor.minimumWidth = text.getBounds().width; // Set the control into the editor editor.setEditor(text, item, column); // Add a handler to transfer the text back to // the cell // any time it's modified final int col = column; text.addModifyListener( new ModifyListener() { @Override public void modifyText(ModifyEvent e) { item.setChecked(true); corectValueTest(item, text.getText()); item.setText(col, text.getText()); } }); } } } }); } dialogShell.layout(); dialogShell.setSize(450, 380); Rectangle shellBounds = getParent().getBounds(); Point dialogSize = dialogShell.getSize(); dialogShell.setLocation( shellBounds.x + (shellBounds.width - dialogSize.x) / 2, shellBounds.y + (shellBounds.height - dialogSize.y) / 2); dialogShell.open(); Display display = dialogShell.getDisplay(); while (!dialogShell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } catch (Exception e) { e.printStackTrace(); } }
/** Create the dialog area and place correctly the user interfaces widgets */ @Override protected Control createDialogArea(Composite parent) { Composite comp = (Composite) super.createDialogArea(parent); GridLayout gridLayout = new GridLayout(1, false); comp.setLayout(gridLayout); GridData gridData = new GridData(GridData.FILL_BOTH); comp.setLayoutData(gridData); Group body = new Group(comp, SWT.SHADOW_ETCHED_IN); gridLayout = new GridLayout(1, false); body.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); body.setLayoutData(gridData); Composite eventBody = new Composite(body, SWT.FILL); gridLayout = new GridLayout(2, false); eventBody.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); eventBody.setLayoutData(gridData); Composite eBody = new Composite(eventBody, SWT.FILL); gridLayout = new GridLayout(2, false); eBody.setLayout(gridLayout); gridData = new GridData(GridData.FILL_VERTICAL); gridData.verticalAlignment = SWT.TOP; eBody.setLayoutData(gridData); // Events Label eventLbl = new Label(eBody, SWT.LEFT); eventLbl.setText("Event:"); eventCbx = new Combo(eBody, SWT.NONE); fillEventTypesList(); // Create a new Event if (event == null) { event = createEvent(eventCbx.getItem(0)); } else { // We need to copy the original event in case the user cancels his changes event = WidgetCopier.copy(event); } eventCbx.setText(event.getEventName()); eventCbx.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String eventName = ((Combo) e.getSource()).getText(); event.setEventName(eventName); createProperties(); // DS-3322 - Page Designer - Refactoring - begin // event.eAdapters().remove(localizable); // localizable = (Localizable) // EventLocalizableAdapterFactory.INSTANCE.adapt(event, Localizable.class); // editor.setLocalizable(localizable); // editor.setReadOnly(isReadOnly(widget)); // DS-3322 - Page Designer - Refactoring - end fillFunctionsList(); String selection = null; if (fctList.getSelection().length > 0) selection = fctList.getSelection()[0]; refreshParamControl(selection); } }); // Functions Label functionsLbl = new Label(eBody, SWT.LEFT); functionsLbl.setText("Functions:"); gridData = new GridData(); gridData.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; functionsLbl.setLayoutData(gridData); fctList = new List(eBody, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL); gridData = new GridData(GridData.FILL_VERTICAL); gridData.heightHint = 120; gridData.widthHint = 120; fctList.setLayoutData(gridData); fillFunctionsList(); fctList.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String funcName = fctList.getSelection()[0]; event.setFunctionName(funcName); createParameters(); fillParametersList(); refreshParamControl(funcName); } }); // parameters group Group paramGroup = new Group(eventBody, SWT.SHADOW_ETCHED_IN | SWT.FILL); paramGroup.setText(" Parameters "); gridLayout = new GridLayout(1, false); paramGroup.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); paramGroup.setLayoutData(gridData); userParamControl = new UserParameterControl(paramGroup, SWT.FILL); userParamControl.setInput(event, null); userParamControl.setEnabled(false); if (!StringUtils.isEmpty(event.getFunctionName())) { fctList.setSelection(new String[] {event.getFunctionName()}); refreshParamControl(event.getFunctionName()); } // attributes group Group def = new Group(body, SWT.SHADOW_ETCHED_IN); def.setText(" Attributes "); gridLayout = new GridLayout(1, false); def.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); def.setLayoutData(gridData); // Parameters table paramsTbl = new Table(def, SWT.SINGLE); gridData = new GridData(GridData.FILL_BOTH); gridData.heightHint = 100; paramsTbl.setLayoutData(gridData); paramsTbl.setHeaderVisible(true); paramsTbl.setLinesVisible(true); addColumn(paramsTbl, "Attribute", 100); addColumn(paramsTbl, "Value", 300); paramsTbl.addListener( SWT.MeasureItem, new Listener() { public void handleEvent(org.eclipse.swt.widgets.Event event) { Double dou = new Double(event.gc.getFontMetrics().getHeight() * 1.12); event.height = dou.intValue(); } }); final TableEditor paramsTblEditor = new TableEditor(paramsTbl); // The editor must have the same size as the cell and must not be any // smaller than 50 pixels. paramsTblEditor.horizontalAlignment = SWT.LEFT; paramsTblEditor.grabHorizontal = true; paramsTblEditor.grabVertical = true; paramsTblEditor.minimumWidth = 50; paramsTbl.addListener( SWT.MouseDown, new Listener() { public void handleEvent(org.eclipse.swt.widgets.Event event) { int nbColumns = paramsTbl.getColumnCount(); Rectangle clientArea = paramsTbl.getClientArea(); Point pt = new Point(event.x, event.y); int index = paramsTbl.getTopIndex(); while (index < paramsTbl.getItemCount()) { boolean visible = false; TableItem item = paramsTbl.getItem(index); for (int cx = 0; cx < nbColumns; cx++) { Rectangle rect = item.getBounds(cx); if (rect.contains(pt)) { installCellEditor(paramsTblEditor, item, index, cx); } if (!visible && rect.intersects(clientArea)) { visible = true; } } if (!visible) return; index++; } } }); fillParametersList(); def = new Group(body, SWT.SHADOW_ETCHED_IN); def.setText(" Confirmation Translations "); gridLayout = new GridLayout(1, false); def.setLayout(gridLayout); gridData = new GridData(GridData.FILL_BOTH); def.setLayoutData(gridData); createProperties(); // DS-3322 - Page Designer - Refactoring - begin // editor = LocalizableEditorSupportFactory.createLocalizableEditor(def, 2, false, true); // localizable = (Localizable) EventLocalizableAdapterFactory.INSTANCE.adapt(event, // Localizable.class); // editor.setLocalizable(localizable); // editor.setReadOnly(isReadOnly(widget)); // addListeners(); // DS-3322 - Page Designer - Refactoring - end return comp; }