/** | |
* Copyright (c)2020 CEA LIST, Committer Name, and others. | |
* | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License 2.0 | |
* which accompanies this distribution, and is available at | |
* https://www.eclipse.org/legal/epl-2.0/ | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* CEA LIST - Initial API and implementation | |
* Gabriel Pedroza (CEA LIST) gabriel.pedroza@cea.fr | |
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr | |
* | |
*/ | |
package org.eclipse.papyrus.pdp4eng.designer.ui.internal; | |
import java.util.ArrayList; | |
import org.eclipse.jface.viewers.TableViewer; | |
import org.eclipse.jface.viewers.TableViewerColumn; | |
import org.eclipse.papyrus.pdp4eng.designer.engine.api.IStrategy; | |
import org.eclipse.papyrus.pdp4eng.designer.engine.api.IStrategyCatalog; | |
import org.eclipse.papyrus.pdp4eng.designer.engine.api.IStrategyEngine; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.events.SelectionAdapter; | |
import org.eclipse.swt.events.SelectionEvent; | |
import org.eclipse.swt.layout.GridData; | |
import org.eclipse.swt.layout.GridLayout; | |
import org.eclipse.swt.widgets.Button; | |
import org.eclipse.swt.widgets.Display; | |
import org.eclipse.swt.widgets.Event; | |
import org.eclipse.swt.widgets.Listener; | |
import org.eclipse.swt.widgets.Shell; | |
import org.eclipse.swt.widgets.Table; | |
import org.eclipse.swt.widgets.TableItem; | |
/** | |
* Req004.002: the system shall provide for Model User to show name and goal of strategy | |
* Req004.003: the system shall provide for Model User to execute the selected strategy | |
* Req004.004: the system shall provide menus to execute Strategy | |
* @author PT202707 | |
* | |
*/ | |
public class StrategyDialog { | |
protected Object result=null; | |
protected Display display; | |
protected Shell shell; | |
protected Button okbt; | |
protected Button cancelbt; | |
protected IStrategyEngine engine=null; | |
protected boolean canExecute=false; | |
protected ArrayList<Table> tableList= new ArrayList<Table>(); | |
protected org.eclipse.uml2.uml.Package targetpackage=null; | |
protected org.eclipse.uml2.uml.Element context=null; | |
public StrategyDialog(org.eclipse.uml2.uml.Element context, IStrategyEngine engine, IStrategyCatalog strategyCatalog) { | |
this.engine=engine; | |
this.context=context; | |
display = Display.getDefault(); | |
shell = new Shell(display); | |
shell.setSize(250, 200); | |
shell.setText("Data-oriented Strategies Dialog"); | |
GridLayout gl = new GridLayout(); | |
gl.numColumns = 2; | |
shell.setLayout(gl); | |
final Table table = new Table(shell, SWT.BORDER | SWT.CHECK | SWT.MULTI | |
| SWT.FULL_SELECTION); | |
TableViewer viewer= new TableViewer(table); | |
viewer.getTable().addListener(SWT.Selection, new Listener() { | |
public void handleEvent(Event event) { | |
if ((event.detail == SWT.CHECK) && (event.item instanceof TableItem)) { | |
TableItem selectedTableItem=(TableItem)event.item; | |
TableItem[] itemSet=table.getItems(); | |
for (int i=0; i<itemSet.length;i++){ | |
if(itemSet[i]==selectedTableItem){ | |
System.err.println(" checked "+itemSet[i].getData()); | |
itemSet[i].setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN)); | |
itemSet[i].setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GREEN)); | |
engine.setStrategyToExecute((IStrategy)itemSet[i].getData()); | |
} | |
else { | |
System.err.println("not checked "+itemSet[i].getData()); | |
itemSet[i].setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); | |
itemSet[i].setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); | |
itemSet[i].setChecked(false); | |
} | |
} | |
} | |
} | |
} | |
); | |
//TableViewer | |
createColumn(viewer); | |
viewer.setContentProvider(new StrategyContentProvider()); | |
StrategyLabelProvider L=new StrategyLabelProvider(); | |
viewer.setLabelProvider(L); | |
viewer.setInput(strategyCatalog.getPossibleStrategies()); | |
final GridData gd = new GridData(GridData.FILL_BOTH); | |
gd.horizontalSpan = 2; | |
table.setLayoutData(gd); | |
table.setHeaderVisible(true); | |
okbt = new Button(shell, SWT.NONE); | |
//okbt.setBounds(294, 7, 59, 23); | |
okbt.setText("Execute"); | |
cancelbt = new Button(shell, SWT.NONE); | |
//cancelbt.setBounds(213, 7, 59, 23); | |
cancelbt.setText("Cancel"); | |
//packagebutton= new Button(shell, SWT.NONE); | |
// packagebutton.setBounds(0, 7, 150, 23); | |
//packagebutton.setText("Choose package"); | |
addButtonListener(); | |
shell.pack(); | |
} | |
private void createColumn(TableViewer viewer) { | |
// name column | |
TableViewerColumn nameColumn = new TableViewerColumn(viewer, SWT.RESIZE); | |
nameColumn.getColumn().setText("Strategy Name"); | |
nameColumn.getColumn().setWidth(200); | |
nameColumn.getColumn().setResizable(true); | |
nameColumn.getColumn().setMoveable(false); | |
TableViewerColumn descColumn = new TableViewerColumn(viewer, SWT.RESIZE); | |
descColumn.getColumn().setText("Strategy Description"); | |
descColumn.getColumn().setWidth(500); | |
descColumn.getColumn().setResizable(true); | |
descColumn.getColumn().setMoveable(false); | |
// TableViewerColumn pluginColumn = new TableViewerColumn(viewer, SWT.RESIZE); | |
// pluginColumn.getColumn().setText("Plugin source"); | |
// pluginColumn.getColumn().setWidth(200); | |
// pluginColumn.getColumn().setResizable(true); | |
// pluginColumn.getColumn().setMoveable(false); | |
} | |
public void addButtonListener(){ | |
//Execute button selection | |
okbt.addSelectionListener(new SelectionAdapter() { | |
public void widgetSelected(SelectionEvent event) { | |
canExecute=true; | |
shell.close(); | |
} | |
}); | |
//Cancel button selection | |
cancelbt.addSelectionListener(new SelectionAdapter() { | |
public void widgetSelected(SelectionEvent event) { | |
canExecute=false; | |
shell.close(); | |
} | |
}); | |
} | |
/** | |
* Open the dialog. | |
* @return the result | |
*/ | |
public Object open() { | |
shell.open(); | |
while(!shell.isDisposed()) { | |
if(!display.readAndDispatch()) { | |
display.sleep(); | |
} | |
} | |
return result; | |
} | |
public boolean canExecute() { | |
return canExecute; | |
} | |
/** | |
public static void main(String[] argv) { | |
StrategyEngineFactory engineFactory= StrategyEngineFactory.getInstance(); | |
CatalogFactory catalogFactory= new CatalogFactory(); | |
engineFactory.getCurrentEngine().connectACatalog(catalogFactory.createCatalog("toto")); | |
StrategyDialog propagationToolShell= new StrategyDialog(null,engineFactory.getCurrentEngine(), engineFactory.getCurrentEngine().getCatalog(0)); | |
propagationToolShell.open(); | |
}**/ | |
} |