Commit fb439c13 authored by Romain Bioteau's avatar Romain Bioteau

add compare with and replace with menu when project is connected (#1469)

* make custom script groovy files deletable and add refactor menu on all
java element
* fix default script name
* fix focus for data wizard
parent 0d8d63dd
......@@ -1270,10 +1270,7 @@
pattern="org.eclipse.ui.navigator.resources.filters.closedProject">
</contentExtension>
</excludes>
</viewerContentBinding>
</extension>
<extension
point="org.eclipse.ui.navigator.navigatorContent">
......@@ -1310,6 +1307,25 @@
class="org.bonitasoft.studio.application.views.ProjectExplorerViewerComparator"
id="org.eclipse.ui.navigator.resources.sorters.defaultSorter">
</commonSorter>
<actionProvider
class="org.eclipse.jdt.internal.ui.navigator.JavaNavigatorRefactorActionProvider"
id="org.bonitasoft.studio.navigator.actions.RefactorActions"
overrides="org.eclipse.ui.navigator.resources.actions.RefactorActions">
<enablement>
<or>
<and>
<instanceof value="org.eclipse.core.resources.IProject" />
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.jdt.core.javanature" />
</and>
<instanceof value="org.eclipse.jdt.core.IJavaElement" />
<instanceof value="org.eclipse.jdt.core.IJarEntryResource" />
<instanceof value="org.eclipse.jdt.internal.ui.packageview.PackageFragmentRootContainer" />
<adapt type="java.util.Collection">
<count value="0" />
</adapt>
</or>
</enablement>
</actionProvider>
</navigatorContent>
<commonFilter
activeByDefault="true"
......
......@@ -7,6 +7,7 @@ import static org.mockito.Mockito.when;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
......@@ -61,7 +62,7 @@ public class DeleteHandlerTest {
@Test
public void should_be_disable_if_selection_is_a_repository_store() {
IResource resource = mock(IResource.class);
IFolder resource = mock(IFolder.class);
IAdaptable selectionContent = mock(IAdaptable.class);
when(selectionContent.getAdapter(IResource.class)).thenReturn(resource);
IStructuredSelection selection = new StructuredSelection(selectionContent);
......
......@@ -28,6 +28,7 @@ import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
......@@ -92,7 +93,8 @@ public class DeleteHandler extends AbstractHandler {
IRepositoryFileStore fileStore = currentRepository.getFileStore(adapter);
if (fileStore != null && !fileStore.canBeDeleted()) {
return false;
} else if (fileStore == null && currentRepository.getRepositoryStore(adapter) != null) {
} else if (fileStore == null && currentRepository.getRepositoryStore(adapter) != null
&& adapter instanceof IFolder) {
return false;
}
}
......
......@@ -48,6 +48,7 @@ import org.eclipse.e4.ui.model.application.ui.menu.MPopupMenu;
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer;
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuListener2;
import org.eclipse.jface.action.IMenuManager;
......@@ -59,6 +60,7 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
......@@ -356,13 +358,16 @@ public class CustomPopupMenuExtender implements IMenuListener2,
StructuredSelection repositoryProject = new StructuredSelection(project);
ISelection selection = selProvider.getSelection();
if (repositoryProject.equals(selection)) {
INCLUDES.remove("compareWithMenu");
INCLUDES.remove("replaceWithMenu");
if (isLocalProject(project)) {
INCLUDES.remove("compareWithMenu");
INCLUDES.remove("replaceWithMenu");
}
INCLUDES.remove("org.eclipse.jdt.ui.source.menu");
INCLUDES.remove("org.eclipse.jdt.ui.refactoring.menu");
INCLUDES.add("org.eclipse.ui.edit.delete");
} else if (((StructuredSelection) selection).getFirstElement() instanceof IProject) {
INCLUDES.add("org.eclipse.ui.edit.delete");
INCLUDES.remove("org.eclipse.jdt.ui.refactoring.menu");
}
Object resource = ((StructuredSelection) selection).getFirstElement();
if (resource instanceof IAdaptable && ((IAdaptable) resource).getAdapter(IResource.class) != null) {
......@@ -370,10 +375,14 @@ public class CustomPopupMenuExtender implements IMenuListener2,
IProject parentProject = adapter.getProject();
StructuredSelection structuredSelection = new StructuredSelection(parentProject);
if (structuredSelection.equals(repositoryProject)) {
INCLUDES.remove("compareWithMenu");
INCLUDES.remove("replaceWithMenu");
INCLUDES.remove("org.eclipse.jdt.ui.source.menu");
INCLUDES.remove("org.eclipse.jdt.ui.refactoring.menu");
if (isLocalProject(project)) {
INCLUDES.remove("compareWithMenu");
INCLUDES.remove("replaceWithMenu");
}
if (!(resource instanceof IJavaElement)) {
INCLUDES.remove("org.eclipse.jdt.ui.source.menu");
INCLUDES.remove("org.eclipse.jdt.ui.refactoring.menu");
}
INCLUDES.add("org.eclipse.ui.edit.delete");
}
}
......@@ -418,6 +427,10 @@ public class CustomPopupMenuExtender implements IMenuListener2,
addStaticActions(mgr);
}
private boolean isLocalProject(IProject project) {
return !RepositoryProvider.isShared(project);
}
/**
* well, this goes to the renderer.
*
......
......@@ -34,7 +34,7 @@ public class CustomWizardDialog extends WizardDialog {
protected String finishLabel;
protected String closeLabel;
private boolean askWhenShellCloses = true && !FileActionDialog.getDisablePopup();
private boolean askWhenShellCloses = !FileActionDialog.getDisablePopup();
/**
* @param parentShell
......@@ -53,7 +53,8 @@ public class CustomWizardDialog extends WizardDialog {
public CustomWizardDialog(Shell parentShell, IWizard newWizard, String finishLabel,boolean isModal) {
super(parentShell, newWizard);
if(!isModal){
setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER | SWT.RESIZE | getDefaultOrientation());
setShellStyle(SWT.CLOSE | SWT.MAX | SWT.TITLE | SWT.BORDER | SWT.RESIZE
| getDefaultOrientation());
}
this.finishLabel = finishLabel;
}
......
......@@ -1088,8 +1088,20 @@ public class DataWizardPage extends WizardPage implements IBonitaVariableContext
descriptionText = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
descriptionText
.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 70).span(2, 1).create());
descriptionText.addTraverseListener(e -> {
if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
e.doit = true;
}
});
}
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
Display.getDefault().asyncExec(nameText::setFocus);
}
}
protected void createDataOptions(final Composite parent) {
new Label(parent, SWT.NONE); // FILLER
......
......@@ -21,19 +21,18 @@ import com.google.common.base.Strings;
public class DefaultExpressionNameResolver implements ExpressionNameResolver {
private static final String DEFAULT_NAME_SCRIPT = "newScript";
private final String defaultScriptName;
public DefaultExpressionNameResolver() {
this("");
this(DEFAULT_NAME_SCRIPT);
}
public DefaultExpressionNameResolver(String defaultScriptName) {
this.defaultScriptName = defaultScriptName;
}
/* (non-Javadoc)
* @see org.bonitasoft.studio.expression.editor.viewer.ExpressionNameResolver#getName(org.bonitasoft.studio.model.expression.Expression)
*/
@Override
public String getName(Expression expression) {
if (Strings.isNullOrEmpty(expression.getName())) {
......
......@@ -380,7 +380,7 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
} else {
inputExpression.setType(type);
}
inputExpression.setName(shouldClearName() ? "" : getExpressionName());
inputExpression.setName(shouldClearName() ? "" : inputExpression.getName());
if (expressionNameResolver != null) {
inputExpression.setName(expressionNameResolver.getName(inputExpression));
}
......@@ -396,15 +396,6 @@ public class EditExpressionDialog extends TrayDialog implements IBonitaVariableC
}
}
private String getExpressionName() {
String currentName = inputExpression.getName();
if ((currentName == null || currentName.isEmpty())
&& ExpressionConstants.SCRIPT_TYPE.equals(inputExpression.getType())) {
currentName = DEFAULT_NAME_SCRIPT;
}
return currentName;
}
private boolean shouldClearName() {
final String type = inputExpression.getType();
return !(ExpressionConstants.SCRIPT_TYPE.equals(type) || ExpressionConstants.QUERY_TYPE.equals(type));
......
......@@ -83,6 +83,11 @@ public class ContentAssistText extends Composite implements SWTBotConstants, ISe
textControl = new Text(this, GTKStyleHandler.replaceSingleWithWrap(style | SWT.SINGLE));
textControl.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
textControl.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
textControl.addTraverseListener(e -> {
if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
e.doit = true;
}
});
textControl.addFocusListener(new FocusListener() {
@Override
......
......@@ -111,12 +111,6 @@ public class ScriptExpressionEditor extends SelectionAwareExpressionEditor imple
}
}
/*
* (non-Javadoc)
* @see
* org.bonitasoft.studio.expression.editor.provider.IExpressionEditor#createExpressionEditor(org.eclipse.swt.widgets.
* Composite)
*/
@Override
public Control createExpressionEditor(final Composite parent, final EMFDataBindingContext ctx) {
mainComposite = new Composite(parent, SWT.NONE);
......@@ -208,9 +202,7 @@ public class ScriptExpressionEditor extends SelectionAwareExpressionEditor imple
return null;
}
/**
* @param classText
*/
@SuppressWarnings("restriction")
private void openClassSelectionDialog() {
final JavaSearchScope scope = new JavaSearchScope();
......@@ -288,9 +280,7 @@ public class ScriptExpressionEditor extends SelectionAwareExpressionEditor imple
}
private IValueChangeListener handleValidationStatusChanged() {
return event -> {
statusChanged((IStatus) bindValue.getValidationStatus().getValue());
};
return event -> statusChanged((IStatus) bindValue.getValidationStatus().getValue());
}
private void statusChanged(IStatus status) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment