use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.
the class ExtraComposite method useProjectSettingButtonClick.
/*
* (non-Javadoc)
*
* @see org.talend.designer.core.ui.views.jobsettings.AbstractPreferenceComposite#useProjectSettingButtonClick()
*/
@Override
protected void useProjectSettingButtonClick() {
boolean flag = useProjectSetting.getSelection();
setMainCompositeEnable(!flag);
topComposite.setEnabled(true);
ElementParameter2ParameterType.setParameterValue(pType, EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS.getName(), Boolean.valueOf(flag));
PropertyChangeCommand cmd = new PropertyChangeCommand(elem, EParameterName.IMPLICITCONTEXT_USE_PROJECT_SETTINGS.getName(), Boolean.valueOf(flag));
getCommandStack().execute(cmd);
updateContextValue(flag);
if (flag) {
useProjectSetting();
}
}
use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.
the class AbstractTraceAction method run.
@Override
public void run() {
List selection = getSelectedObjects();
Object input = selection.get(0);
if (input instanceof ConnectionPart) {
ConnectionPart connPart = (ConnectionPart) input;
List childParts = connPart.getChildren();
for (Object part : childParts) {
if (part != null && part instanceof ConnectionTraceEditPart) {
ConnectionTraceEditPart tracePart = (ConnectionTraceEditPart) part;
Connection conn = (Connection) connPart.getModel();
execute(new PropertyChangeCommand(conn, EParameterName.TRACES_CONNECTION_ENABLE.getName(), isEnableAction()));
tracePart.refresh();
break;
}
}
}
if (input instanceof ConnLabelEditPart) {
ConnLabelEditPart labelPart = (ConnLabelEditPart) input;
ConnectionPart connPart = (ConnectionPart) labelPart.getParent();
List childParts = connPart.getChildren();
for (Object part : childParts) {
if (part != null && part instanceof ConnectionTraceEditPart) {
ConnectionTraceEditPart tracePart = (ConnectionTraceEditPart) part;
Connection conn = (Connection) connPart.getModel();
execute(new PropertyChangeCommand(conn, EParameterName.TRACES_CONNECTION_ENABLE.getName(), isEnableAction()));
tracePart.refresh();
break;
}
}
}
if (input instanceof ConnectionTraceEditPart) {
ConnectionTraceEditPart tracePart = (ConnectionTraceEditPart) input;
ConnectionPart connPart = (ConnectionPart) tracePart.getParent();
Connection conn = (Connection) connPart.getModel();
execute(new PropertyChangeCommand(conn, EParameterName.TRACES_CONNECTION_ENABLE.getName(), isEnableAction()));
tracePart.refresh();
}
}
use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method addDragAndDropTarget.
/**
* Accept Text and StyledText control.
*
* @param labelText
*/
public void addDragAndDropTarget(final Control textControl) {
DropTargetListener dropTargetListener = new DropTargetListener() {
String propertyName = null;
@Override
public void dragEnter(final DropTargetEvent event) {
}
@Override
public void dragLeave(final DropTargetEvent event) {
}
@Override
public void dragOperationChanged(final DropTargetEvent event) {
}
@Override
public void dragOver(final DropTargetEvent event) {
if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
propertyName = getParameterName(textControl);
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getName().equals(propertyName)) {
if (param.isReadOnly()) {
event.detail = DND.ERROR_INVALID_DATA;
}
}
}
}
}
@Override
public void drop(final DropTargetEvent event) {
if (propertyName != null) {
String text;
if (textControl instanceof StyledText) {
text = ((StyledText) textControl).getText() + (String) event.data;
((StyledText) textControl).setText(text);
} else {
text = ((Text) textControl).getText() + (String) event.data;
((Text) textControl).setText(text);
}
Command cmd = new PropertyChangeCommand(elem, propertyName, text);
// getCommandStack().execute(cmd);
executeCommand(cmd);
}
}
@Override
public void dropAccept(final DropTargetEvent event) {
}
};
DropTarget target = new DropTarget(textControl, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
target.setTransfer(transfers);
target.addDropListener(dropTargetListener);
}
use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.
the class AbstractSchemaController method createComboCommand.
@Override
protected Command createComboCommand(CCombo combo) {
IMetadataTable repositoryMetadata = null;
String fullParamName = (String) combo.getData(PARAMETER_NAME);
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
//$NON-NLS-1$
String value = new String("");
IElementParameter param = elem.getElementParameter(fullParamName);
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
// if change to build-in, unuse the validation rule if the component has.
boolean isValRulesLost = false;
IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectBuildInMsg"))) {
//$NON-NLS-1$
return null;
} else {
isValRulesLost = true;
}
}
org.talend.core.model.metadata.builder.connection.Connection connection = null;
if (elem instanceof Node) {
Node node = (Node) elem;
Command baseCommand = null;
boolean isReadOnly = false;
String newRepositoryIdValue = null;
if (node.getMetadataFromConnector(param.getContext()) != null) {
isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
}
if (//$NON-NLS-1$
value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
//$NON-NLS-1$
boolean hasMetadataInput = false;
if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
hasMetadataInput = true;
}
repositoryMetadata = new MetadataTable();
if (hasMetadataInput) {
for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
repositoryMetadata = connec.getMetadataTable().clone();
}
}
}
} else if (value.equals(EmfComponent.REPOSITORY)) {
// Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
/* 16969 */
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
if (repobj != null) {
Property tmpproperty = repobj.getProperty();
if (tmpproperty != null) {
item = tmpproperty.getItem();
}
}
// item = factory.getLastVersion(propertySelected).getProperty().getItem();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
final ConnectionItem connectionItem = (ConnectionItem) item;
if (connectionItem != null) {
connection = connectionItem.getConnection();
}
}
}
IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
String schemaSelected = (String) repositorySchemaType.getValue();
if (schemaSelected == null) {
//$NON-NLS-1$
schemaSelected = "";
}
/* value can be devided means the value like "connectionid - label" */
//$NON-NLS-1$
String[] keySplitValues = schemaSelected.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = keySplitValues[0];
String tableLabel = keySplitValues[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property tmpproperty = repobj.getProperty();
if (tmpproperty != null) {
item = tmpproperty.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
final ConnectionItem connectionItem = (ConnectionItem) item;
if (connectionItem != null) {
connection = connectionItem.getConnection();
}
}
if (item != null && item instanceof ConnectionItem) {
boolean findTable = false;
Set<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = null;
IGenericWizardService wizardService = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
}
if (wizardService != null && wizardService.isGenericItem(item)) {
tables = new HashSet<>(wizardService.getMetadataTables(connection));
} else {
tables = ConnectionHelper.getTables(connection);
}
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
if (table.getLabel().equals(tableLabel)) {
repositoryMetadata = ConvertionHelper.convert(table);
newRepositoryIdValue = schemaSelected;
findTable = true;
break;
}
}
if (!findTable) {
repositoryMetadata = new MetadataTable();
}
} else {
repositoryMetadata = new MetadataTable();
}
} else {
// value only got a empty string
repositoryMetadata = new MetadataTable();
}
} else {
baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
CompoundCommand cc = new CompoundCommand();
if (baseCommand != null) {
cc.add(baseCommand);
} else {
RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
changeMetadataCommand.setConnection(connection);
cc.add(changeMetadataCommand);
}
// unuse the validation rules of the component.
if (isValRulesLost) {
ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
}
return cc;
}
return null;
}
use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.
the class ComponentListController method updateComponentList.
protected static void updateComponentList(Collection<INode> nodeList, INode currentNode, IElementParameter param, boolean isSelectDefaultItem) {
final Collection<String> componentDisplayNames = new ArrayList<String>();
final Collection<String> componentUniqueNames = new ArrayList<String>();
for (INode node : nodeList) {
if (node.getJobletNode() != null) {
node = node.getJobletNode();
}
final String uniqueName = node.getUniqueName();
if (uniqueName.equals(currentNode.getUniqueName())) {
continue;
}
//$NON-NLS-1$
String displayName = (String) node.getElementParameter("LABEL").getValue();
if (displayName == null) {
displayName = uniqueName;
}
if (displayName.indexOf("__UNIQUE_NAME__") != -1) {
//$NON-NLS-1$
//$NON-NLS-1$
displayName = displayName.replaceAll("__UNIQUE_NAME__", uniqueName);
}
if (!displayName.equals(uniqueName)) {
//$NON-NLS-1$
displayName = uniqueName + " - " + displayName;
}
componentUniqueNames.add(uniqueName);
componentDisplayNames.add(displayName);
}
param.setListItemsDisplayName(componentDisplayNames.toArray(new String[0]));
final String[] componentValueList = componentUniqueNames.toArray(new String[0]);
param.setListItemsValue(componentValueList);
Object value = param.getValue();
if (!componentUniqueNames.contains(value) && isSelectDefaultItem) {
String newValue = null;
if (!param.isDynamicSettings()) {
if (!componentUniqueNames.isEmpty()) {
if (value == null || value.equals("")) {
//$NON-NLS-1$
currentNode.setPropertyValue(getParameterName(param), componentValueList[0]);
if (currentNode instanceof IGraphicalNode) {
IGraphicalNode node = (IGraphicalNode) currentNode;
node.checkAndRefreshNode();
((IProcess2) node.getProcess()).setProcessModified(true);
} else if (currentNode instanceof IConnection) {
((IProcess2) ((IConnection) currentNode).getSource().getProcess()).setProcessModified(true);
}
} else {
newValue = componentValueList[0];
}
} else {
// removed the old value.
//$NON-NLS-1$
newValue = "";
}
}
if (!("".equals(newValue)) && newValue != null) {
//$NON-NLS-1$
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (part instanceof AbstractMultiPageTalendEditor) {
AbstractTalendEditor te = ((AbstractMultiPageTalendEditor) part).getTalendEditor();
CommandStack cmdStack = (CommandStack) te.getAdapter(CommandStack.class);
cmdStack.execute(new PropertyChangeCommand(currentNode, getParameterName(param), ""));
}
}
}
}
Aggregations