use of org.talend.repository.model.ItemVersionObject in project tdi-studio-se by Talend.
the class VersionManagementPage method versionLatest.
private void versionLatest() {
List<ItemVersionObject> tableList = new ArrayList<ItemVersionObject>();
tableList.addAll(checkedObjects);
for (ItemVersionObject object : checkedObjects) {
if (object.getRepositoryNode() != null) {
List<Relation> relations = builder.getItemsJobRelatedTo(object.getRepositoryNode().getId(), object.getOldVersion(), RelationshipItemBuilder.JOB_RELATION);
for (Relation relation : relations) {
try {
IRepositoryViewObject obj = FACTORY.getLastVersion(relation.getId());
if (obj != null) {
for (ItemVersionObject obj2 : versionObjects) {
if (obj2.getItem() == obj.getProperty().getItem()) {
ItemVersionObject relat = obj2;
if (!tableList.contains(relat)) {
tableList.add(relat);
checkAllVerSionLatest(tableList, relat);
}
break;
}
}
}
} catch (PersistenceException et) {
ExceptionHandler.process(et);
}
}
}
}
removeItemElements(checkedObjects);
checkedObjects.clear();
checkedObjects.addAll(tableList);
refreshTableItems();
refreshCheckedTreeView();
}
use of org.talend.repository.model.ItemVersionObject in project tdi-studio-se by Talend.
the class VersionManagementPage method updateItemsVersion.
@Override
protected void updateItemsVersion() {
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>(project, "Update items version") {
@Override
protected void run() throws LoginException, PersistenceException {
//$NON-NLS-1$
monitor.beginTask("Update items version", checkedObjects.size());
Map<String, String> versions = new HashMap<String, String>();
for (int i = 0; i < checkedObjects.size(); i++) {
ItemVersionObject object = checkedObjects.get(i);
versions.put(object.getItem().getProperty().getId(), object.getOldVersion());
}
for (ItemVersionObject object : checkedObjects) {
IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
if (repositoryObject != null && repositoryObject.getProperty() != null) {
if (!object.getNewVersion().equals(repositoryObject.getVersion())) {
final Item item = object.getItem();
Property itemProperty = item.getProperty();
itemProperty.setVersion(object.getNewVersion());
monitor.subTask(itemProperty.getLabel());
try {
// for bug 12853 ,version management doesn't work for joblet because eResource
// is null
IRepositoryViewObject obj = null;
if (itemProperty.eResource() == null) {
ItemState state = item.getState();
if (state != null && state.getPath() != null) {
obj = FACTORY.getLastVersion(project, itemProperty.getId(), state.getPath(), object.getRepositoryNode().getObjectType());
} else {
obj = FACTORY.getLastVersion(project, itemProperty.getId());
}
}
if (obj != null) {
// obj.setVersion(object.getNewVersion());
FACTORY.save(project, obj.getProperty());
builder.addOrUpdateItem(obj.getProperty().getItem(), true);
} else {
String id = itemProperty.getId();
FACTORY.save(project, itemProperty);
if (versionLatest.getSelection()) {
builder.updateItemVersion(item, object.getOldVersion(), id, versions, true);
}
builder.addOrUpdateItem(item, true);
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
monitor.worked(1);
}
try {
FACTORY.saveProject(project);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
};
rwu.setAvoidUnloadResources(true);
rwu.executeRun();
monitor.done();
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
};
// final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
use of org.talend.repository.model.ItemVersionObject in project tdi-studio-se by Talend.
the class VersionManagementPage method selectAllDependencies.
private void selectAllDependencies() {
List<ItemVersionObject> tableList = new ArrayList<ItemVersionObject>();
tableList.addAll(checkedObjects);
IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
for (ItemVersionObject object : checkedObjects) {
if (object.getRepositoryNode() != null) {
List<Relation> relations = builder.getItemsRelatedTo(object.getRepositoryNode().getId(), object.getOldVersion(), RelationshipItemBuilder.JOB_RELATION);
for (Relation relation : relations) {
IRepositoryViewObject obj = null;
try {
if (RelationshipItemBuilder.ROUTINE_RELATION.equals(relation.getType())) {
obj = RoutinesUtil.getRoutineFromName(relation.getId());
} else {
obj = factory.getLastVersion(relation.getId());
}
if (obj != null) {
for (ItemVersionObject obj2 : versionObjects) {
if (obj2.getItem() == obj.getProperty().getItem()) {
ItemVersionObject relat = obj2;
if (!tableList.contains(relat)) {
tableList.add(relat);
checkAllVerSionLatest(tableList, relat);
}
break;
}
}
}
} catch (PersistenceException et) {
ExceptionHandler.process(et);
}
}
}
}
removeItemElements(checkedObjects);
checkedObjects.clear();
checkedObjects.addAll(tableList);
refreshTableItems();
refreshCheckedTreeView();
}
use of org.talend.repository.model.ItemVersionObject in project tdi-studio-se by Talend.
the class MavenVersionManagementProjectSettingPage method addItemElements.
@Override
protected void addItemElements(List<ItemVersionObject> elements) {
if (elements == null || elements.isEmpty()) {
return;
}
itemTable.setRedraw(false);
for (final ItemVersionObject object : elements) {
final TableItem tableItem = new TableItem(itemTable, SWT.CENTER);
tableItem.setData(object);
Item item = object.getItem();
IBaseLabelProvider labelProvider = treeViewer.getLabelProvider();
Image itemsImage = null;
if (labelProvider instanceof NavigatorDecoratingLabelProvider) {
NavigatorDecoratingLabelProvider navigatorProvider = (NavigatorDecoratingLabelProvider) labelProvider;
itemsImage = navigatorProvider.getImage(object.getRepositoryNode());
} else {
ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
itemsImage = getItemsImage(CoreImageProvider.getIcon(itemType));
}
tableItem.setImage(itemsImage);
tableItem.setText(item.getProperty().getLabel());
// old version
tableItem.setText(1, MavenVersionUtils.getItemMavenVersion(item.getProperty()));
TableEditor versionEditor = null;
if (fixedVersionButton.getSelection()) {
tableItem.setText(2, appliedFixedVersion);
} else if (useJobVersionButton.getSelection()) {
String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(item.getProperty().getVersion());
tableItem.setText(2, jobDefaultVersion);
object.setNewVersion(jobDefaultVersion);
} else {
// new version
versionEditor = new TableEditor(itemTable);
Composite versionComposite = new Composite(itemTable, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.marginLeft = 0;
layout.marginRight = 1;
versionComposite.setLayout(layout);
final Text text = new Text(versionComposite, SWT.CENTER | SWT.BORDER);
GridData data = new GridData(GridData.FILL_BOTH);
text.setLayoutData(data);
String newVersion = object.getNewVersion();
if (newVersion == null || "".equals(newVersion.trim())) {
//$NON-NLS-1$
newVersion = appliedFixedVersion;
object.setNewVersion(newVersion);
}
text.setText(newVersion);
checkVersionPattern(text, newVersion);
text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String version = text.getText();
checkVersionPattern(text, version);
object.setNewVersion(version);
checkValid();
}
});
versionEditor.minimumWidth = itemTable.getColumn(2).getWidth();
versionEditor.setEditor(versionComposite, tableItem, 2);
}
TableEditor delEditor = new TableEditor(itemTable);
Label delLabel = new Label(itemTable, SWT.CENTER);
delLabel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
delLabel.setImage(ImageProvider.getImage(EImage.DELETE_ICON));
//$NON-NLS-1$
delLabel.setToolTipText(Messages.getString("VersionManagementDialog.DeletedTip"));
delLabel.pack();
delLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
checkedObjects.remove(object);
removeTableItem(tableItem);
refreshCheckedTreeView();
checkButtonsState();
checkButtonsState(false);
}
});
delEditor.minimumWidth = 25;
delEditor.horizontalAlignment = SWT.CENTER;
delEditor.setEditor(delLabel, tableItem, 3);
if (fixedVersionButton.getSelection() || useJobVersionButton.getSelection()) {
tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { delEditor });
} else if (versionEditor != null) {
tableItem.setData(ITEM_EDITOR_KEY, new TableEditor[] { versionEditor, delEditor });
}
itemTable.setRedraw(true);
}
}
use of org.talend.repository.model.ItemVersionObject in project tdi-studio-se by Talend.
the class MavenVersionManagementProjectSettingPage method updateItemsVersion.
protected void updateItemsVersion() {
List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
boolean hasJobOpenedInEditor = false;
StringBuilder builder = new StringBuilder();
for (ItemVersionObject object : checkedObjects) {
if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
hasJobOpenedInEditor = true;
JobsOpenedInEditor.add(object);
//$NON-NLS-1$
builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
} else {
closedJobs.add(object);
}
}
if (builder.length() > 0) {
builder.delete(builder.length() - 2, builder.length());
}
if (hasJobOpenedInEditor) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workBench != null) {
IWorkbenchPage page = workBench.getActivePage();
IEditorReference[] editorRefs = page.getEditorReferences();
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
if (service != null) {
for (IEditorReference editorRef : editorRefs) {
IEditorPart editor = editorRef.getEditor(false);
if (editor instanceof IMultiPageTalendEditor) {
IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
String version = null;
for (ItemVersionObject object : JobsOpenedInEditor) {
if (object.getItem().getProperty().getId().equals(process.getId())) {
version = object.getNewVersion();
break;
}
}
if (version != null) {
String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
if (version.equals(jobDefaultVersion)) {
// if default, set null to remove key from property.
version = null;
}
Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
if (process instanceof IGEFProcess) {
service.executeCommand((IGEFProcess) process, command);
}
}
}
}
}
}
}
}
final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
@Override
public void run(final IProgressMonitor monitor) throws CoreException {
RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
RepositoryWorkUnit<Object>(//$NON-NLS-1$
project, //$NON-NLS-1$
"Update items Maven version") {
@Override
protected void run() throws LoginException, PersistenceException {
//$NON-NLS-1$
monitor.beginTask("Update items Maven version", closedJobs.size());
for (ItemVersionObject object : closedJobs) {
final Item item = object.getItem();
Property itemProperty = item.getProperty();
MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
monitor.subTask(itemProperty.getLabel());
FACTORY.save(project, itemProperty);
monitor.worked(1);
}
try {
FACTORY.saveProject(project);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
};
rwu.setAvoidUnloadResources(true);
rwu.executeRun();
monitor.done();
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all notification
// of changes before the end of the modifications.
workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
};
final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
try {
dialog.run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException | InterruptedException e) {
ExceptionHandler.process(e);
}
}
Aggregations