diff options
21 files changed, 1994 insertions, 110 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF index a61a72832c..47b65de795 100644 --- a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF @@ -23,5 +23,6 @@ Export-Package: org.eclipse.emf.cdo.internal.ui;version="0.8.0", org.eclipse.emf.cdo.internal.ui.dialogs;version="0.8.0", org.eclipse.emf.cdo.internal.ui.editor;version="0.8.0", org.eclipse.emf.cdo.internal.ui.preferences;version="0.8.0", - org.eclipse.emf.cdo.internal.ui.views;version="0.8.0" + org.eclipse.emf.cdo.internal.ui.views;version="0.8.0", + org.eclipse.emf.cdo.ui;version="0.8.0" Eclipse-LazyStart: true diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.ui/plugin.xml index 03bb96aaf7..5928244575 100644 --- a/plugins/org.eclipse.emf.cdo.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.ui/plugin.xml @@ -69,6 +69,12 @@ id="org.eclipse.emf.cdo.ui.CDOPreferencePage" name="CDO"> </page> + <page + category="org.eclipse.emf.cdo.ui.CDOPreferencePage" + class="org.eclipse.emf.cdo.internal.ui.preferences.CDOUIPreferencePage" + id="org.eclipse.emf.cdo.ui.CDOUIPreferencePage" + name="User Interface"> + </page> </extension> </plugin> diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java index d9bc4d5e30..bb47a9819b 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/bundle/OM.java @@ -10,6 +10,8 @@ **************************************************************************/ package org.eclipse.emf.cdo.internal.ui.bundle; +import org.eclipse.emf.cdo.ui.CDOLabelProvider; + import org.eclipse.net4j.internal.util.security.ResponseNegotiator; import org.eclipse.net4j.util.internal.ui.security.InteractiveCredentialsProvider; import org.eclipse.net4j.util.om.OMBundle; @@ -37,17 +39,20 @@ public abstract class OM public static final OMPreferences PREFS = BUNDLE.preferences(); + public static final OMPreference<String> PREF_LABEL_DECORATION = // + PREFS.init("PREF_LABEL_DECORATION", CDOLabelProvider.DEFAULT_DECORATION); //$NON-NLS-1$ + public static final OMPreference<String[]> PREF_HISTORY_SELECT_PACKAGES = // - PREFS.initArray("PREF_HISTORY_SELECT_PACKAGES"); + PREFS.initArray("PREF_HISTORY_SELECT_PACKAGES"); //$NON-NLS-1$ public static final OMPreference<String[]> PREF_HISTORY_CONNECTORS = // - PREFS.initArray("PREF_HISTORY_CONNECTORS"); + PREFS.initArray("PREF_HISTORY_CONNECTORS"); //$NON-NLS-1$ public static final OMPreference<String[]> PREF_HISTORY_REPOSITORIES = // - PREFS.initArray("PREF_HISTORY_REPOSITORIES"); + PREFS.initArray("PREF_HISTORY_REPOSITORIES"); //$NON-NLS-1$ public static final OMPreference<Boolean> PREF_LEGACY_SUPPORT = // - PREFS.init("PREF_LEGACY_SUPPORT", true); + PREFS.init("PREF_LEGACY_SUPPORT", true); //$NON-NLS-1$ static void start() { diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java index d60d063e4a..71ff5a9715 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/dialogs/PackageManagerDialog.java @@ -15,8 +15,8 @@ import org.eclipse.emf.cdo.internal.ui.SharedIcons; import org.eclipse.emf.cdo.internal.ui.actions.RegisterFilesystemPackagesAction; import org.eclipse.emf.cdo.internal.ui.actions.RegisterGeneratedPackagesAction; import org.eclipse.emf.cdo.internal.ui.actions.RegisterWorkspacePackagesAction; -import org.eclipse.emf.cdo.internal.ui.views.CDOItemProvider; import org.eclipse.emf.cdo.protocol.model.CDOPackage; +import org.eclipse.emf.cdo.ui.CDOItemProvider; import org.eclipse.emf.cdo.util.CDOPackageType; import org.eclipse.emf.cdo.util.CDOUtil; diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java index 7f44656c91..5fbb9521fd 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java @@ -13,9 +13,10 @@ import org.eclipse.emf.cdo.eresource.CDOResource; import org.eclipse.emf.cdo.internal.ui.SharedIcons; import org.eclipse.emf.cdo.internal.ui.bundle.OM; import org.eclipse.emf.cdo.internal.ui.dialogs.RollbackTransactionDialog; -import org.eclipse.emf.cdo.internal.ui.views.CDOEventHandler; import org.eclipse.emf.cdo.protocol.model.CDOClass; import org.eclipse.emf.cdo.protocol.model.CDOPackage; +import org.eclipse.emf.cdo.ui.CDOEventHandler; +import org.eclipse.emf.cdo.ui.CDOLabelProvider; import org.eclipse.emf.cdo.util.CDOUtil; import org.eclipse.emf.common.command.BasicCommandStack; diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java index c9fa61be86..c519da94a6 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOPreferencePage.java @@ -13,16 +13,11 @@ package org.eclipse.emf.cdo.internal.ui.preferences; import org.eclipse.emf.cdo.CDOView; import org.eclipse.emf.cdo.protocol.revision.CDORevision; -import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.net4j.util.ui.UIUtil; import org.eclipse.net4j.util.ui.prefs.OMPreferencePage; +import org.eclipse.net4j.util.ui.widgets.TextAndDisable; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; @@ -116,10 +111,10 @@ public class CDOPreferencePage extends OMPreferencePage org.eclipse.emf.internal.cdo.bundle.OM.PREF_USER_NAME.setValue(userName.getText()); org.eclipse.emf.internal.cdo.bundle.OM.PREF_CONNECTOR_DESCRIPTION.setValue(connectorDescription.getText()); - int v1 = Integer.parseInt(referenceChunkSize.getText().getText()); + int v1 = Integer.parseInt(referenceChunkSize.getValue()); org.eclipse.emf.internal.cdo.bundle.OM.PREF_REFERENCE_CHUNK_SIZE.setValue(v1); - int v2 = Integer.parseInt(preloadChunkSize.getText().getText()); + int v2 = Integer.parseInt(preloadChunkSize.getValue()); org.eclipse.emf.internal.cdo.bundle.OM.PREF_LOAD_REVISION_COLLECTION_CHUNK_SIZE.setValue(v2); boolean v3 = invalidationNotifications.getSelection(); @@ -127,85 +122,4 @@ public class CDOPreferencePage extends OMPreferencePage return super.performOk(); } - - private static final class TextAndDisable extends Composite implements SelectionListener, ModifyListener - { - private Text text; - - private Button disabled; - - private String disabledValue; - - public TextAndDisable(Composite parent, int textStyle, String disabledValue) - { - super(parent, SWT.NONE); - this.disabledValue = disabledValue; - - GridLayout grid = new GridLayout(2, false); - grid.marginHeight = 0; - grid.marginWidth = 0; - setLayout(grid); - - GridData gd = new GridData(); - gd.widthHint = 32; - - text = new Text(this, textStyle); - text.addModifyListener(this); - text.setLayoutData(gd); - - disabled = new Button(this, SWT.CHECK); - disabled.setText("Disabled"); - disabled.addSelectionListener(this); - disabled.setLayoutData(UIUtil.createGridData(false, false)); - } - - public Text getText() - { - return text; - } - - public Button getButton() - { - return disabled; - } - - public boolean isDisabled() - { - return disabled.getSelection(); - } - - public void setDisabled(boolean disabled) - { - this.disabled.setSelection(disabled); - widgetSelected(null); - } - - public void setValue(String value) - { - text.setText(value); - setDisabled(ObjectUtil.equals(value, disabledValue)); - } - - public void widgetDefaultSelected(SelectionEvent e) - { - widgetSelected(e); - } - - public void widgetSelected(SelectionEvent e) - { - if (isDisabled()) - { - text.setText(disabledValue); - text.setEnabled(false); - } - else - { - text.setEnabled(true); - } - } - - public void modifyText(ModifyEvent e) - { - } - } }
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOUIPreferencePage.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOUIPreferencePage.java new file mode 100644 index 0000000000..7561b337b0 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/preferences/CDOUIPreferencePage.java @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.emf.cdo.internal.ui.preferences; + +import org.eclipse.emf.cdo.internal.ui.bundle.OM; +import org.eclipse.emf.cdo.ui.CDOLabelProvider; + +import org.eclipse.net4j.util.ui.UIUtil; +import org.eclipse.net4j.util.ui.prefs.OMPreferencePage; +import org.eclipse.net4j.util.ui.widgets.TextAndDisable; + +import org.eclipse.jface.fieldassist.IContentProposalProvider; +import org.eclipse.jface.fieldassist.IControlContentAdapter; +import org.eclipse.jface.fieldassist.SimpleContentProposalProvider; +import org.eclipse.jface.fieldassist.TextContentAdapter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; + +/** + * @author Eike Stepper + */ +public class CDOUIPreferencePage extends OMPreferencePage +{ + private TextAndDisable decoration; + + public CDOUIPreferencePage() + { + super(OM.PREFS); + } + + @Override + protected Control createUI(Composite parent) + { + Composite composite = UIUtil.createGridComposite(parent, 2); + composite.setLayoutData(UIUtil.createGridData()); + + new Label(composite, SWT.NONE).setText("Label decoration:"); + decoration = new TextAndDisable(composite, SWT.BORDER, CDOLabelProvider.NO_DECORATION) + { + @Override + protected GridData createTextLayoutData() + { + return UIUtil.createGridData(true, false); + } + }; + decoration.setLayoutData(UIUtil.createGridData(true, false)); + + Text text = decoration.getText(); + IControlContentAdapter contentAdapter = new TextContentAdapter(); + IContentProposalProvider provider = new SimpleContentProposalProvider(CDOLabelProvider.DECORATION_PROPOSALS); + new ContentAssistCommandAdapter(text, contentAdapter, provider, null, new char[] { '$' }, true); + UIUtil.addDecorationMargin(text); + + initValues(); + return composite; + } + + protected void initValues() + { + decoration.setValue(OM.PREF_LABEL_DECORATION.getValue()); + } + + @Override + public boolean performOk() + { + OM.PREF_LABEL_DECORATION.setValue(decoration.getValue()); + return super.performOk(); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java index 1a3eae816c..948b87a0ba 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java @@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.CDOSession; import org.eclipse.emf.cdo.CDOView; import org.eclipse.emf.cdo.internal.ui.actions.OpenSessionAction; import org.eclipse.emf.cdo.internal.ui.editor.CDOEditor; +import org.eclipse.emf.cdo.ui.CDOItemProvider; import org.eclipse.net4j.util.container.IContainer; import org.eclipse.net4j.util.container.IManagedContainer; diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java index e78fde0651..e804d40ae0 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistory.java @@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.internal.ui.views; import org.eclipse.emf.cdo.CDOView; import org.eclipse.emf.cdo.CDOViewResourcesEvent; import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.ui.CDOViewHistoryEvent; import org.eclipse.net4j.internal.util.event.Event; import org.eclipse.net4j.internal.util.event.Notifier; diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOEventHandler.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEventHandler.java index 56ed02f7d3..4bcee8e55e 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOEventHandler.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEventHandler.java @@ -8,7 +8,7 @@ * Contributors: * Eike Stepper - initial API and implementation **************************************************************************/ -package org.eclipse.emf.cdo.internal.ui.views; +package org.eclipse.emf.cdo.ui; import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.CDOSessionInvalidationEvent; diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java new file mode 100644 index 0000000000..588cc49bd3 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java @@ -0,0 +1,393 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.emf.cdo.ui; + +import org.eclipse.emf.cdo.CDOAudit; +import org.eclipse.emf.cdo.CDOSession; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.CDOTransactionFinishedEvent; +import org.eclipse.emf.cdo.CDOTransactionStartedEvent; +import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.CDOViewEvent; +import org.eclipse.emf.cdo.internal.ui.SharedIcons; +import org.eclipse.emf.cdo.internal.ui.actions.CloseSessionAction; +import org.eclipse.emf.cdo.internal.ui.actions.CloseViewAction; +import org.eclipse.emf.cdo.internal.ui.actions.CommitTransactionAction; +import org.eclipse.emf.cdo.internal.ui.actions.CreateResourceAction; +import org.eclipse.emf.cdo.internal.ui.actions.LoadResourceAction; +import org.eclipse.emf.cdo.internal.ui.actions.ManagePackagesAction; +import org.eclipse.emf.cdo.internal.ui.actions.OpenAuditAction; +import org.eclipse.emf.cdo.internal.ui.actions.OpenTransactionAction; +import org.eclipse.emf.cdo.internal.ui.actions.OpenViewAction; +import org.eclipse.emf.cdo.internal.ui.actions.OpenViewEditorAction; +import org.eclipse.emf.cdo.internal.ui.actions.RegisterFilesystemPackagesAction; +import org.eclipse.emf.cdo.internal.ui.actions.RegisterSinglePackageAction; +import org.eclipse.emf.cdo.internal.ui.actions.RegisterWorkspacePackagesAction; +import org.eclipse.emf.cdo.internal.ui.actions.ReloadViewAction; +import org.eclipse.emf.cdo.internal.ui.actions.RollbackTransactionAction; +import org.eclipse.emf.cdo.internal.ui.views.CDOViewHistory; +import org.eclipse.emf.cdo.internal.ui.views.CDOViewHistory.Entry; +import org.eclipse.emf.cdo.util.CDOPackageType; +import org.eclipse.emf.cdo.util.CDOUtil; + +import org.eclipse.net4j.IConnector; +import org.eclipse.net4j.util.container.IContainer; +import org.eclipse.net4j.util.event.IEvent; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.ui.actions.SafeAction; +import org.eclipse.net4j.util.ui.views.ContainerItemProvider; +import org.eclipse.net4j.util.ui.views.IElementFilter; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.IWorkbenchPage; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @author Eike Stepper + */ +public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> +{ + private IWorkbenchPage page; + + private Map<CDOView, CDOViewHistory> viewHistories = new HashMap<CDOView, CDOViewHistory>(); + + private IListener viewListener = new IListener() + { + public void notifyEvent(IEvent event) + { + if (event instanceof CDOTransactionStartedEvent || event instanceof CDOTransactionFinishedEvent) + { + try + { + final CDOView view = ((CDOViewEvent)event).getView(); + getViewer().getControl().getDisplay().syncExec(new Runnable() + { + public void run() + { + try + { + fireLabelProviderChanged(view); + CDOViewHistory history = viewHistories.get(view); + if (history != null) + { + Entry[] entries = history.getEntries(); + if (entries != null && entries.length != 0) + { + fireLabelProviderChanged(entries); + } + } + } + catch (Exception ignore) + { + } + } + }); + } + catch (Exception ignore) + { + } + } + } + }; + + private IListener historyListener = new IListener() + { + public void notifyEvent(IEvent event) + { + if (event instanceof CDOViewHistoryEvent) + { + CDOViewHistoryEvent e = (CDOViewHistoryEvent)event; + CDOView view = e.getViewHistory().getView(); + refreshElement(view, false); + + Entry addedEntry = e.getAddedEntry(); + if (addedEntry != null) + { + revealElement(addedEntry); + } + } + } + }; + + public CDOItemProvider(IWorkbenchPage page, IElementFilter rootElementFilter) + { + super(rootElementFilter); + this.page = page; + } + + public CDOItemProvider(IWorkbenchPage page) + { + this(page, null); + } + + @Override + public Object[] getChildren(Object element) + { + if (element instanceof CDOView) + { + CDOView view = (CDOView)element; + CDOViewHistory history = viewHistories.get(view); + if (history != null) + { + return history.getEntries(); + } + + return NO_ELEMENTS; + } + + return super.getChildren(element); + } + + @Override + public boolean hasChildren(Object element) + { + if (element instanceof CDOView) + { + CDOView view = (CDOView)element; + CDOViewHistory history = viewHistories.get(view); + if (history != null) + { + return history.hasEntries(); + } + + return false; + } + + return super.hasChildren(element); + } + + @Override + public Object getParent(Object element) + { + if (element instanceof CDOViewHistory.Entry) + { + return ((CDOViewHistory.Entry)element).getView(); + } + + return super.getParent(element); + } + + @Override + public String getText(Object obj) + { + if (obj instanceof CDOSession) + { + return getSessionLabel((CDOSession)obj); + } + + if (obj instanceof CDOView) + { + return getViewLabel((CDOView)obj); + } + + if (obj instanceof CDOViewHistory.Entry) + { + return getHistroyEntryLabel((CDOViewHistory.Entry)obj); + } + + return super.getText(obj); + } + + @Override + public Image getImage(Object obj) + { + if (obj instanceof CDOSession) + { + return SharedIcons.getImage(SharedIcons.OBJ_SESSION); + } + + if (obj instanceof CDOView) + { + CDOView view = (CDOView)obj; + switch (view.getViewType()) + { + case TRANSACTION: + return SharedIcons.getImage(SharedIcons.OBJ_EDITOR); + case READONLY: + return SharedIcons.getImage(SharedIcons.OBJ_EDITOR_READONLY); + case AUDIT: + return SharedIcons.getImage(SharedIcons.OBJ_EDITOR_HISTORICAL); + } + } + + return super.getImage(obj); + } + + public static String getSessionLabel(CDOSession session) + { + IConnector connector = session.getChannel().getConnector(); + String repositoryName = session.getRepositoryName(); + return "Session " + connector.getURL() + "/" + repositoryName + " [" + session.getSessionID() + "]"; + } + + public static String getViewLabel(CDOView view) + { + if (view instanceof CDOTransaction) + { + CDOTransaction transaction = (CDOTransaction)view; + return MessageFormat.format("{0}Transaction [{1}]", transaction.isDirty() ? "*" : "", transaction.getViewID()); + } + + if (view instanceof CDOAudit) + { + CDOAudit audit = (CDOAudit)view; + return MessageFormat.format("Audit [{0,date} {0,time}]", audit.getTimeStamp()); + } + + return MessageFormat.format("View [{0}]", view.getViewID()); + } + + public static String getHistroyEntryLabel(CDOViewHistory.Entry entry) + { + return (entry.getView().isDirty() ? "*" : "") + entry.getResourcePath(); + } + + @Override + protected void fillContextMenu(IMenuManager manager, ITreeSelection selection) + { + super.fillContextMenu(manager, selection); + if (selection.size() == 1) + { + Object object = selection.getFirstElement(); + if (object instanceof CDOSession) + { + fillSession(manager, (CDOSession)object); + } + else if (object instanceof CDOView) + { + fillView(manager, (CDOView)object); + } + else if (object instanceof CDOViewHistory.Entry) + { + fillHistoryEntry(manager, (CDOViewHistory.Entry)object); + } + } + } + + protected void fillSession(IMenuManager manager, CDOSession session) + { + manager.add(new OpenTransactionAction(page, session)); + manager.add(new OpenViewAction(page, session)); + manager.add(new OpenAuditAction(page, session)); + manager.add(new Separator()); + manager.add(new ManagePackagesAction(page, session)); + + MenuManager generatedManager = new MenuManager("Register Generated Package"); + if (fillGenerated(generatedManager, session)) + { + manager.add(generatedManager); + } + + IAction a1 = new RegisterWorkspacePackagesAction(page, session); + a1.setText(a1.getText() + SafeAction.INTERACTIVE); + manager.add(a1); + + RegisterFilesystemPackagesAction a2 = new RegisterFilesystemPackagesAction(page, session); + a2.setText(a2.getText() + SafeAction.INTERACTIVE); + manager.add(a2); + + manager.add(new Separator()); + manager.add(new CloseSessionAction(page, session)); + } + + protected boolean fillGenerated(MenuManager manager, CDOSession session) + { + Set<Map.Entry<String, CDOPackageType>> entrySet = CDOUtil.getPackageTypes().entrySet(); + List<Map.Entry<String, CDOPackageType>> entryList = new ArrayList<Map.Entry<String, CDOPackageType>>(entrySet); + Collections.sort(entryList, new Comparator<Map.Entry<String, CDOPackageType>>() + { + public int compare(Map.Entry<String, CDOPackageType> e1, Map.Entry<String, CDOPackageType> e2) + { + return e1.getKey().compareTo(e2.getKey()); + } + }); + + Set<String> registeredURIs = new HashSet<String>(session.getPackageRegistry().keySet()); + boolean added = false; + for (Map.Entry<String, CDOPackageType> entry : entryList) + { + String packageURI = entry.getKey(); + if (!registeredURIs.contains(packageURI)) + { + manager.add(new RegisterSinglePackageAction(page, session, packageURI, entry.getValue())); + added = true; + } + } + + return added; + } + + protected void fillView(IMenuManager manager, CDOView view) + { + manager.add(new OpenViewEditorAction(page, view)); + manager.add(new LoadResourceAction(page, view)); + manager.add(new Separator()); + if (view.getViewType() == CDOView.Type.TRANSACTION) + { + manager.add(new CreateResourceAction(page, view)); + manager.add(new CommitTransactionAction(page, view)); + manager.add(new RollbackTransactionAction(page, view)); + } + + manager.add(new Separator()); + manager.add(new ReloadViewAction(page, view)); + manager.add(new Separator()); + manager.add(new CloseViewAction(page, view)); + } + + protected void fillHistoryEntry(IMenuManager manager, Entry entry) + { + } + + @Override + protected void elementAdded(Object element, Object parent) + { + super.elementAdded(element, parent); + if (element instanceof CDOView) + { + CDOView view = (CDOView)element; + view.addListener(viewListener); + + CDOViewHistory history = new CDOViewHistory(view); + history.addListener(historyListener); + viewHistories.put(view, history); + } + } + + @Override + protected void elementRemoved(Object element, Object parent) + { + super.elementRemoved(element, parent); + if (element instanceof CDOView) + { + CDOView view = (CDOView)element; + view.removeListener(viewListener); + + CDOViewHistory history = viewHistories.remove(view); + history.removeListener(historyListener); + history.dispose(); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOLabelProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java index 59e0d78100..09049cf637 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOLabelProvider.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOLabelProvider.java @@ -1,6 +1,8 @@ -package org.eclipse.emf.cdo.internal.ui.editor; +package org.eclipse.emf.cdo.ui; import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.internal.ui.bundle.OM; +import org.eclipse.emf.cdo.protocol.revision.CDORevision; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; @@ -8,6 +10,8 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; import org.eclipse.emf.internal.cdo.InternalCDOObject; import org.eclipse.emf.internal.cdo.util.FSMUtil; +import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.ui.UIUtil; import org.eclipse.jface.viewers.IColorProvider; @@ -17,11 +21,21 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; +import java.text.MessageFormat; + /** * @author Eike Stepper */ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements IColorProvider, IFontProvider { + public static final String[] DECORATION_PROPOSALS = { "${element}", "${id}", "${state}", "${created}", "${revised}" }; + + public static final String DEFAULT_DECORATION = DECORATION_PROPOSALS[0] + " [" + DECORATION_PROPOSALS[1] + "]"; + + public static final String NO_DECORATION = DECORATION_PROPOSALS[0]; + + private static final String[] DECORATION_ARGS = { "{0}", "{1}", "{2}", "{3,date} {3,time}", "{4,date} {4,time}" }; + private static final Color GRAY = UIUtil.getDisplay().getSystemColor(SWT.COLOR_GRAY); private static final Color RED = UIUtil.getDisplay().getSystemColor(SWT.COLOR_RED); @@ -32,12 +46,24 @@ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements ICo private TreeViewer viewer; + private String pattern; + public CDOLabelProvider(AdapterFactory adapterFactory, CDOView view, TreeViewer viewer) { super(adapterFactory); this.view = view; this.viewer = viewer; bold = UIUtil.getBoldFont(viewer.getControl()); + + pattern = OM.PREF_LABEL_DECORATION.getValue(); + if (ObjectUtil.equals(pattern, NO_DECORATION)) + { + pattern = null; + } + else + { + pattern = StringUtil.replace(pattern, DECORATION_PROPOSALS, DECORATION_ARGS); + } } public CDOView getView() @@ -84,17 +110,15 @@ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements ICo } @Override + public String getText(Object object) + { + return decorateText(super.getText(object), object); + } + + @Override public String getColumnText(Object object, int columnIndex) { - try - { - InternalCDOObject cdoObject = FSMUtil.adapt(object, view); - return super.getColumnText(object, columnIndex) + " [" + cdoObject.cdoID() + "]"; - } - catch (RuntimeException ex) - { - return super.getColumnText(object, columnIndex); - } + return decorateText(super.getColumnText(object, columnIndex), object); } public Color getBackground(Object object) @@ -142,4 +166,24 @@ public class CDOLabelProvider extends AdapterFactoryLabelProvider implements ICo return null; } + + protected String decorateText(String text, Object object) + { + try + { + if (pattern != null) + { + InternalCDOObject obj = FSMUtil.adapt(object, view); + CDORevision rev = obj.cdoRevision(); + long created = rev == null ? CDORevision.UNSPECIFIED_DATE : rev.getCreated(); + long revised = rev == null ? CDORevision.UNSPECIFIED_DATE : rev.getRevised(); + text = MessageFormat.format(pattern, text, obj.cdoID(), obj.cdoState(), created, revised); + } + } + catch (RuntimeException ignore) + { + } + + return text; + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistoryEvent.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOViewHistoryEvent.java index b2a35f4f52..a366096808 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOViewHistoryEvent.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOViewHistoryEvent.java @@ -8,8 +8,9 @@ * Contributors: * Eike Stepper - initial API and implementation **************************************************************************/ -package org.eclipse.emf.cdo.internal.ui.views; +package org.eclipse.emf.cdo.ui; +import org.eclipse.emf.cdo.internal.ui.views.CDOViewHistory; import org.eclipse.emf.cdo.internal.ui.views.CDOViewHistory.Entry; import org.eclipse.net4j.util.event.IEvent; @@ -19,9 +20,7 @@ import org.eclipse.net4j.util.event.IEvent; */ public interface CDOViewHistoryEvent extends IEvent { - public CDOViewHistory getViewHistory(); public Entry getAddedEntry(); - } diff --git a/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF index b4625f0609..353a819137 100644 --- a/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Export-Package: org.eclipse.net4j.util.internal.ui;version="0.8.0", org.eclipse.net4j.util.ui;version="0.8.0", org.eclipse.net4j.util.ui.actions;version="0.8.0", org.eclipse.net4j.util.ui.prefs;version="0.8.0", + org.eclipse.net4j.util.ui.proposals;version="0.8.0", org.eclipse.net4j.util.ui.views;version="0.8.0", org.eclipse.net4j.util.ui.widgets;version="0.8.0" Eclipse-LazyStart: true diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java index 6351b9dcb9..f7b6728652 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java @@ -13,6 +13,8 @@ package org.eclipse.net4j.util.ui; import org.eclipse.net4j.util.internal.ui.security.InteractiveCredentialsProvider; import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; +import org.eclipse.jface.fieldassist.FieldDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; @@ -131,4 +133,16 @@ public final class UIUtil { return new GridData(SWT.FILL, SWT.FILL, grabHorizontal, grabVertical); } + + public static void addDecorationMargin(Control control) + { + Object data = control.getLayoutData(); + if (data instanceof GridData) + { + GridData gd = (GridData)data; + FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault(); + FieldDecoration dec = registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); + gd.horizontalIndent = dec.getImage().getBounds().width; + } + } } diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/README.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/README.java new file mode 100644 index 0000000000..55840f3371 --- /dev/null +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/README.java @@ -0,0 +1,23 @@ +/*************************************************************************** + * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.net4j.util.ui.proposals; + +/** + * The classes in this package are copied from org.eclipse.ui.texteditor because the class + * org.eclipse.ui.texteditor.RegExContentProposalProvider is not public. + * <p> + * TODO We should ask platform guys to open this API. + * + * @author Eike Stepper + */ +class README +{ +} diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExContentProposalProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExContentProposalProvider.java new file mode 100644 index 0000000000..b8d76d485a --- /dev/null +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExContentProposalProvider.java @@ -0,0 +1,427 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.net4j.util.ui.proposals; + +import org.eclipse.jface.fieldassist.IContentProposal; +import org.eclipse.jface.fieldassist.IContentProposalProvider; + +import java.util.ArrayList; + +/** + * Content assist proposal provider for regular expressions. + * <p> + * Note: Replaces <code>RegExContentAssistProcessor</code> which was introduced in 3.0. + * </p> + * Copied from org.eclipse.ui.texteditor.RegExContentProposalProvider. + * <p> + * Needed by org.eclipse.mylyn.internal.team.ui.preferences.workaround.MylynTeamPreferencePage. + * <p> + * TODO Ask platform guys to open this API + * + * @since 3.2 + */ +public class RegExContentProposalProvider implements IContentProposalProvider +{ + /** + * Proposal computer. + */ + private static class ProposalComputer + { + private static class Proposal implements IContentProposal + { + private String fContent; + + private String fLabel; + + private String fDescription; + + private int fCursorPosition; + + Proposal(String content, String label, String description, int cursorPosition) + { + fContent = content; + fLabel = label; + fDescription = description; + fCursorPosition = cursorPosition; + } + + public String getContent() + { + return fContent; + } + + public String getLabel() + { + return fLabel; + } + + public String getDescription() + { + return fDescription; + } + + public int getCursorPosition() + { + return fCursorPosition; + } + } + + /** + * The whole regular expression. + */ + private final String fExpression; + + /** + * The document offset. + */ + private final int fDocumentOffset; + + /** + * The high-priority proposals. + */ + private final ArrayList<Proposal> fPriorityProposals; + + /** + * The low-priority proposals. + */ + private final ArrayList<Proposal> fProposals; + + /** + * <code>true</code> iff <code>fExpression</code> ends with an open escape. + */ + private final boolean fIsEscape; + + /** + * Creates a new Proposal Computer. + * + * @param contents + * the contents of the subject control + * @param position + * the cursor position + */ + public ProposalComputer(String contents, int position) + { + fExpression = contents; + fDocumentOffset = position; + fPriorityProposals = new ArrayList<Proposal>(); + fProposals = new ArrayList<Proposal>(); + + boolean isEscape = false; + esc: for (int i = position - 1; i >= 0; i--) + { + if (fExpression.charAt(i) == '\\') + isEscape = !isEscape; + else + break esc; + } + + fIsEscape = isEscape; + } + + /** + * Computes applicable proposals for the find field. + * + * @return the proposals + */ + public IContentProposal[] computeFindProposals() + { + // characters + addBsProposal("\\\\", RegExMessages.displayString_bs_bs, RegExMessages.additionalInfo_bs_bs); //$NON-NLS-1$ + addBracketProposal("\\0", 2, RegExMessages.displayString_bs_0, RegExMessages.additionalInfo_bs_0); //$NON-NLS-1$ + addBracketProposal("\\x", 2, RegExMessages.displayString_bs_x, RegExMessages.additionalInfo_bs_x); //$NON-NLS-1$ + addBracketProposal("\\u", 2, RegExMessages.displayString_bs_u, RegExMessages.additionalInfo_bs_u); //$NON-NLS-1$ + addBsProposal("\\t", RegExMessages.displayString_bs_t, RegExMessages.additionalInfo_bs_t); //$NON-NLS-1$ + addBsProposal("\\n", RegExMessages.displayString_bs_n, RegExMessages.additionalInfo_bs_n); //$NON-NLS-1$ + addBsProposal("\\r", RegExMessages.displayString_bs_r, RegExMessages.additionalInfo_bs_r); //$NON-NLS-1$ + addBsProposal("\\f", RegExMessages.displayString_bs_f, RegExMessages.additionalInfo_bs_f); //$NON-NLS-1$ + addBsProposal("\\a", RegExMessages.displayString_bs_a, RegExMessages.additionalInfo_bs_a); //$NON-NLS-1$ + addBsProposal("\\e", RegExMessages.displayString_bs_e, RegExMessages.additionalInfo_bs_e); //$NON-NLS-1$ + addBsProposal("\\c", RegExMessages.displayString_bs_c, RegExMessages.additionalInfo_bs_c); //$NON-NLS-1$ + + if (!fIsEscape) addBracketProposal(".", 1, RegExMessages.displayString_dot, RegExMessages.additionalInfo_dot); //$NON-NLS-1$ + addBsProposal("\\d", RegExMessages.displayString_bs_d, RegExMessages.additionalInfo_bs_d); //$NON-NLS-1$ + addBsProposal("\\D", RegExMessages.displayString_bs_D, RegExMessages.additionalInfo_bs_D); //$NON-NLS-1$ + addBsProposal("\\s", RegExMessages.displayString_bs_s, RegExMessages.additionalInfo_bs_s); //$NON-NLS-1$ + addBsProposal("\\S", RegExMessages.displayString_bs_S, RegExMessages.additionalInfo_bs_S); //$NON-NLS-1$ + addBsProposal("\\w", RegExMessages.displayString_bs_w, RegExMessages.additionalInfo_bs_w); //$NON-NLS-1$ + addBsProposal("\\W", RegExMessages.displayString_bs_W, RegExMessages.additionalInfo_bs_W); //$NON-NLS-1$ + + // back reference + addBsProposal("\\", RegExMessages.displayString_bs_i, RegExMessages.additionalInfo_bs_i); //$NON-NLS-1$ + + // quoting + addBsProposal("\\", RegExMessages.displayString_bs, RegExMessages.additionalInfo_bs); //$NON-NLS-1$ + addBsProposal("\\Q", RegExMessages.displayString_bs_Q, RegExMessages.additionalInfo_bs_Q); //$NON-NLS-1$ + addBsProposal("\\E", RegExMessages.displayString_bs_E, RegExMessages.additionalInfo_bs_E); //$NON-NLS-1$ + + // character sets + if (!fIsEscape) + { + addBracketProposal("[]", 1, RegExMessages.displayString_set, RegExMessages.additionalInfo_set); //$NON-NLS-1$ + addBracketProposal("[^]", 2, RegExMessages.displayString_setExcl, RegExMessages.additionalInfo_setExcl); //$NON-NLS-1$ + addBracketProposal("[-]", 1, RegExMessages.displayString_setRange, RegExMessages.additionalInfo_setRange); //$NON-NLS-1$ + addProposal("&&", RegExMessages.displayString_setInter, RegExMessages.additionalInfo_setInter); //$NON-NLS-1$ + } + if (!fIsEscape && fDocumentOffset > 0 && fExpression.charAt(fDocumentOffset - 1) == '\\') + { + addProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$ + addProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$ + } + else + { + addBracketProposal("\\p{}", 3, RegExMessages.displayString_posix, RegExMessages.additionalInfo_posix); //$NON-NLS-1$ + addBracketProposal("\\P{}", 3, RegExMessages.displayString_posixNot, RegExMessages.additionalInfo_posixNot); //$NON-NLS-1$ + } + + // boundary matchers + if (fDocumentOffset == 0) + { + addPriorityProposal("^", RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$ + } + else if (fDocumentOffset == 1 && fExpression.charAt(0) == '^') + { + addBracketProposal("^", 1, RegExMessages.displayString_start, RegExMessages.additionalInfo_start); //$NON-NLS-1$ + } + if (fDocumentOffset == fExpression.length()) + { + addProposal("$", RegExMessages.displayString_end, RegExMessages.additionalInfo_end); //$NON-NLS-1$ + } + addBsProposal("\\b", RegExMessages.displayString_bs_b, RegExMessages.additionalInfo_bs_b); //$NON-NLS-1$ + addBsProposal("\\B", RegExMessages.displayString_bs_B, RegExMessages.additionalInfo_bs_B); //$NON-NLS-1$ + addBsProposal("\\A", RegExMessages.displayString_bs_A, RegExMessages.additionalInfo_bs_A); //$NON-NLS-1$ + addBsProposal("\\G", RegExMessages.displayString_bs_G, RegExMessages.additionalInfo_bs_G); //$NON-NLS-1$ + addBsProposal("\\Z", RegExMessages.displayString_bs_Z, RegExMessages.additionalInfo_bs_Z); //$NON-NLS-1$ + addBsProposal("\\z", RegExMessages.displayString_bs_z, RegExMessages.additionalInfo_bs_z); //$NON-NLS-1$ + + if (!fIsEscape) + { + // capturing groups + addBracketProposal("()", 1, RegExMessages.displayString_group, RegExMessages.additionalInfo_group); //$NON-NLS-1$ + + // flags + addBracketProposal("(?)", 2, RegExMessages.displayString_flag, RegExMessages.additionalInfo_flag); //$NON-NLS-1$ + addBracketProposal("(?:)", 3, RegExMessages.displayString_flagExpr, RegExMessages.additionalInfo_flagExpr); //$NON-NLS-1$ + + // non-capturing group + addBracketProposal("(?:)", 3, RegExMessages.displayString_nonCap, RegExMessages.additionalInfo_nonCap); //$NON-NLS-1$ + addBracketProposal("(?>)", 3, RegExMessages.displayString_atomicCap, RegExMessages.additionalInfo_atomicCap); //$NON-NLS-1$ + + // lookaraound + addBracketProposal( + "(?=)", 3, RegExMessages.displayString_posLookahead, RegExMessages.additionalInfo_posLookahead); //$NON-NLS-1$ + addBracketProposal( + "(?!)", 3, RegExMessages.displayString_negLookahead, RegExMessages.additionalInfo_negLookahead); //$NON-NLS-1$ + addBracketProposal( + "(?<=)", 4, RegExMessages.displayString_posLookbehind, RegExMessages.additionalInfo_posLookbehind); //$NON-NLS-1$ + addBracketProposal( + "(?<!)", 4, RegExMessages.displayString_negLookbehind, RegExMessages.additionalInfo_negLookbehind); //$NON-NLS-1$ + + // greedy quantifiers + addBracketProposal("?", 1, RegExMessages.displayString_quest, RegExMessages.additionalInfo_quest); //$NON-NLS-1$ + addBracketProposal("*", 1, RegExMessages.displayString_star, RegExMessages.additionalInfo_star); //$NON-NLS-1$ + addBracketProposal("+", 1, RegExMessages.displayString_plus, RegExMessages.additionalInfo_plus); //$NON-NLS-1$ + addBracketProposal("{}", 1, RegExMessages.displayString_exact, RegExMessages.additionalInfo_exact); //$NON-NLS-1$ + addBracketProposal("{,}", 1, RegExMessages.displayString_least, RegExMessages.additionalInfo_least); //$NON-NLS-1$ + addBracketProposal("{,}", 1, RegExMessages.displayString_count, RegExMessages.additionalInfo_count); //$NON-NLS-1$ + + // lazy quantifiers + addBracketProposal("??", 1, RegExMessages.displayString_questLazy, RegExMessages.additionalInfo_questLazy); //$NON-NLS-1$ + addBracketProposal("*?", 1, RegExMessages.displayString_starLazy, RegExMessages.additionalInfo_starLazy); //$NON-NLS-1$ + addBracketProposal("+?", 1, RegExMessages.displayString_plusLazy, RegExMessages.additionalInfo_plusLazy); //$NON-NLS-1$ + addBracketProposal("{}?", 1, RegExMessages.displayString_exactLazy, RegExMessages.additionalInfo_exactLazy); //$NON-NLS-1$ + addBracketProposal("{,}?", 1, RegExMessages.displayString_leastLazy, RegExMessages.additionalInfo_leastLazy); //$NON-NLS-1$ + addBracketProposal("{,}?", 1, RegExMessages.displayString_countLazy, RegExMessages.additionalInfo_countLazy); //$NON-NLS-1$ + + // possessive quantifiers + addBracketProposal("?+", 1, RegExMessages.displayString_questPoss, RegExMessages.additionalInfo_questPoss); //$NON-NLS-1$ + addBracketProposal("*+", 1, RegExMessages.displayString_starPoss, RegExMessages.additionalInfo_starPoss); //$NON-NLS-1$ + addBracketProposal("++", 1, RegExMessages.displayString_plusPoss, RegExMessages.additionalInfo_plusPoss); //$NON-NLS-1$ + addBracketProposal("{}+", 1, RegExMessages.displayString_exactPoss, RegExMessages.additionalInfo_exactPoss); //$NON-NLS-1$ + addBracketProposal("{,}+", 1, RegExMessages.displayString_leastPoss, RegExMessages.additionalInfo_leastPoss); //$NON-NLS-1$ + addBracketProposal("{,}+", 1, RegExMessages.displayString_countPoss, RegExMessages.additionalInfo_countPoss); //$NON-NLS-1$ + + // alternative + addBracketProposal("|", 1, RegExMessages.displayString_alt, RegExMessages.additionalInfo_alt); //$NON-NLS-1$ + } + + fPriorityProposals.addAll(fProposals); + return fPriorityProposals.toArray(new IContentProposal[fProposals.size()]); + } + + /** + * Computes applicable proposals for the replace field. + * + * @return the proposals + */ + public IContentProposal[] computeReplaceProposals() + { + if (fDocumentOffset > 0 && '$' == fExpression.charAt(fDocumentOffset - 1)) + { + addProposal("", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$ + } + else + { + addProposal("$", RegExMessages.displayString_dollar, RegExMessages.additionalInfo_dollar); //$NON-NLS-1$ + addBsProposal("\\", RegExMessages.displayString_replace_bs, RegExMessages.additionalInfo_replace_bs); //$NON-NLS-1$ + addProposal("\t", RegExMessages.displayString_tab, RegExMessages.additionalInfo_tab); //$NON-NLS-1$ + } + return fProposals.toArray(new IContentProposal[fProposals.size()]); + } + + /** + * Adds a proposal. + * + * @param proposal + * the string to be inserted + * @param displayString + * the proposal's label + * @param additionalInfo + * the additional information + */ + private void addProposal(String proposal, String displayString, String additionalInfo) + { + fProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length())); + } + + /** + * Adds a proposal. + * + * @param proposal + * the string to be inserted + * @param cursorPosition + * the cursor position after insertion, relative to the start of the proposal + * @param displayString + * the proposal's label + * @param additionalInfo + * the additional information + */ + private void addProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) + { + fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition)); + } + + /** + * Adds a proposal to the priority proposals list. + * + * @param proposal + * the string to be inserted + * @param displayString + * the proposal's label + * @param additionalInfo + * the additional information + */ + private void addPriorityProposal(String proposal, String displayString, String additionalInfo) + { + fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, proposal.length())); + } + + /** + * Adds a proposal. Ensures that existing pre- and postfixes are not duplicated. + * + * @param proposal + * the string to be inserted + * @param cursorPosition + * the cursor position after insertion, relative to the start of the proposal + * @param displayString + * the proposal's label + * @param additionalInfo + * the additional information + */ + private void addBracketProposal(String proposal, int cursorPosition, String displayString, String additionalInfo) + { + String prolog = fExpression.substring(0, fDocumentOffset); + if (!fIsEscape && prolog.endsWith("\\") && proposal.startsWith("\\")) { //$NON-NLS-1$//$NON-NLS-2$ + fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition)); + return; + } + for (int i = 1; i <= cursorPosition; i++) + { + String prefix = proposal.substring(0, i); + if (prolog.endsWith(prefix)) + { + String postfix = proposal.substring(cursorPosition); + String epilog = fExpression.substring(fDocumentOffset); + if (epilog.startsWith(postfix)) + { + fPriorityProposals.add(new Proposal(proposal.substring(i, cursorPosition), displayString, additionalInfo, + cursorPosition - i)); + } + else + { + fPriorityProposals.add(new Proposal(proposal.substring(i), displayString, additionalInfo, cursorPosition + - i)); + } + return; + } + } + fProposals.add(new Proposal(proposal, displayString, additionalInfo, cursorPosition)); + } + + /** + * Adds a proposal that starts with a backslash. Ensures that the backslash is not repeated if already typed. + * + * @param proposal + * the string to be inserted + * @param displayString + * the proposal's label + * @param additionalInfo + * the additional information + */ + private void addBsProposal(String proposal, String displayString, String additionalInfo) + { + String prolog = fExpression.substring(0, fDocumentOffset); + int position = proposal.length(); + // If the string already contains the backslash, do not include in + // the proposal + if (prolog.endsWith("\\")) { //$NON-NLS-1$ + position--; + proposal = proposal.substring(1); + } + + if (fIsEscape) + { + fPriorityProposals.add(new Proposal(proposal, displayString, additionalInfo, position)); + } + else + { + addProposal(proposal, position, displayString, additionalInfo); + } + } + } + + /** + * <code>true</code> iff the processor is for the find field. <code>false</code> iff the processor is for the + * replace field. + */ + private final boolean fIsFind; + + /** + * Creates a new completion proposal provider. + * + * @param isFind + * <code>true</code> if the provider is used for the 'find' field <code>false</code> if the provider is + * used for the 'reaplce' field + */ + public RegExContentProposalProvider(boolean isFind) + { + fIsFind = isFind; + } + + /* + * @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int) + */ + public IContentProposal[] getProposals(String contents, int position) + { + if (fIsFind) return new ProposalComputer(contents, position).computeFindProposals(); + return new ProposalComputer(contents, position).computeReplaceProposals(); + } +} diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExMessages.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExMessages.java new file mode 100644 index 0000000000..f9714ed1a1 --- /dev/null +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExMessages.java @@ -0,0 +1,331 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.net4j.util.ui.proposals; + +import org.eclipse.osgi.util.NLS; + +/** + * RegEx messages. Helper class to get NLSed messages. + * <p> + * Copied from org.eclipse.ui.texteditor.RegExMessages. + * <p> + * Needed by org.eclipse.mylyn.internal.team.ui.preferences.workaround.RegExContentProposalProvider. + * <p> + * TODO Ask platform guys to open this API + * + * @since 3.1 + */ +final class RegExMessages extends NLS { + + private static final String BUNDLE_NAME = RegExMessages.class.getName(); + + private RegExMessages() { + // Do not instantiate + } + + static { + reloadMessages(); + } + + static void reloadMessages() { + NLS.initializeMessages(BUNDLE_NAME, RegExMessages.class); + } + + // characters + public static String displayString_bs_bs; + + public static String additionalInfo_bs_bs; + + public static String displayString_bs_0; + + public static String additionalInfo_bs_0; + + public static String displayString_bs_x; + + public static String additionalInfo_bs_x; + + public static String displayString_bs_u; + + public static String additionalInfo_bs_u; + + public static String displayString_bs_t; + + public static String additionalInfo_bs_t; + + public static String displayString_bs_n; + + public static String additionalInfo_bs_n; + + public static String displayString_bs_r; + + public static String additionalInfo_bs_r; + + public static String displayString_bs_f; + + public static String additionalInfo_bs_f; + + public static String displayString_bs_a; + + public static String additionalInfo_bs_a; + + public static String displayString_bs_e; + + public static String additionalInfo_bs_e; + + public static String displayString_bs_c; + + public static String additionalInfo_bs_c; + + // character classes + public static String displayString_dot; + + public static String additionalInfo_dot; + + public static String displayString_bs_d; + + public static String additionalInfo_bs_d; + + public static String displayString_bs_D; + + public static String additionalInfo_bs_D; + + public static String displayString_bs_s; + + public static String additionalInfo_bs_s; + + public static String displayString_bs_S; + + public static String additionalInfo_bs_S; + + public static String displayString_bs_w; + + public static String additionalInfo_bs_w; + + public static String displayString_bs_W; + + public static String additionalInfo_bs_W; + + // boundary matchers + public static String displayString_start; + + public static String additionalInfo_start; + + public static String displayString_end; + + public static String additionalInfo_end; + + public static String displayString_bs_b; + + public static String additionalInfo_bs_b; + + public static String displayString_bs_B; + + public static String additionalInfo_bs_B; + + public static String displayString_bs_A; + + public static String additionalInfo_bs_A; + + public static String displayString_bs_G; + + public static String additionalInfo_bs_G; + + public static String displayString_bs_Z; + + public static String additionalInfo_bs_Z; + + public static String displayString_bs_z; + + public static String additionalInfo_bs_z; + + // greedy quantifiers + public static String displayString_quest; + + public static String additionalInfo_quest; + + public static String displayString_star; + + public static String additionalInfo_star; + + public static String displayString_plus; + + public static String additionalInfo_plus; + + public static String displayString_exact; + + public static String additionalInfo_exact; + + public static String displayString_least; + + public static String additionalInfo_least; + + public static String displayString_count; + + public static String additionalInfo_count; + + // lazy quantifiers + public static String displayString_questLazy; + + public static String additionalInfo_questLazy; + + public static String displayString_starLazy; + + public static String additionalInfo_starLazy; + + public static String displayString_plusLazy; + + public static String additionalInfo_plusLazy; + + public static String displayString_exactLazy; + + public static String additionalInfo_exactLazy; + + public static String displayString_leastLazy; + + public static String additionalInfo_leastLazy; + + public static String displayString_countLazy; + + public static String additionalInfo_countLazy; + + // possessive quantifiers + public static String displayString_questPoss; + + public static String additionalInfo_questPoss; + + public static String displayString_starPoss; + + public static String additionalInfo_starPoss; + + public static String displayString_plusPoss; + + public static String additionalInfo_plusPoss; + + public static String displayString_exactPoss; + + public static String additionalInfo_exactPoss; + + public static String displayString_leastPoss; + + public static String additionalInfo_leastPoss; + + public static String displayString_countPoss; + + public static String additionalInfo_countPoss; + + // alternative + public static String displayString_alt; + + public static String additionalInfo_alt; + + // capturing groups + public static String displayString_group; + + public static String additionalInfo_group; + + public static String displayString_bs_i; + + public static String additionalInfo_bs_i; + + // quoting + public static String displayString_bs; + + public static String additionalInfo_bs; + + public static String displayString_bs_Q; + + public static String additionalInfo_bs_Q; + + public static String displayString_bs_E; + + public static String additionalInfo_bs_E; + + // character sets + public static String displayString_set; + + public static String additionalInfo_set; + + public static String displayString_setExcl; + + public static String additionalInfo_setExcl; + + public static String displayString_setRange; + + public static String additionalInfo_setRange; + + public static String displayString_setInter; + + public static String additionalInfo_setInter; + + public static String displayString_posix; + + public static String additionalInfo_posix; + + public static String displayString_posixNot; + + public static String additionalInfo_posixNot; + + public static String displayString_flag; + + public static String additionalInfo_flag; + + public static String displayString_flagExpr; + + public static String additionalInfo_flagExpr; + + // non-capturing group + public static String displayString_nonCap; + + public static String additionalInfo_nonCap; + + public static String displayString_atomicCap; + + public static String additionalInfo_atomicCap; + + // look-ahead + public static String displayString_posLookahead; + + public static String additionalInfo_posLookahead; + + public static String displayString_negLookahead; + + public static String additionalInfo_negLookahead; + + public static String displayString_posLookbehind; + + public static String additionalInfo_posLookbehind; + + public static String displayString_negLookbehind; + + public static String additionalInfo_negLookbehind; + + // replace + public static String displayString_dollar; + + public static String additionalInfo_dollar; + + public static String additionalInfo_replace_bs; + + public static String displayString_replace_bs; + + public static String displayString_tab; + + public static String additionalInfo_tab; + + public static String displayString_nl; + + public static String additionalInfo_nl; + + public static String displayString_cr; + + public static String additionalInfo_cr; +} diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExMessages.properties b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExMessages.properties new file mode 100644 index 0000000000..e79cbc7fb3 --- /dev/null +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/proposals/RegExMessages.properties @@ -0,0 +1,495 @@ +############################################################################### +# Copyright (c) 2000, 2005 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### + +## Content Assist for regular expressions ## +## Copied from org.eclipse.ui.texteditor.RegExMessages.properties. +## Needed by org.eclipse.mylyn.internal.team.ui.preferences.workaround.RegExMessages. +## TODO Ask platform guys to open this API +# use \\\u0075 for a backslash-u +displayString_bs_bs= \\\\ - Backslash +additionalInfo_bs_bs= Backslash +displayString_bs_0= \\0nnn - Octal character code +additionalInfo_bs_0= Octal character code\n\nExamples:\n\\011 (tabulator)\n\\0112 (character J) +displayString_bs_x= \\xhh - Hex character code +additionalInfo_bs_x= Hexadecimal character code\n\nExamples:\n\\x09 (tabulator)\n\\x4A or \\x4a (character J) +displayString_bs_u= \\\u0075hhhh - Hex code for Unicode character +additionalInfo_bs_u= Hexadecimal code for Unicode character\n\nExamples:\n\\\u0075004A (character J)\n\\\u007503B2 (lowercase Greek letter beta: \u03B2) +displayString_bs_t= \\t - Tab +additionalInfo_bs_t= Tabulator (\\x09, decimal: 9) +displayString_bs_n= \\n - Newline +additionalInfo_bs_n= Newline (\\x0A, decimal: 10) +displayString_bs_r= \\r - CR +additionalInfo_bs_r= Carriage Return (\\x0D, decimal: 13) +displayString_bs_f= \\f - FF +additionalInfo_bs_f= Form Feed (\\x0C, decimal: 12) +displayString_bs_a= \\a - Beep +additionalInfo_bs_a= Beep, Bell, Alert (\\x07, decimal: 7) +displayString_bs_e= \\e - Esc +additionalInfo_bs_e= Escape (\\x1B, decimal: 27) +displayString_bs_c= \\c - Control character +additionalInfo_bs_c= Control character\n\nExample:\n\\cC (Ctrl+C) + +displayString_dot= . - Any character +additionalInfo_dot= The dot matches any character except line terminators.\n\n\ +To make the dot match line terminators as well, \n\ +start the expression with the embedded flag expression \n\ +"(?s)" (without quotes). +displayString_bs_d= \\d - A digit +additionalInfo_bs_d= A digit: [0-9] +displayString_bs_D= \\D - Not a digit +additionalInfo_bs_D= Not a digit: [^0-9] +displayString_bs_s= \\s - A whitespace +additionalInfo_bs_s= A whitespace: [ \\t\\n\\x0B\\f\\r] +displayString_bs_S= \\S - Not a whitespace +additionalInfo_bs_S= Not a whitespace: [^\\s] +displayString_bs_w= \\w - An alphanumeric (word character) +additionalInfo_bs_w= An alphanumeric (a word character): [a-zA-Z_0-9] +displayString_bs_W= \\W - Not an alphanumeric +additionalInfo_bs_W= Not an alphanumeric (not a word character): [^\\w] + +displayString_start= ^ - Line start +additionalInfo_start= Line start (positional match)\n\nExample:\n\ +The expression "^Eclipse" matches the term "Eclipse"\n\ +only on the second line of text\n\ +"The Eclipse Project\n\ +Eclipse Platform". +displayString_end= $ - Line end +additionalInfo_end= Line end (positional match)\n\nExample:\n\ +The expression "Eclipse$" matches the term "Eclipse"\n\ +only on the second line of text\n\ +"- Install the Eclipse Platform\n\ +- Run Eclipse". +displayString_bs_b= \\b- Word beginning or end +additionalInfo_bs_b= Word beginning or end (positional match)\n\nExample:\n\ +The expression "s\\b" matches only the last "s" of "glasses" in text\n\ +"I lost my glasses." +displayString_bs_B= \\B - Not a word beginning or end +additionalInfo_bs_B= Not a word beginning or end (positional match)\n\nExample:\n\ +The expression "\\BS" matches only "S" of "printString" in text\n\ +"void print(String printString)". +displayString_bs_A= \\A - Start of input +additionalInfo_bs_A= Start of input (positional match)\n\nExample:\n\ +The expression "\\ABC" matches only "BC" of "BCD" in text\n\ +"BCD ABC\n\ +BCDEF". +displayString_bs_G= \\G - Previous match's end +additionalInfo_bs_G= Previous match's end (positional match)\n\nExample:\n\ +The expression "\\Ga" matches the first and then the second "a" in text\n\ +"aardvark" (when starting from the beginning). +displayString_bs_Z= \\Z - End of input, does not consider last line terminator +additionalInfo_bs_Z= End of input, does not consider last line terminator (positional match)\n\n\ +The expression matches at the end of the file, except for when the\n\ +file ends in a line terminator, in which case it matches before that\n\ +line terminator.\n\nExample:\n\ +The expression "ing\\Z" matches "ing" in text\n\ +"testing", as well as in text\n\ +"testing\n\ +", but doesn't match in text\n\ +"testing\n\ +\n\ +" +displayString_bs_z= \\z - End of input +additionalInfo_bs_z= End of input (positional match)\n\nExample:\n\ +The expression "ing\\z" matches "ing" in text\n\ +"testing", but doesn't match in text\n\ +"testing\n\ +" + +### repetition quantifiers ### +displayString_quest= ? - Greedy match 0 or 1 times +additionalInfo_quest= Greedy match 0 or 1 times.\n\n\ +First tries to match the preceding token.\n\ +Falls back to not matching if this choice made a full match impossible.\n\nExample:\n\ +The expression "fo?" matches "f", "fo", and "fo" in text\n\ +"f fo foo". +displayString_star= * - Greedy match 0 or more times +additionalInfo_star= Greedy match 0 or more times.\n\n\ +First tries to match the preceding token as many times as possible.\n\ +Falls back to matching it less often if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo*" matches "f", "fo", and "foo" in text\n\ +"f fo foo".\n\ +- The expression "fo*o\\d" matches all three words in text\n\ +"fo1 foo2 fooo3".\n\ +- The expression "<.*>" matches the whole text\n\ +"<p><b>bold</b>". +displayString_plus= + - Greedy match 1 or more times +additionalInfo_plus= Greedy match 1 or more times\n\n\ +First tries to match the preceding token as many times as possible.\n\ +Falls back to matching it less often if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo+" matches "fo" and "foo" in text\n\ +"f fo foo".\n\ +- The expression "fo+o\\d" matches "foo2" and "fooo3" in text\n\ +"fo1 foo2 fooo3".\n\ +- The expression "<.+>" matches the whole text\n\ +"<p><b>bold</b>", but does not match anywhere in "<>". +displayString_exact= {n} - Greedy match exactly n times +additionalInfo_exact= Greedy match exactly n times.\n\nExamples:\n\ +- The expression "\\\\0[0-3][0-7]{2}" matches all three-digit octal character tokens.\n\ +- The expression "\\b\\w{4}\\b" matches all four-letter-words\n\ +such as "Java", "cool", or "food" (but not "dog"). +displayString_least= {n,} - Greedy match >= n times +additionalInfo_least= Greedy match >= n times.\n\n\ +First tries to match the preceding token as many times as possible.\n\ +Falls back to matching it less often (but at least n times),\n\ +if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo{2,}" matches "foo" and "fooo" in text\n\ +"f fo foo fooo".\n\ +- The expression "fo{2,}o\\d" matches "fooo3" and "foooo4" in text\n\ +"fo1 foo2 fooo3 foooo4".\n\ +- The expression "10{3,}[^0]" matches all powers of ten that are larger than one thousand.\n\n\ +Note: The expressions "{0,}" and "*" are equivalent;\n\ +likewise, "{1,}" is equivalent to "+". +displayString_count= {n,m} - Greedy match >= n times but <= m times +additionalInfo_count= Greedy match >= n times but <= m times.\n\n\ +First tries to match the preceding token m times.\n\ +Falls back to matching it less often (but at least n times),\n\ +if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo{1,2}" matches "fo", "foo", and "foo" in text\n\ +"f fo foo fooo".\n\ +- The expression "fo{1,2}o\\d" matches "foo2" and "fooo3" in text\n\ +"fo1 foo2 fooo3 foooo4".\n\ +- The expression "^.{70,80}$" matches all the lines that contain\n\ +between 70 and 80 characters (inclusive). + +displayString_questLazy= ?? - Lazy match 0 or 1 times +additionalInfo_questLazy= Lazy match 0 or 1 times.\n\n\ +First tries to not match the preceding token.\n\ +Falls back to matching it if this choice made a full match impossible.\n\nExample:\n\ +The expression "fo??" matches "f", "f", and "f" in text\n\ +"f fo foo". +displayString_starLazy= *? - Lazy match 0 or more times +additionalInfo_starLazy= Lazy match 0 or more times.\n\n\ +First tries to not match the preceding token.\n\ +Falls back to matching it more often if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo*?" matches "f", "f", and "f" in text\n\ +"f fo foo".\n\ +- The expression "fo*?o\\d" matches all three words in text\n\ +"fo1 foo2 fooo3".\n\ +- The expression "<.*?>" matches "<p>", "<b>", and "</b>" in text\n\ +"<p><b>bold</b>". Note: a more performant expression for finding\n\ +xml tags is "<[^>]*>", which avoids backtracking. +displayString_plusLazy= +? - Lazy match 1 or more times +additionalInfo_plusLazy= Lazy match 1 or more times\n\n\ +First tries to match the preceding token once.\n\ +Falls back to matching it more often if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo+?" matches "fo" and "fo" in text\n\ +"f fo foo".\n\ +- The expression "fo+?o\\d" matches "foo2" and "fooo3" in text\n\ +"fo1 foo2 fooo3".\n\ +- The expression "<.+?>" matches "<p>", "<b>", and "</b>" in text\n\ +"<p><b>bold</b>". Note: a more performant expression for finding\n\ +xml tags is "<[^>]*>", which avoids backtracking. +displayString_exactLazy= {n}? - Lazy match exactly n times +additionalInfo_exactLazy= Lazy match exactly n times.\n\n\ +This expression is equivalent to the expression\n\ +{n} - Greedy match exactly n times. +displayString_leastLazy= {n,}? - Lazy match >= n times +additionalInfo_leastLazy= Lazy match >= n times.\n\n\ +First tries to match the preceding token n times. Falls back to\n\ +matching it more often, if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo{2,}?" matches "foo" and "foo" in text\n\ +"f fo foo fooo".\n\ +- The expression "fo{2,}?o\\d" matches "fooo3" and "foooo4" in text\n\ +"fo1 foo2 fooo3 foooo4".\n\ +- The expression "10{3,}?[^0]" matches all powers of ten that are larger than one thousand.\n\n\ +Note: The expressions "{0,}?" and "*?" are equivalent;\n\ +likewise, "{1,}?" is equivalent to "+?". +displayString_countLazy= {n,m}? - Lazy match >= n times but <= m times +additionalInfo_countLazy= Lazy match >= n times but <= m times.\n\n\ +First tries to match the preceding token n times.\n\ +Falls back to matching it more often (but at most m times),\n\ +if this choice made a full match impossible.\n\nExamples:\n\ +- The expression "fo{1,2}?" matches "fo", "fo", and "fo" in text\n\ +"f fo foo fooo".\n\ +- The expression "fo{1,2}?o\\d" matches "foo2" and "fooo3" in text\n\ +"fo1 foo2 fooo3 foooo4".\n\ + +displayString_questPoss= ?+ - Possessive match 0 or 1 times (no backtracking) +additionalInfo_questPoss= Possessive match 0 or 1 times.\n\n\ +Matches the preceding token if possible. Never backtracks,\n\ +even if this choice renders a full match impossible.\n\nExample:\n\ +The expression "fo?+o\\d" matches the first, but not the second line in text\n\ +"fo1\n\ +foo1". +displayString_starPoss= *+ Possessive match 0 or more times (no backtracking) +additionalInfo_starPoss= Possessive match 0 or more times.\n\n\ +Tries to match the preceding token as many times as possible. Never backtracks,\n\ +even if this choice renders a full match impossible.\n\nExamples:\n\ +- The expression "fo*+" matches "f", "fo" and "foo" in text\n\ +"f fo foo".\n\ +- The expression "fo*+o\\d" matches nowhere in text\n\ +"fo1 foo2 fooo3".\n\ +- The expression "<.*+>" matches nowhere in text\n\ +"<p><b>bold</b>". +displayString_plusPoss= ++ - Possessive match 1 or more times (no backtracking) +additionalInfo_plusPoss= Possessive match 1 or more times.\n\n\ +Tries to match the preceding token as many times as possible. Never backtracks,\n\ +even if this choice renders a full match impossible.\n\nExamples:\n\ +- The expression "fo++" matches "fo" and "foo" in text\n\ +"f fo foo".\n\ +- The expression "fo++o\\d" matches nowhere in text\n\ +"fo1 foo2 fooo3".\n\ +- The expression "<.++>" matches nowhere in text\n\ +"<p><b>bold</b>". + +displayString_exactPoss= {n}+ - Possessive match exactly n times (no backtracking) +additionalInfo_exactPoss= Possessive match exactly n times.\n\n\ +This expression is equivalent to the expression\n\ +{n} - Greedy match exactly n times. +displayString_leastPoss= {n,}+ - Possessive match >= n times (no backtracking) +additionalInfo_leastPoss= Possessive match >= n times.\n\n\ +Tries to match the preceding token as many times as possible, but at least n times.\n\ +Never backtracks, even if this choice renders a full match impossible.\n\nExamples:\n\ +- The expression "fo{2,}+" matches "foo" and "fooo" in text\n\ +"f fo foo fooo".\n\ +- The expression "fo{2,}?o\\d" matches nowhere in text\n\ +"fo1 foo2 fooo3 foooo4".\n\ +Note: The expressions "{0,}?" and "*?" are equivalent;\n\ +likewise, "{1,}?" is equivalent to "+?". + +displayString_countPoss= {n,m}+ - Possessive match >= n times but <= m times (no backtracking) +additionalInfo_countPoss= Possessive match >= n times but <= m times.\n\n\ +Tries to match the preceding token as many times as possible, \n\ +at least n times and at most m times.\n\ +Never backtracks, even if this choice renders a full match impossible.\n\nExamples:\n\ +- The expression "fo{1,2}+" matches "fo", "foo", and "foo" in text\n\ +"f fo foo fooo".\n\ +- The expression "fo{1,2}+o\\d" matches only "fooo3" in text\n\ +"fo1 foo2 fooo3 foooo4".\n\ +- The expression "^.{70,80}+$" matches all the lines that contain\n\ +between 70 and 80 characters (inclusive). + +displayString_alt= U|V - Alternation: U or V +additionalInfo_alt= Alternation.\n\n\ +First tries to match subexpression U. Falls back and tries to match V if U didn't match.\n\nExamples:\n\ +- The expression "A|B" applied to text "BA" first matches "B", then "A".\n\ +- The expression "AB|BC|CD" applied to text "ABC BC DAB" matches, in sequence:\n\ +"AB" in the first word, the second word "BC", "AB" at the very end. +displayString_group= (Expr) - Mark Expr as capturing group +additionalInfo_group= Mark Expr as capturing group.\n\n\ +Capturing groups are numbered by counting their opening parentheses from left to right.\n\ +In the expression "((A)(B(C)))", for example, there are four such groups:\n\ +1 ((A)(B(C)))\n\ +2 (A)\n\ +3 (B(C))\n\ +4 (C)\n\ +\n\ +Group zero always stands for the entire expression. During a match,\n\ +each subsequence of the input sequence that matches such a group is saved.\n\ +The captured subsequence i may be used later in the expression, via a back reference "\\i",\n\ +and may also be used in the replace string via "$i".\n\ +\n\ +Note: Groups beginning with (? are pure, non-capturing groups that\n\ +do not capture text and do not count towards the group total. + +displayString_bs_i= \\i - Match of the capturing group i +additionalInfo_bs_i= Match of the capturing group i.\n\n\ +\\i matches the subsequence that has already been saved as capturing group i.\n\ +\\0 is not a valid group number in the regular expression.\n\nExample:\n\ +The expression "(\\d+)\\+\\1" matches "10+10" in text "9+10+10+11".\n\ +\n\ +Note: in the replace string, $i stands for the capturing group i. + +displayString_bs= \\ - Quote next character +additionalInfo_bs= Quote next character\n\nExample:\n\ +The expression "\\{\\n\\}" matches the text "{n}". + +displayString_bs_Q= \\Q - Start quoting +additionalInfo_bs_Q= Start quoting\n\n\ +All characters between \\Q and the next \\E are taken literally and are not interpreted.\n\nExample:\n\ +The expression "\\Qnew int[] {42}\\E;" matches text "new int[] {42}". +displayString_bs_E= \\E - End quoting +additionalInfo_bs_E= End quoting\n\n\ +All characters between \\Q and the next \\E are taken literally and are not interpreted.\n\nExample:\n\ +The expression "\\Qnew int[] {42}\\E;" matches text "new int[] {42}". + +displayString_set= [ecl] - Character set +additionalInfo_set= Character set\n\n\ +Matches a single character out of the set.\n\nExample:\n\ +The expression "[ecl]" matches "c" and "l" in text "cold". +displayString_setExcl= [^ecl] - Excluded character set +additionalInfo_setExcl= Excluded character set\n\n\ +Matches a single character that is not one of the excluded characters.\n\nExamples:\n\ +The expression "[^ecl]" matches "o" and "d" in text "cold".\n\ +The expression "[a-z&&[^ecl]]" matches any character from a to z, excluding e, c, and l. +displayString_setRange= [c-l] - Character range +additionalInfo_setRange= Character range\n\n\ +Matches a single character out of the range from 'c' to 'l'.\n\nExamples:\n\ +The expression "[c-l]" matches "c", "l", and "d" in text "cold".\n\ +The expression "[a-z&&[^ecl]]" matches any character from a to z, excluding e, c, and l. +displayString_setInter= && - Intersection of character sets +additionalInfo_setInter= Intersection of character sets\n\n\ +Matches a character that is in both of the given sets.\n\nExample:\n\ +The expression "[a-z&&[^ecl]]" matches any character from a to z, excluding e, c, and l. + +displayString_posix= \\p{Class} - POSIX or Unicode character class +additionalInfo_posix= POSIX or Unicode character class\n\n\ +Matches a character from the given character class 'Class'.\n\ +Valid classes are:\n\ +\n\ +- POSIX character classes (US-ASCII only):\n\ +\ Lower, Upper, ASCII, Alpha, Digit, Alnum, Punct,\n\ +\ Graph, Print, Blank, Cntrl, XDigit, and Space.\n\ +\n\ +- Unicode blocks and categories, e.g.:\n\ +\ BasicLatin\n\ +\ Latin-1Supplement\n\ +\ Greek\n\ +\ Lu: Uppercase Letter\n\ +\ Ll: Lowercase Letter\n\ +\ L: Letter\n\ +\ N: Number\n\ +\ Z: Separator\n\ +\ LD: Letter or Digit\n\ +\ L1: Latin-1 + +displayString_posixNot= \\P{Class} - Excluded POSIX or Unicode character class +additionalInfo_posixNot= Excluded POSIX or Unicode character class\n\n\ +Negation of character set \\p{Class}. Example:\n\ +\\P{ASCII} is equivalent to [^\\p{ASCII}] and matches all non-ASCII characters.\n\n\ +Valid classes are:\n\ +\n\ +- POSIX character classes (US-ASCII only):\n\ +\ Lower, Upper, ASCII, Alpha, Digit, Alnum, Punct,\n\ +\ Graph, Print, Blank, Cntrl, XDigit, and Space.\n\ +\n\ +- Unicode blocks and categories, e.g.:\n\ +\ BasicLatin\n\ +\ Latin-1Supplement\n\ +\ Greek\n\ +\ Lu: Uppercase Letter\n\ +\ Ll: Lowercase Letter\n\ +\ L: Letter\n\ +\ N: Number\n\ +\ Z: Separator\n\ +\ LD: Letter or Digit\n\ +\ L1: Latin-1 + + +#Flags: +displayString_flag= (?ismd-ismd) - Turn flags on or off +additionalInfo_flag= Turn flags on and off for the rest of the matching process.\n\n\ +Flags before the dash are turned on; those after the dash are turned off.\n\ +The following flags are supported:\n\ +- i: case-insensitive matching\n\ +\n\ +- s: single-line, or dotall matching mode:\n\ +\ The expression . matches any character, including a line terminator.\n\ +\n\ +- m: multiline matching mode:\n\ +\ The expressions ^ and $ match just after or just before,\n\ +\ respectively, a line terminator or the end of the input sequence.\n\ +\ By default these expressions only match at the beginning and the\n\ +\ end of the entire input sequence.\n\ +\n\ +- d: Unix lines matching mode:\n\ +\ Only the '\\n' line terminator\n\ +\ is recognized in the behavior of ., ^, and $ +# - u: unicode-aware case folding:\n\ +# Case-insensitive matching, when enabled, is done in a manner consistent\n\ +# with the Unicode Standard. By default, case-insensitive matching\n\ +# assumes that only characters in the US-ASCII charset are being matched. +# - c: canonical equivalence\n\ +# Two characters will be considered to match if, and only if, their full\n\ +# canonical decompositions match. The expression "a\\\u0075030A", for example,\n\ +# will match the string "a\u030A" when this flag is specified.\n\ +# By default, matching does not take canonical equivalence into account. +# - x: comments mode\n\ +# Whitespace is ignored, and embedded comments starting with\n\ +# # are ignored until the end of a line.\n\ + +displayString_flagExpr= (?ismd-ismd:Expr) - Turn flags on or off in Expr +additionalInfo_flagExpr= Turn flags on and off in Expr.\n\n\ +Flags before the dash are turned on; those after the dash are turned off.\n\ +The following flags are supported:\n\ +- i: case-insensitive matching\n\ +\n\ +- s: single-line, or dotall matching mode:\n\ +\ The expression . matches any character, including a line terminator.\n\ +\n\ +- m: multiline matching mode:\n\ +\ The expressions ^ and $ match just after or just before,\n\ +\ respectively, a line terminator or the end of the input sequence.\n\ +\ By default these expressions only match at the beginning and the\n\ +\ end of the entire input sequence.\n\ +\n\ +- d: Unix lines matching mode:\n\ +\ Only the '\\n' line terminator\n\ +\ is recognized in the behavior of ., ^, and $ + + +#Noncapturing groups: +displayString_nonCap= (?:Expr) - Non-capturing group +additionalInfo_nonCap= Non-capturing group of regular expression Expr.\n\n\ +The group is not saved in a back reference.\n\nExample:\n\ +The expression "(?:\\w+) (\\d+)" matches "bug 42" in text "It's bug 42.".\n\ +A back reference "$1" in the replace string will be replaced by "42". + +displayString_atomicCap= (?>Expr) - Non-capturing atomic group +additionalInfo_atomicCap= Non-capturing atomic group of regular expression Expr.\n\n\ +Matches the regular expression Expr once, but does not backtrack into the expression\n\ +again if the first match did not prove to be successful later on.\n\ +The group is not saved in a back reference. + +#Lookaround: +displayString_posLookahead= (?=Expr) - Zero-width positive lookahead +additionalInfo_posLookahead= Expr, via zero-width positive lookahead.\n\n\ +Matches a position (zero-width: does not consume the matched characters),\n\ +where the next characters (-> lookahead)\n\ +do match (-> positive) the embedded expression Expr.\n\nExamples:\n\ +- The expression "var(?==)" matches only the first "var" in text "var=17; other=var;".\n\ +- The expression "\\b(?=\\w{7}\\b)\\w*clip\\w*\\b" matches any\n\ +seven-letter-word that contains "clip". It matches "Eclipse", but not "paperclip". + +displayString_negLookahead= (?!Expr) - Zero-width negative lookahead +additionalInfo_negLookahead= Expr, via zero-width negative lookahead.\n\n\ +Matches a position (zero-width: does not consume the matched characters),\n\ +where the next characters (-> lookahead)\n\ +do not match (-> negative) the embedded expression Expr.\n\nExamples:\n\ +- The expression "var(?!=)" matches only the second "var" in text "var=17; other=var;".\n\ +- The expression "\\b(?!\\w{5,7}\\b)\\w*clip\\w*\\b" matches any\n\ +word that contains "clip" and consists of less than 5 or more than 7 characters.\n\ +It matches "clip" and "paperclip", but not "Eclipse". + +displayString_posLookbehind= (?<=Expr) - Zero-width positive lookbehind +additionalInfo_posLookbehind= Expr, via zero-width positive lookbehind.\n\n\ +Matches a position (zero-width: does not consume the matched characters),\n\ +where the previous characters (-> lookbehind)\n\ +do match (-> positive) the embedded expression Expr.\n\nExample:\n\ +- The expression "\\w{5,}+(?<=as)\\b" matches "alias" and "bananas",\n\ +but does not match "peas", "apples", or "Alaska". + +displayString_negLookbehind= (?<!Expr) - Zero-width negative lookbehind +additionalInfo_negLookbehind= Expr, via zero-width negative lookbehind.\n\n\ +Matches a position (zero-width: does not consume the matched characters),\n\ +where the previous characters (-> lookbehind)\n\ +do not match (-> negative) the embedded expression Expr.\n\nExample:\n\ +- The expression "\\w{5,}+(?<!as)\\b" matches "Eclipse" and "apples",\n\ +but does not match "peas" or "bananas". + +#Replace string: +displayString_dollar= $i - Match of the capturing group i +additionalInfo_dollar= Match of the capturing group i.\n\n\ +$i is the string that has been saved as capturing group i.\n\ +$0 is the subsequence matched by the entire expression.\n\ +\n\ +Note: in the find expression, \\i stands for the capturing group i. +displayString_replace_bs= \\ - Quote next character +additionalInfo_replace_bs= Quote next character\n\nExamples:\n\ +"\\$" will be replaced by "$".\n\ +"\\a" will be replaced by "a".\n\ +"\\\\" will be replaced by "\\". +displayString_tab= Tab - The tabulator character +additionalInfo_tab= The tabulator character (\\t in the find expression). +displayString_cr= CR - The carriage return character +additionalInfo_cr= The carriage return character (\\r or \\x0D in the find expression). +displayString_nl= Newline - The newline character +additionalInfo_nl= The newline character (\\n or \\x0A in the find expression). diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/TextAndDisable.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/TextAndDisable.java new file mode 100644 index 0000000000..17305f1ccc --- /dev/null +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/TextAndDisable.java @@ -0,0 +1,125 @@ +/*************************************************************************** + * Copyright (c) 2004 - 2007 Eike Stepper, Germany. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.net4j.util.ui.widgets; + +import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.ui.UIUtil; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Text; + +public class TextAndDisable extends Composite implements SelectionListener, ModifyListener +{ + private Text text; + + private Button disabled; + + private String disabledValue; + + public TextAndDisable(Composite parent, int textStyle, String disabledValue) + { + super(parent, SWT.NONE); + this.disabledValue = disabledValue; + + GridLayout grid = new GridLayout(2, false); + grid.marginHeight = 0; + grid.marginWidth = 0; + setLayout(grid); + + text = createText(textStyle); + text.setLayoutData(createTextLayoutData()); + text.addModifyListener(this); + + disabled = createButton(); + disabled.setText("Disabled"); + disabled.addSelectionListener(this); + disabled.setLayoutData(UIUtil.createGridData(false, false)); + } + + public Text getText() + { + return text; + } + + public Button getButton() + { + return disabled; + } + + public boolean isDisabled() + { + return disabled.getSelection(); + } + + public void setDisabled(boolean disabled) + { + this.disabled.setSelection(disabled); + widgetSelected(null); + } + + public String getValue() + { + return text.getText(); + } + + public void setValue(String value) + { + text.setText(value); + setDisabled(ObjectUtil.equals(value, disabledValue)); + } + + public void widgetDefaultSelected(SelectionEvent e) + { + widgetSelected(e); + } + + public void widgetSelected(SelectionEvent e) + { + if (isDisabled()) + { + text.setText(disabledValue); + text.setEnabled(false); + } + else + { + text.setEnabled(true); + } + } + + public void modifyText(ModifyEvent e) + { + } + + protected Text createText(int textStyle) + { + return new Text(this, textStyle); + } + + protected GridData createTextLayoutData() + { + GridData gd = new GridData(); + gd.widthHint = 32; + return gd; + } + + protected Button createButton() + { + return new Button(this, SWT.CHECK); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java index c482256b0b..06d7f28b10 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java @@ -22,6 +22,27 @@ public final class StringUtil { } + public static String replace(String text, String[] find, String[] replace) + { + for (int i = 0; i < find.length; i++) + { + int end = 0; + for (;;) + { + int start = text.indexOf(find[i], end); + if (start == -1) + { + break; + } + + end = start + find[i].length(); + text = text.substring(0, start) + replace[i] + text.substring(end); + } + } + + return text; + } + public static String safe(String str) { if (str == null) |