小编bre*_*ine的帖子

Eclipse RCP PropertyTester永远不会通过菜单visibleWhen调用

我想为自定义导航器视图弹出菜单实现自定义属性测试器.不幸的是它实际上从未被调用.这是plugin.xml部分和类.

定义的属性测试器:

<extension
     point="org.eclipse.core.expressions.propertyTesters">
  <propertyTester
        class="com.mytest.MyPropertyTester"
        id="com.mytest.myPropertyTester"
        namespace="com.mytest.myPropertyTester"
        properties="testProperty"
        type="com.mytest.MyPropertyTester">
  </propertyTester>
Run Code Online (Sandbox Code Playgroud)

定义部分:

<extension
     point="org.eclipse.core.expressions.definitions">
  <definition
        id="org.eclipse.example.testExtension">
     <adapt
           type="org.eclipse.core.resources.IResource">
        <test
              property="com.mytest.myPropertyTester.testProperty">
        </test>
     </adapt>
  </definition>
Run Code Online (Sandbox Code Playgroud)

可见部分:

<command
           commandId="com.mytest.testcommand"
           label="Test Command"
           style="push">
         <visibleWhen
              checkEnabled="false">
           <with
                 variable="activeMenuSelection">
              <iterate
                    ifEmpty="false"
                    operator="or">
                 <or>
                    <reference
                          definitionId="org.eclipse.example.testExtension">
                    </reference>
                 </or>
              </iterate>
           </with>
        </visibleWhen>
     </command>
Run Code Online (Sandbox Code Playgroud)

和相应的课程:

package com.mytest;

import org.eclipse.core.expressions.PropertyTester;

public class MyPropertyTester extends PropertyTester {

public MyPropertyTester() {
    System.out.println("PROPERTY TESTER CONSTRUCTOR");
}

@Override
public boolean test(Object receiver, String property, Object[] args,
        Object expectedValue) {
    System.out.println("PROPERTY TESTER CALLED"); …
Run Code Online (Sandbox Code Playgroud)

eclipse eclipse-plugin eclipse-rcp

5
推荐指数
2
解决办法
3018
查看次数

Spring Security 和 OAuth2 生成具有自定义授权类型的令牌

我使用 Spring+Oauth2 来保护 Web 服务,并且添加了自定义授予类型 (custom-grant):

<bean id="myTokenGranter" class="com.example.oauth2.MyTokenGranter" />

<oauth:authorization-server client-details-service-ref="client-details-service" token-services-ref="tokenServices">
    <oauth:refresh-token/>
    <oauth:password/>
    <oauth:custom-grant token-granter-ref="myTokenGranter" />
</oauth:authorization-server>
Run Code Online (Sandbox Code Playgroud)

Spring调用实现就好了。但是我不知道应该如何在这里实际生成令牌。我看到他们使用一个名为“RandomValueStringGenerator”的类,但我不确定是否没有更好的方法,而且我不知道如何生成一个“好的”令牌,它应该有多长,或者 spring 是否检查令牌的唯一性实际上等等。有没有一种方法可以在这里调用Spring自己的生成器部分?

现在这是我的 tokengranter 类:

public class MyTokenGranter implements TokenGranter {

private RandomValueStringGenerator generator = new RandomValueStringGenerator();

@Override
public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
    //...logic added here later
    return new DefaultOAuth2AccessToken(generator.generate());
}
Run Code Online (Sandbox Code Playgroud)

}

我找不到一个很好的例子,并且 spring ouath2 源代码中只有一个半实现的测试令牌授予者。

java spring spring-security spring-security-oauth2

5
推荐指数
1
解决办法
9596
查看次数

Java ExecutorService - 为什么这个程序继续运行?

我正在尝试构建类似后台任务执行器的东西,如果没有答案,则在一定时间后终止后台任务(后台任务调用webservices并且它们可以超时但我需要确保它们在特定时间内超时)

所以我把它作为一个实验,但如果我运行它,程序不会终止.我想知道它是否因为后台线程仍然有效?我怎么能把它关闭?

public class Test {

public static class Task implements Callable<Object> {

    @Override
    public Object call() throws Exception {
        while(true) {}
    }

}

public static void main(String[] args) {
    try {
        Task t = new Task();
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.invokeAll(Arrays.asList(t), 5L, TimeUnit.SECONDS);
        executor.shutdown();
        System.out.println("DONE");
    } 
    catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

}

java multithreading executorservice

5
推荐指数
1
解决办法
1712
查看次数

FragmentManager已经在执行事务

所以我在使用带有FragmentStatePagerAdapter的ViewPager时遇到这个问题然后我试图选择当前页面(即向用户显示第二页而不是第一页),我不时会得到这个例外.

问题似乎是并发性,因为viewpager仍在添加/初始化片段,即当我正在尝试设置当前页面时正在运行片段事务.像这样的东西:

pagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager());
viewPager.setAdapter(pagerAdapter);
pagerAdapter.addItems(...) //Addings ID's here for each fragment, this is where the adapter notifies the viewpager
viewPager.setCurrentItem(1); //This is where the two transactions at the same time might happen
Run Code Online (Sandbox Code Playgroud)

问题是:我怎么知道viewpager什么时候完成片段初始化所以设置当前页面是安全的?

确切的例外是:

Fatal Exception: java.lang.IllegalStateException: FragmentManager is already executing transactions
   at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1631)
   at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
   at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:166)
   at android.support.v4.view.ViewPager.populate(ViewPager.java:1272)
   at android.support.v4.view.ViewPager.populate(ViewPager.java:1120)
   at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1646)
   at android.view.View.measure(View.java:18916)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
   at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:703)
   at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
   at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1367)
   at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:768)
   at android.view.View.measure(View.java:18916)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5972)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
   at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
   at android.view.View.measure(View.java:18916)
   at …
Run Code Online (Sandbox Code Playgroud)

android android-fragments fragmentstatepageradapter

5
推荐指数
2
解决办法
5460
查看次数

IOS 给 UIButton 添加阴影

我试图为按钮添加阴影,但阴影被添加到按钮的文本而不是整个按钮:

在此处输入图片说明

我需要使用代码来实现这一点吗?还是尺码问题?我可以在情节提要上添加阴影大小,但如果它应该绕过按钮,我看不到在哪里设置

uibutton uikit ios swift

5
推荐指数
1
解决办法
6751
查看次数

Android 适配器:使用 Linkedlist 与 Arraylist

我将 RecycleView 与 Gridlayoutmanager 一起使用。当用户向下滚动时,我的应用程序会加载很多项目。

LinkedList 在添加新元素时具有良好的性能,而我的 ArrayList 需要不断调整大小。

但我不确定 RecycleView 在后台做什么,这与 ArrayList 和/或 LinkedList 配合使用会更好。

我的适配器是:

public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.PhotosViewHolder> {

    private Context context;

    private List<Photo> items;

    public PhotosAdapter(Context context, List<Photo> items) {
        this.context = context;
        this.items = items;
    }

    //other code here

    public void addAll(List<Photo> newItems) {
        int beforeSize = items.size()-1;
        items.addAll(newItems);
        notifyItemRangeInserted(beforeSize, newItems.size());
    }

}
Run Code Online (Sandbox Code Playgroud)

因此,当我创建一个新的空适配器时,我可以这样做:

new PhotosAdapter(getContext(), new ArrayList<Photo>());
Run Code Online (Sandbox Code Playgroud)

或这个:

new PhotosAdapter(getContext(), new LinkedList<Photo>());
Run Code Online (Sandbox Code Playgroud)

当简单地添加新元素时:

adapter.addAll(myPhotos);
Run Code Online (Sandbox Code Playgroud)

那么在这种情况下 LinkedList 会更好吗?RecycleView 的优化滚动怎么样?使用 ArrayList 或 LinkedList 效果更好吗?

performance android android-adapter android-recyclerview

4
推荐指数
1
解决办法
2248
查看次数

Swift:nil需要一个上下文类型

我想在代码中实现以下功能:

class MyService {

    let mySubject = BehaviorSubject<MyData>(value: nil)

    //....

}
Run Code Online (Sandbox Code Playgroud)

不幸的是我得到"nil需要上下文类型"错误.我希望这个主题是"空的",直到我真正把东西放在那里.那么如何通过nil作为参数呢?我可以将它投射到我自己的类型以使其工作吗?

xcode ios swift rx-swift

4
推荐指数
1
解决办法
7935
查看次数

Android Studio 3.4.1 约束布局编辑器预览再次不起作用

我相信自 v3.x 以来我曾经遇到过类似的问题,并且它们不断出现。我不知道我要花多少小时来尝试使用布局编辑器,但他们就是做对了。

无论如何,这是xml代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/textView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:text="TextView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

这是它的外观:

在此处输入图片说明

我拖入的任何项目都会以 0 尺寸放置在左上角。无论您是设置精确大小还是仅设置约束。

我的 Android Studio 版本是 3.4.1
使用 28.0.0 支持库。
由于公司政策,我不能降级,所以这不是一个选择。

约束布局版本是最新的:

implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
Run Code Online (Sandbox Code Playgroud)

它也不适用于早期版本。

我已经尝试了一些早期与其他类似错误“有效”的事情:

  • 使用不同的主题
  • 在布局编辑器中尝试不同的 API 版本
  • 使缓存无效/重新启动
  • 更新了 Android Studio(到此版本)

欢迎任何建议

layout android editor android-studio android-constraintlayout

4
推荐指数
2
解决办法
2256
查看次数

具有依赖关系的Maven依赖插件复制jar

我正在尝试将jar从我的本地存储库复制到另一个项目中,如下所述:

http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html

然而,我的jar从maven-assembly-plugin作为"带有依赖性的jar"出来,它将常规jar和组装的jar放在我的本地repo中.jar名称看起来像:

示例 - 测试 - 0.0.1-快照罐与 - dependencies.jar

如果我手动复制,我可以在回购中找到它并使用它.我认为让maven复制它是个好主意所以我使用了上面描述的依赖项复制目标.

但是我不能让它工作,所以它复制"jar with dependencies"jar.

这就是pom的样子:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.10</version>
    <executions>
      <execution>
        <id>copy</id>
        <phase>package</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>my.group</groupId>
              <artifactId>example-test</artifactId>
              <version>0.0.1-SNAPSHOT</version>
              <type>jar</type>
              <overWrite>true</overWrite>
              <outputDirectory>libs</outputDirectory>
              <destFileName>somename.jar</destFileName>
            </artifactItem>
          </artifactItems>

          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

我试图将类型设置为"jar-with-dependencies",但这不起作用.只有当我将类型设为"jar"但它才会复制常规未组装的jar时,它才有效.任何想法如何解决这一问题?

maven-2 jar maven-plugin maven-3 maven

3
推荐指数
1
解决办法
5996
查看次数

RxJava过滤空列表并使用firstOrDefault

我正在尝试过滤一个列表,该列表可能是空的(或者该项不在列表中).inboxData由另一个observable填充:

private BehaviorSubject<InboxResponse> inboxData = BehaviorSubject.create();

public Observable<Item> getInboxItem(String id) {
    return inboxData
        .flatMap(response -> Observable.from(response.getData()))
        .filter(item -> item.getId().equals(id))
        .firstOrDefault(null);
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如果response.getData()为空,则firstOrDefault永远不会运行.但为什么?它清楚地表明,如果前面的observable没有发出任何内容,它会返回默认值.

java android list rx-java rx-java2

3
推荐指数
1
解决办法
2812
查看次数